Support a basic facet based query system

This commit is contained in:
Clément Renault 2020-11-14 13:21:22 +01:00
parent 1d5795d134
commit 2341b99379
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
3 changed files with 166 additions and 12 deletions

View file

@ -28,7 +28,7 @@ use warp::{Filter, http::Response};
use milli::tokenizer::{simple_tokenizer, TokenType};
use milli::update::UpdateIndexingStep::*;
use milli::update::{UpdateBuilder, IndexDocumentsMethod, UpdateFormat};
use milli::{obkv_to_json, Index, UpdateStore, SearchResult};
use milli::{obkv_to_json, Index, UpdateStore, SearchResult, FacetCondition};
static GLOBAL_THREAD_POOL: OnceCell<ThreadPool> = OnceCell::new();
@ -550,9 +550,12 @@ async fn main() -> anyhow::Result<()> {
.body(include_str!("../public/logo-black.svg"))
);
#[derive(Deserialize)]
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
struct QueryBody {
query: Option<String>,
facet_condition: Option<String>,
}
let disable_highlighting = opt.disable_highlighting;
@ -569,6 +572,10 @@ async fn main() -> anyhow::Result<()> {
if let Some(query) = query.query {
search.query(query);
}
if let Some(condition) = query.facet_condition {
let condition = FacetCondition::from_str(&rtxn, &index, &condition).unwrap();
search.facet_condition(condition);
}
let SearchResult { found_words, documents_ids } = search.execute().unwrap();