Skip to content

Commit

Permalink
remove semantic search tab
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Nov 28, 2024
1 parent f37debf commit 1f132c9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 156 deletions.
65 changes: 1 addition & 64 deletions lemarche/templates/siaes/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@
aria-selected="false"
aria-controls="search-text">Recherche par SIRET / nom</button>
</li>
<li role="presentation">
<button id="search-semantic-tab"
class="fr-tabs__tab"
tabindex="0"
role="tab"
aria-selected="false"
aria-controls="search-semantic">
Recherche par mot clé
<span class="fr-badge fr-badge--sm fr-mx-2v">Beta</span>
</button>
</li>
</ul>
<div id="search-filter"
class="fr-tabs__panel"
Expand Down Expand Up @@ -162,43 +151,6 @@
</div>
</form>
</div>
<div id="search-semantic"
class="fr-tabs__panel"
role="tabpanel"
aria-labelledby="search-semantic-tab"
tabindex="0">
<form method="get"
action="{% url 'siae:search_results' %}"
id="semantic-search-form"
aria-label="Rechercher des prestataires de l'insertion et du handicap"
role="search">
{% if form.non_field_errors %}
<section class="fr-my-4v fr-input-group fr-input-group--error">
{{ form.non_field_errors }}
</section>
{% endif %}
<div class="fr-grid-row fr-grid-row--gutters">
<div class="fr-col-12 fr-col-lg-4">{% dsfr_form_field form.semantic_q %}</div>
<div class="fr-col-12 fr-col-lg-4">
<div class="fr-input-group">
<label for="id_semantic_city" class="fr-label fr-mb-2v">{{ form.semantic_city.label }}</label>
<div id="dir_form_semantic_city"
data-input-name="{{ form.semantic_city.name }}"></div>
{{ form.semantic_city }}
</div>
</div>
<div class="fr-col-12 fr-col-lg-4">
<ul class="fr-btns-group fr-btns-group--icon-left">
<li>
<button id="text-search-submit"
class="fr-btn fr-btn--icon-right fr-icon-search-line fr-mt-4w"
type="submit">Rechercher</button>
</li>
</ul>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -299,21 +251,14 @@ <h4>
let searchTextContent = document.getElementById('search-text');
let qInput = document.getElementById('id_q');

let searchSemanticContent = document.getElementById('search-semantic');
let semanticqInput = document.getElementById('id_semantic_q');

let resetBtn = document.getElementById('form-reset-btn');

if (resetBtn) {
resetBtn.addEventListener("click", resetForm);
}

// init search form
if (semanticqInput.value) {
setTimeout(() => {
dsfr(searchSemanticContent).tabPanel.disclose();
}, 500);
} else if (qInput.value) {
if (qInput.value) {
setTimeout(() => {
dsfr(searchTextContent).tabPanel.disclose();
}, 500);
Expand All @@ -331,14 +276,6 @@ <h4>
const locationsAutoComplete = new PerimetersMultiAutocomplete(LOCATION_AUTOCOMPLETE_ID, LOCATION_AUTOCOMPLETE_CONTAINER_SELECTOR, LOCATION_SELECTED_CONTAINER_SELECTOR, LOCATION_HIDDEN_INPUT_SELECTOR_PREFIX, LOCATION_CURRENT_ID);
locationsAutoComplete.init();
{% endif %}

// init city form fields
const cityAutoComplete = new PerimeterAutocomplete("dir_form_semantic_city", "id_semantic_city", "Ville", "CITY");
cityAutoComplete.init();
cityInput = document.getElementById('dir_form_semantic_city').querySelector('input')
cityInput.classList.remove("autocomplete__input")
cityInput.classList.remove("autocomplete__input--default")
cityInput.classList.add("fr-input");
});
</script>
<script type="text/javascript">
Expand Down
31 changes: 0 additions & 31 deletions lemarche/www/siaes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from lemarche.siaes import constants as siae_constants
from lemarche.siaes.models import Siae, SiaeActivity, SiaeClientReference, SiaeGroup
from lemarche.tenders.models import Tender
from lemarche.utils.apis import api_elasticsearch
from lemarche.utils.fields import GroupedModelMultipleChoiceField
from lemarche.utils.widgets import CustomSelectMultiple
from lemarche.www.siaes.widgets import CustomLocationWidget
Expand Down Expand Up @@ -181,21 +180,6 @@ class SiaeFilterForm(forms.Form):
widget=forms.TextInput(attrs={"placeholder": "Votre recherche…"}),
)

