From ef3bad811abc57b2741b270634d185b0ab78b73e Mon Sep 17 00:00:00 2001 From: aecsocket <43144841+aecsocket@users.noreply.github.com> Date: Sun, 2 Aug 2026 16:38:22 +0100 Subject: [PATCH] approach parity even without explicit parity enabled --- .../src/search/backend/elasticsearch/mod.rs | 65 ++++++++++++++++--- .../backend/elasticsearch/typesense_parity.rs | 2 - 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/apps/labrinth/src/search/backend/elasticsearch/mod.rs b/apps/labrinth/src/search/backend/elasticsearch/mod.rs index 9fdac2204b..ebcbf60f6f 100644 --- a/apps/labrinth/src/search/backend/elasticsearch/mod.rs +++ b/apps/labrinth/src/search/backend/elasticsearch/mod.rs @@ -739,6 +739,12 @@ impl Elasticsearch { "project_id": {"type": "keyword"}, "project_types": {"type": "keyword"}, "all_project_types": {"type": "keyword"}, + "slug": Self::native_text_field_schema(), + "author": Self::native_text_field_schema(), + "indexed_author": Self::native_text_field_schema(), + "name": Self::native_text_field_schema(), + "indexed_name": Self::native_text_field_schema(), + "summary": Self::native_text_field_schema(), "categories": {"type": "keyword"}, "project_categories": {"type": "keyword"}, "display_categories": {"type": "keyword"}, @@ -779,6 +785,22 @@ impl Elasticsearch { }) } + fn native_text_field_schema() -> Value { + json!({ + "type": "text", + "index_prefixes": { + "min_chars": 1, + "max_chars": 10 + }, + "fields": { + "keyword": { + "type": "keyword", + "ignore_above": 256 + } + } + }) + } + async fn import_projects( &self, indices: &[String], @@ -862,20 +884,45 @@ impl Elasticsearch { } json!({ - "multi_match": { - "query": query, - "fields": [ - "name", - "indexed_name", - "slug", - "author", - "indexed_author", - "summary" + "dis_max": { + "queries": [ + Self::native_prefix_tier(query, &["name"], 4), + Self::native_prefix_tier( + query, + &["indexed_name", "slug"], + 3, + ), + Self::native_prefix_tier( + query, + &["author", "indexed_author"], + 2, + ), + Self::native_prefix_tier(query, &["summary"], 1), ] } }) } + fn native_prefix_tier( + query: &str, + fields: &[&str], + boost: u8, + ) -> Value { + json!({ + "constant_score": { + "filter": { + "multi_match": { + "query": query, + "type": "bool_prefix", + "operator": "and", + "fields": fields + } + }, + "boost": boost + } + }) + } + async fn search_for_project_raw_native( &self, info: &SearchRequest, diff --git a/apps/labrinth/src/search/backend/elasticsearch/typesense_parity.rs b/apps/labrinth/src/search/backend/elasticsearch/typesense_parity.rs index 8da91481b0..1cf44f1539 100644 --- a/apps/labrinth/src/search/backend/elasticsearch/typesense_parity.rs +++ b/apps/labrinth/src/search/backend/elasticsearch/typesense_parity.rs @@ -1852,8 +1852,6 @@ impl Elasticsearch { pub(super) fn typesense_parity_index_schema() -> Value { json!({ "settings": { - "number_of_shards": 3, - "number_of_replicas": 1, "refresh_interval": "30s", "index.mapping.total_fields.limit": 5000, "analysis": {