Rank exact extension ID matches higher in search results (#14588)
Release Notes: - Improved relevance of extension search results Co-authored-by: Marshall <marshall@zed.dev>
This commit is contained in:
parent
cf8bd4a90a
commit
cb6fc11abc
3 changed files with 42 additions and 4 deletions
|
@ -10,7 +10,7 @@ use axum::{
|
|||
Extension, Json, Router,
|
||||
};
|
||||
use collections::HashMap;
|
||||
use rpc::{ExtensionApiManifest, GetExtensionsResponse};
|
||||
use rpc::{ExtensionApiManifest, ExtensionMetadata, GetExtensionsResponse};
|
||||
use semantic_version::SemanticVersion;
|
||||
use serde::Deserialize;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
@ -43,7 +43,7 @@ async fn get_extensions(
|
|||
Extension(app): Extension<Arc<AppState>>,
|
||||
Query(params): Query<GetExtensionsParams>,
|
||||
) -> Result<Json<GetExtensionsResponse>> {
|
||||
let extensions = app
|
||||
let mut extensions = app
|
||||
.db
|
||||
.get_extensions(params.filter.as_deref(), params.max_schema_version, 500)
|
||||
.await?;
|
||||
|
@ -53,6 +53,23 @@ async fn get_extensions(
|
|||
tracing::info!(query, count, "extension_search")
|
||||
}
|
||||
|
||||
if let Some(filter) = params.filter.as_deref() {
|
||||
let mut exact_match: Option<ExtensionMetadata> = None;
|
||||
extensions.retain(|extension| {
|
||||
exact_match = Some(extension.clone());
|
||||
extension.id.as_ref() != &filter.to_lowercase()
|
||||
});
|
||||
if exact_match == None {
|
||||
exact_match = app
|
||||
.db
|
||||
.get_extensions_by_ids(&[&filter.to_lowercase()], None)
|
||||
.await?
|
||||
.first()
|
||||
.cloned();
|
||||
}
|
||||
extensions.splice(0..0, exact_match);
|
||||
};
|
||||
|
||||
Ok(Json(GetExtensionsResponse { data: extensions }))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue