approach parity even without explicit parity enabled

This commit is contained in:
aecsocket
2026-08-02 16:38:22 +01:00
parent c12fee2f7b
commit ef3bad811a
2 changed files with 56 additions and 11 deletions
@@ -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,
@@ -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": {