web search done right
autosuggest browser
Mikkel Denker95fb9a871d94
diff --git a/core/src/api/autosuggest.rs b/core/src/api/autosuggest.rsindex a43dffff..9de14e4b 100644--- a/core/src/api/autosuggest.rs+++ b/core/src/api/autosuggest.rs@@ -61,6 +61,7 @@ pub struct AutosuggestQuery {(status = 200, description = "Autosuggest", body = Vec<Suggestion>),))]+pub async fn route(extract::State(state): extract::State<Arc<State>>,extract::Query(params): extract::Query<HashMap<String, String>>,@@ -82,6 +83,17 @@ pub async fn route(}}+pub async fn browser(+ extract::State(state): extract::State<Arc<State>>,+ extract::Query(params): extract::Query<HashMap<String, String>>,+) -> impl IntoResponse {+ if let Some(query) = params.get("q") {+ Json((query.clone(), state.autosuggest.suggestions(query).unwrap()))+ } else {+ Json((String::new(), Vec::new()))+ }+}+#[cfg(test)]mod tests {use super::*;diff --git a/core/src/api/mod.rs b/core/src/api/mod.rsindex bf03763e..0ffa1e5f 100644--- a/core/src/api/mod.rs+++ b/core/src/api/mod.rs@@ -169,6 +169,7 @@ pub async fn router(config: &ApiConfig, counters: Counters) -> Result<Router> {"/beta",Router::new().route("/api/autosuggest", post(autosuggest::route))+ .route("/api/autosuggest/browser", get(autosuggest::browser)).route("/api/summarize", get(summarize::summarize_route)).route("/api/webgraph/similar_sites", post(webgraph::similar_sites)).route("/api/webgraph/knows_site", post(webgraph::knows_site))diff --git a/frontend/static/opensearch.xml b/frontend/static/opensearch.xmlindex 6cc7fc08..bbe1d723 100644--- a/frontend/static/opensearch.xml+++ b/frontend/static/opensearch.xml@@ -4,6 +4,6 @@<InputEncoding>UTF-8</InputEncoding><Image width="32" height="32" type="image/x-icon">https://trystract.com/favicon.ico</Image><Url rel="results" type="text/html" template="https://trystract.com/search?q={searchTerms}"/>- <Url rel="suggestions" type="application/x-suggestions+json" template="https://trystract.com/autosuggest/browser?q={searchTerms}"/>+ <Url rel="suggestions" type="application/x-suggestions+json" template="https://trystract.com/beta/api/autosuggest/browser?q={searchTerms}"/><moz:SearchForm>https://trystract.com/</moz:SearchForm></OpenSearchDescription>