Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Recherche sémantique): Suppression de la fonctionnalité #1556

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clevercloud/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"15 0 * * * $ROOT/clevercloud/stats_export_user_download_list_to_file.sh",
"30 0 * * * $ROOT/clevercloud/stats_export_user_search_list_to_file.sh",
"0 1 * * * $ROOT/clevercloud/tenders_update_count_fields.sh",
"15 1 * * 1 $ROOT/clevercloud/siaes_sync_elasticsearch_index.sh",
"0 6 * * * $ROOT/clevercloud/conversations_delete_outdated.sh",
"0 7 * * 1 $ROOT/clevercloud/siaes_sync_with_emplois_inclusion.sh",
"5 7 * * 1 $ROOT/clevercloud/siaes_sync_c2_c4.sh",
Expand All @@ -22,4 +21,4 @@
"0 9 * * * $ROOT/clevercloud/tenders_send_siae_contacted_reminder_emails.sh",
"10 9 * * * $ROOT/clevercloud/tenders_send_siae_interested_reminder_emails.sh",
"*/5 8-15 * * 1-5 $ROOT/clevercloud/tenders_send_validated.sh"
]
]
22 changes: 0 additions & 22 deletions clevercloud/siaes_sync_elasticsearch_index.sh

This file was deleted.

11 changes: 0 additions & 11 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,14 +955,3 @@
OPENAI_API_BASE = env.str("OPENAI_API_BASE", "")
OPENAI_API_KEY = env.str("OPENAI_API_KEY", "")
OPENAI_MODEL = env.str("OPENAI_MODEL", "")


# ELASTICSEARCH
# ------------------------------------------------------------------------------
ELASTICSEARCH_SCHEME = env.str("ELASTICSEARCH_SCHEME", "https")
ELASTICSEARCH_HOST = env.str("ELASTICSEARCH_HOST", "")
ELASTICSEARCH_PORT = env.str("ELASTICSEARCH_PORT", "443")
ELASTICSEARCH_USERNAME = env.str("ELASTICSEARCH_USERNAME", "")
ELASTICSEARCH_PASSWORD = env.str("ELASTICSEARCH_PASSWORD", "")
ELASTICSEARCH_INDEX_SIAES = env.str("ELASTICSEARCH_INDEX_SIAES", "")
ELASTICSEARCH_MIN_SCORE = env.float("ELASTICSEARCH_MIN_SCORE", 0.9)
7 changes: 0 additions & 7 deletions env.default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,3 @@ export OPENAI_API_BASE=""
export OPENAI_API_KEY=""
export OPENAI_MODEL=""

# ELASTICSEARCH
# ########################
export ELASTICSEARCH_HOST=
export ELASTICSEARCH_USERNAME=
export ELASTICSEARCH_PASSWORD=
export ELASTICSEARCH_INDEX_SIAES=
export ELASTICSEARCH_MIN_SCORE=

This file was deleted.

35 changes: 0 additions & 35 deletions lemarche/siaes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,41 +1192,6 @@ def latest_activity_at(self):
latest_activity_at = self.updated_at
return latest_activity_at

@property
def elasticsearch_index_text(self):
text = self.description
if self.offers.count() > 0:
offers = "\n\nPrestations:\n"
for offer in self.offers.all():
offers += f"- {offer.name}:\n{offer.description}\n\n"
text += offers
return text

@property
def elasticsearch_index_metadata(self):
metadata = {
"id": self.id,
"name": self.name,
"website": self.website if self.website else "",
"kind": self.kind,
}
if self.latitude and self.longitude:
metadata["geo_location"] = {
"lat": self.latitude,
"lon": self.longitude,
}

if self.geo_range == siae_constants.GEO_RANGE_COUNTRY:
metadata["geo_country"] = True
elif self.geo_range == siae_constants.GEO_RANGE_REGION:
metadata["geo_reg"] = self.region
elif self.geo_range == siae_constants.GEO_RANGE_DEPARTMENT:
metadata["geo_dep"] = self.department
elif self.geo_range == siae_constants.GEO_RANGE_CUSTOM:
metadata["geo_dist"] = self.geo_range_custom_distance

return metadata

def sector_groups_list_string(self, display_max=3):
# Retrieve sectors from activities instead of directly from the sectors field
sectors_name_list = set(self.activities.values_list("sector_group__name", flat=True))
Expand Down
4 changes: 0 additions & 4 deletions lemarche/static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ window.addEventListener('DOMContentLoaded', function () {

initModalMessages();

// reload click events and tooltip after htmx content loading as in semantic search
document.addEventListener('htmx:afterSwap', function (event) {
initSuperBadges();
});
initSuperBadges();

// some elements have their url in data-url attribute
Expand Down
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
1 change: 1 addition & 0 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ class TenderAdmin(FieldsetsInlineMixin, admin.ModelAdmin):
"extra_data_display",
"import_raw_object_display",
"logs_display",
"with_ai_matching",
]
formfield_overrides = {
models.TextField: {"widget": CKEditorWidget},
Expand Down
36 changes: 0 additions & 36 deletions lemarche/tenders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from lemarche.tenders.enums import SurveyDoesNotExistQuestionChoices, SurveyScaleQuestionChoices
from lemarche.tenders.utils import find_amount_ranges
from lemarche.users.models import User
from lemarche.utils.apis import api_elasticsearch
from lemarche.utils.constants import (
ADMIN_FIELD_HELP_TEXT,
AUTO_FIELD_HELP_TEXT,
Expand Down Expand Up @@ -748,41 +747,6 @@ def set_siae_found_list(self):
siae_found_list = Siae.objects.filter_with_tender_through_activities(self)
self.siaes.set(siae_found_list, clear=False)

if self.with_ai_matching and self.validated_at is None:
if (
self.location
and self.location.kind == Perimeter.KIND_CITY
and self.distance_location
and self.distance_location > 0
):
# with geo distance
siae_ids = api_elasticsearch.siaes_similarity_search_with_geo_distance(
self.description,
geo_distance=self.distance_location,
geo_lat=self.location.coords.y,
geo_lon=self.location.coords.x,
siae_kinds=self.siae_kind,
)
else:
siae_ids = api_elasticsearch.siaes_similarity_search(self.description, siae_kinds=self.siae_kind)

siaes_had_found_by_ia = Siae.objects.filter(id__in=siae_ids)
siaes_had_found_by_ia_too = []
for siae in siaes_had_found_by_ia:
if siae not in siae_found_list:
self.siaes.add(
siae,
through_defaults={
"source": tender_constants.TENDER_SIAE_SOURCE_AI,
"found_with_ai": True,
},
)
else:
siaes_had_found_by_ia_too.append(siae)

# keep the info that the AI also found those siaes
TenderSiae.objects.filter(tender_id=self.id, siae__in=siaes_had_found_by_ia_too).update(found_with_ai=True)

def save(self, *args, **kwargs):
"""
- update the "last_updated" fields
Expand Down
Loading
Loading