Merge pull request #72 from meilisearch/enable-criterion

enable criterion setting
This commit is contained in:
marin 2021-03-08 14:08:16 +01:00 committed by GitHub
commit 9d421d5ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 19 deletions

3
Cargo.lock generated
View File

@ -1726,7 +1726,7 @@ dependencies = [
[[package]]
name = "milli"
version = "0.1.0"
source = "git+https://github.com/meilisearch/milli.git?rev=794fce7#794fce7bff3e3461a7f3954fd97f58f8232e5a8e"
source = "git+https://github.com/meilisearch/milli.git?rev=f190d5f#f190d5f496cc39517b6a81300c6dee9b6dba7a38"
dependencies = [
"anyhow",
"bstr",
@ -1757,6 +1757,7 @@ dependencies = [
"roaring",
"serde",
"serde_json",
"slice-group-by",
"smallstr",
"smallvec",
"tempfile",

View File

@ -38,7 +38,7 @@ main_error = "0.1.0"
meilisearch-error = { path = "../meilisearch-error" }
meilisearch-tokenizer = { git = "https://github.com/meilisearch/Tokenizer.git", branch = "main" }
memmap = "0.7.0"
milli = { git = "https://github.com/meilisearch/milli.git", rev = "794fce7" }
milli = { git = "https://github.com/meilisearch/milli.git", rev = "f190d5f" }
mime = "0.3.16"
once_cell = "1.5.2"
rand = "0.7.3"

View File

@ -107,11 +107,17 @@ impl Data {
.map(|(k, v)| (k, v.to_string()))
.collect();
let criteria = index
.criteria(&txn)?
.into_iter()
.map(|v| v.to_string())
.collect();
Ok(Settings {
displayed_attributes: Some(Some(displayed_attributes)),
searchable_attributes: Some(Some(searchable_attributes)),
faceted_attributes: Some(Some(faceted_attributes)),
criteria: None,
ranking_rules: Some(Some(criteria)),
})
}

View File

@ -6,7 +6,7 @@ use anyhow::{bail, Context};
use either::Either;
use heed::RoTxn;
use meilisearch_tokenizer::{Analyzer, AnalyzerConfig};
use milli::{obkv_to_json, FacetCondition, Index, facet::FacetValue};
use milli::{FacetCondition, Index, MatchingWords, facet::FacetValue, obkv_to_json};
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
@ -60,7 +60,7 @@ impl SearchQuery {
let milli::SearchResult {
documents_ids,
found_words,
matching_words,
candidates,
} = search.execute()?;
@ -91,7 +91,7 @@ impl SearchQuery {
for (_id, obkv) in index.documents(&rtxn, documents_ids)? {
let mut object = obkv_to_json(&displayed_fields_ids, &fields_ids_map, obkv)?;
if let Some(ref attributes_to_highlight) = self.attributes_to_highlight {
highlighter.highlight_record(&mut object, &found_words, attributes_to_highlight);
highlighter.highlight_record(&mut object, &matching_words, attributes_to_highlight);
}
documents.push(object);
}
@ -144,7 +144,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
Self { analyzer }
}
fn highlight_value(&self, value: Value, words_to_highlight: &HashSet<String>) -> Value {
fn highlight_value(&self, value: Value, words_to_highlight: &MatchingWords) -> Value {
match value {
Value::Null => Value::Null,
Value::Bool(boolean) => Value::Bool(boolean),
@ -154,7 +154,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
let analyzed = self.analyzer.analyze(&old_string);
for (word, token) in analyzed.reconstruct() {
if token.is_word() {
let to_highlight = words_to_highlight.contains(token.text());
let to_highlight = words_to_highlight.matches(token.text());
if to_highlight {
string.push_str("<mark>")
}
@ -186,7 +186,7 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
fn highlight_record(
&self,
object: &mut Map<String, Value>,
words_to_highlight: &HashSet<String>,
words_to_highlight: &MatchingWords,
attributes_to_highlight: &HashSet<String>,
) {
// TODO do we need to create a string for element that are not and needs to be highlight?

View File

@ -153,7 +153,7 @@ impl UpdateHandler {
}
// We transpose the settings JSON struct into a real setting update.
if let Some(ref criteria) = settings.criteria {
if let Some(ref criteria) = settings.ranking_rules {
match criteria {
Some(criteria) => builder.set_criteria(criteria.clone()),
None => builder.reset_criteria(),

View File

@ -83,7 +83,7 @@ pub struct Settings {
deserialize_with = "deserialize_some",
skip_serializing_if = "Option::is_none",
)]
pub criteria: Option<Option<Vec<String>>>,
pub ranking_rules: Option<Option<Vec<String>>>,
}
impl Settings {
@ -92,7 +92,7 @@ impl Settings {
displayed_attributes: Some(None),
searchable_attributes: Some(None),
faceted_attributes: Some(None),
criteria: Some(None),
ranking_rules: Some(None),
}
}
}

View File

@ -103,11 +103,11 @@ make_setting_route!(
//distinct_attribute
//);
//make_setting_route!(
//"/indexes/{index_uid}/settings/ranking-rules",
//Vec<String>,
//ranking_rules
//);
make_setting_route!(
"/indexes/{index_uid}/settings/ranking-rules",
Vec<String>,
ranking_rules
);
macro_rules! create_services {
($($mod:ident),*) => {
@ -128,7 +128,8 @@ macro_rules! create_services {
create_services!(
faceted_attributes,
displayed_attributes,
searchable_attributes
searchable_attributes,
ranking_rules
);
#[post("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]

View File

@ -16,10 +16,11 @@ async fn get_settings() {
let (response, code) = index.settings().await;
assert_eq!(code, 200);
let settings = response.as_object().unwrap();
assert_eq!(settings.keys().len(), 3);
assert_eq!(settings.keys().len(), 4);
assert_eq!(settings["displayedAttributes"], json!(["*"]));
assert_eq!(settings["searchableAttributes"], json!(["*"]));
assert_eq!(settings["facetedAttributes"], json!({}));
assert_eq!(settings["rankingRules"], json!(["typo", "words", "proximity", "attribute", "wordsPosition", "exactness"]));
}
#[actix_rt::test]