# semantic search
semantic_q = forms.CharField(
label="Prestation recherchée",
required=False,
widget=forms.TextInput(attrs={"placeholder": "Nettoyage de locaux"}),
min_length=5,
)
semantic_city = forms.ModelChoiceField(
label="Localisation de votre besoin",
queryset=Perimeter.objects.cities(),
to_field_name="slug",
required=False,
widget=forms.HiddenInput(), # displayed with a JS autocomplete library (see `perimeter_autocomplete_field.js`) # noqa
)

# other hidden filters
tender = forms.ModelChoiceField(
queryset=Tender.objects.all(), to_field_name="slug", required=False, widget=forms.HiddenInput()
Expand Down Expand Up @@ -337,16 +321,6 @@ def filter_queryset(self, qs=None): # noqa C901
full_text_string = full_text_string.replace(" ", "")
qs = qs.filter_full_text(full_text_string)

# semantic search
semantic_q = self.cleaned_data.get("semantic_q", None)
semantic_city = self.cleaned_data.get("semantic_city", None)
if semantic_q:
if semantic_city:
siaes_id = api_elasticsearch.siaes_similarity_search_with_city(semantic_q, semantic_city)
else:
siaes_id = api_elasticsearch.siaes_similarity_search(semantic_q)
qs = qs.filter(pk__in=siaes_id)

# a Tender author can export its Siae list
tender = self.cleaned_data.get("tender", None)
if tender:
Expand Down Expand Up @@ -420,11 +394,6 @@ def order_queryset(self, qs):
if full_text_string:
ORDER_BY_FIELDS = ["-similarity"]

# if semantic search, no ordering
semantic_q = self.cleaned_data.get("semantic_q", None)
if semantic_q:
return qs

# final ordering
qs = qs.order_by(*ORDER_BY_FIELDS)

Expand Down
61 changes: 0 additions & 61 deletions lemarche/www/siaes/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from unittest import mock

from django.contrib.gis.geos import Point
from django.contrib.sites.models import Site
from django.test import TestCase
Expand Down Expand Up @@ -1052,65 +1050,6 @@ def test_search_by_company_name_should_be_case_insensitive(self):
self.assertEqual(len(siaes), 2)


class SiaeSemanticSearchTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.url = reverse("siae:search_results")
cls.siae_one = SiaeFactory()
cls.siae_two = SiaeFactory()
cls.siae_three = SiaeFactory()
cls.siae_four = SiaeFactory()
cls.city = PerimeterFactory(kind=Perimeter.KIND_CITY)

def test_search_query_no_result(self):
with mock.patch(
"lemarche.utils.apis.api_elasticsearch.siaes_similarity_search"
) as mock_siaes_similarity_search:
mock_siaes_similarity_search.return_value = []
url = self.url + "?semantic_q=entretien espace vert&id_semantic_city_name=&semantic_city="
response = self.client.get(url)
siaes = list(response.context["siaes"])
self.assertEqual(len(siaes), 0)
self.assertContains(response, "Oups, aucun prestataire trouvé !")

mock_siaes_similarity_search.assert_called_once()

def test_search_query_with_results(self):
with (
mock.patch(
"lemarche.utils.apis.api_elasticsearch.siaes_similarity_search"
) as mock_siaes_similarity_search,
mock.patch(
"lemarche.utils.apis.api_elasticsearch.siaes_similarity_search_with_city"
) as mock_siaes_similarity_search_with_city,
):
mock_siaes_similarity_search.return_value = [self.siae_two.pk, self.siae_three.pk, self.siae_four.pk]
url = self.url + "?semantic_q=entretien espace vert&id_semantic_city_name=&semantic_city="
response = self.client.get(url)
siaes = list(response.context["siaes"])
self.assertEqual(len(siaes), 3)
self.assertIn(self.siae_two, siaes)
self.assertIn(self.siae_three, siaes)
self.assertIn(self.siae_four, siaes)

mock_siaes_similarity_search.assert_called_once()
mock_siaes_similarity_search_with_city.assert_not_called()

def test_search_query_with_city(self):
with mock.patch(
"lemarche.utils.apis.api_elasticsearch.siaes_similarity_search_with_city"
) as mock_siaes_similarity_search_with_city:
mock_siaes_similarity_search_with_city.return_value = [self.siae_two.pk, self.siae_four.pk]
url = f"{self.url}?semantic_q=entretien foret&id_semantic_city_name={self.city.name}&semantic_city={self.city.slug}" # noqa
response = self.client.get(url)
siaes = list(response.context["siaes"])
self.assertEqual(len(siaes), 2)
self.assertIn(self.siae_two, siaes)
self.assertIn(self.siae_four, siaes)

mock_siaes_similarity_search_with_city.assert_called_once()


class SiaeSearchOrderTest(TestCase):
@classmethod
def setUpTestData(cls):
Expand Down

0 comments on commit 1f132c9

Please sign in to comment.