mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 18:17:39 +08:00
Add changes according to milli update
This commit is contained in:
parent
1e659bb17b
commit
aa04124bfc
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1658,8 +1658,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "milli"
|
name = "milli"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/meilisearch/milli.git?tag=v0.2.1#25f75d4d03732131e6edcf20f4d126210b159d43"
|
source = "git+https://github.com/meilisearch/milli.git?tag=v0.3.0#a32236c80cb1334cf249d820e8614ee36ace166e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bstr",
|
"bstr",
|
||||||
|
@ -51,7 +51,7 @@ main_error = "0.1.0"
|
|||||||
meilisearch-error = { path = "../meilisearch-error" }
|
meilisearch-error = { path = "../meilisearch-error" }
|
||||||
meilisearch-tokenizer = { git = "https://github.com/meilisearch/Tokenizer.git", tag = "v0.2.2" }
|
meilisearch-tokenizer = { git = "https://github.com/meilisearch/Tokenizer.git", tag = "v0.2.2" }
|
||||||
memmap = "0.7.0"
|
memmap = "0.7.0"
|
||||||
milli = { git = "https://github.com/meilisearch/milli.git", tag = "v0.2.1" }
|
milli = { git = "https://github.com/meilisearch/milli.git", tag = "v0.3.0" }
|
||||||
mime = "0.3.16"
|
mime = "0.3.16"
|
||||||
once_cell = "1.5.2"
|
once_cell = "1.5.2"
|
||||||
oxidized-json-checker = "0.3.2"
|
oxidized-json-checker = "0.3.2"
|
||||||
|
@ -67,7 +67,6 @@ impl Index {
|
|||||||
let faceted_attributes = self
|
let faceted_attributes = self
|
||||||
.faceted_fields(&txn)?
|
.faceted_fields(&txn)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(k, v)| (k, v.to_string()))
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let criteria = self
|
let criteria = self
|
||||||
@ -83,7 +82,7 @@ impl Index {
|
|||||||
})
|
})
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or_else(BTreeSet::new);
|
.unwrap_or_else(BTreeSet::new);
|
||||||
let distinct_attribute = self.distinct_attribute(&txn)?.map(String::from);
|
let distinct_field = self.distinct_field(&txn)?.map(String::from);
|
||||||
|
|
||||||
Ok(Settings {
|
Ok(Settings {
|
||||||
displayed_attributes: Some(displayed_attributes),
|
displayed_attributes: Some(displayed_attributes),
|
||||||
@ -91,7 +90,7 @@ impl Index {
|
|||||||
attributes_for_faceting: Some(Some(faceted_attributes)),
|
attributes_for_faceting: Some(Some(faceted_attributes)),
|
||||||
ranking_rules: Some(Some(criteria)),
|
ranking_rules: Some(Some(criteria)),
|
||||||
stop_words: Some(Some(stop_words)),
|
stop_words: Some(Some(stop_words)),
|
||||||
distinct_attribute: Some(distinct_attribute),
|
distinct_attribute: Some(distinct_field),
|
||||||
_kind: PhantomData,
|
_kind: PhantomData,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use heed::RoTxn;
|
|||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use meilisearch_tokenizer::{Analyzer, AnalyzerConfig};
|
use meilisearch_tokenizer::{Analyzer, AnalyzerConfig};
|
||||||
use milli::{facet::FacetValue, FacetCondition, FieldId, FieldsIdsMap, MatchingWords};
|
use milli::{FilterCondition, FieldId, FieldsIdsMap, MatchingWords};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ pub struct SearchResult {
|
|||||||
pub offset: usize,
|
pub offset: usize,
|
||||||
pub processing_time_ms: u128,
|
pub processing_time_ms: u128,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub facet_distributions: Option<BTreeMap<String, BTreeMap<FacetValue, u64>>>,
|
pub facet_distributions: Option<BTreeMap<String, BTreeMap<String, u64>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index {
|
impl Index {
|
||||||
@ -74,9 +74,15 @@ impl Index {
|
|||||||
search.limit(query.limit);
|
search.limit(query.limit);
|
||||||
search.offset(query.offset.unwrap_or_default());
|
search.offset(query.offset.unwrap_or_default());
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
if let Some(ref filter) = query.filter {
|
if let Some(ref filter) = query.filter {
|
||||||
if let Some(facets) = parse_facets(filter, self, &rtxn)? {
|
if let Some(facets) = parse_facets(filter, self, &rtxn)? {
|
||||||
search.facet_condition(facets);
|
search.facet_condition(facets);
|
||||||
|
=======
|
||||||
|
if let Some(ref facets) = query.facet_filters {
|
||||||
|
if let Some(facets) = parse_facets(facets, self, &rtxn)? {
|
||||||
|
search.filter(facets);
|
||||||
|
>>>>>>> 562cc32 (Add changes according to milli update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,10 +278,42 @@ impl Matcher for HashSet<String> {
|
|||||||
|
|
||||||
impl Matcher for MatchingWords {
|
impl Matcher for MatchingWords {
|
||||||
fn matches(&self, w: &str) -> bool {
|
fn matches(&self, w: &str) -> bool {
|
||||||
self.matches(w)
|
self.matching_bytes(w).is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
fn parse_facets_array(
|
||||||
|
txn: &RoTxn,
|
||||||
|
index: &Index,
|
||||||
|
arr: &[Value],
|
||||||
|
) -> anyhow::Result<Option<FilterCondition>> {
|
||||||
|
let mut ands = Vec::new();
|
||||||
|
for value in arr {
|
||||||
|
match value {
|
||||||
|
Value::String(s) => ands.push(Either::Right(s.clone())),
|
||||||
|
Value::Array(arr) => {
|
||||||
|
let mut ors = Vec::new();
|
||||||
|
for value in arr {
|
||||||
|
match value {
|
||||||
|
Value::String(s) => ors.push(s.clone()),
|
||||||
|
v => bail!("Invalid facet expression, expected String, found: {:?}", v),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ands.push(Either::Left(ors));
|
||||||
|
}
|
||||||
|
v => bail!(
|
||||||
|
"Invalid facet expression, expected String or [String], found: {:?}",
|
||||||
|
v
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FilterCondition::from_array(txn, &index.0, ands)
|
||||||
|
}
|
||||||
|
|
||||||
|
>>>>>>> 562cc32 (Add changes according to milli update)
|
||||||
struct Highlighter<'a, A> {
|
struct Highlighter<'a, A> {
|
||||||
analyzer: Analyzer<'a, A>,
|
analyzer: Analyzer<'a, A>,
|
||||||
marks: (String, String),
|
marks: (String, String),
|
||||||
@ -335,7 +373,7 @@ fn parse_facets(
|
|||||||
facets: &Value,
|
facets: &Value,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &RoTxn,
|
txn: &RoTxn,
|
||||||
) -> anyhow::Result<Option<FacetCondition>> {
|
) -> anyhow::Result<Option<FilterCondition>> {
|
||||||
match facets {
|
match facets {
|
||||||
Value::String(expr) => Ok(Some(FacetCondition::from_str(txn, index, expr)?)),
|
Value::String(expr) => Ok(Some(FacetCondition::from_str(txn, index, expr)?)),
|
||||||
Value::Array(arr) => parse_facets_array(txn, index, arr),
|
Value::Array(arr) => parse_facets_array(txn, index, arr),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::{BTreeSet, HashMap};
|
use std::collections::{BTreeSet, HashSet};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
@ -51,7 +51,7 @@ pub struct Settings<T> {
|
|||||||
deserialize_with = "deserialize_some",
|
deserialize_with = "deserialize_some",
|
||||||
skip_serializing_if = "Option::is_none"
|
skip_serializing_if = "Option::is_none"
|
||||||
)]
|
)]
|
||||||
pub attributes_for_faceting: Option<Option<HashMap<String, String>>>,
|
pub attributes_for_faceting: Option<Option<HashSet<String>>>,
|
||||||
|
|
||||||
#[serde(
|
#[serde(
|
||||||
default,
|
default,
|
||||||
@ -253,8 +253,8 @@ impl Index {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref facet_types) = settings.attributes_for_faceting {
|
if let Some(ref facet_types) = settings.attributes_for_faceting {
|
||||||
let facet_types = facet_types.clone().unwrap_or_else(HashMap::new);
|
let facet_types = facet_types.clone().unwrap_or_else(HashSet::new);
|
||||||
builder.set_faceted_fields(facet_types);
|
builder.set_filterable_fields(facet_types);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref criteria) = settings.ranking_rules {
|
if let Some(ref criteria) = settings.ranking_rules {
|
||||||
@ -273,8 +273,8 @@ impl Index {
|
|||||||
|
|
||||||
if let Some(ref distinct_attribute) = settings.distinct_attribute {
|
if let Some(ref distinct_attribute) = settings.distinct_attribute {
|
||||||
match distinct_attribute {
|
match distinct_attribute {
|
||||||
Some(attr) => builder.set_distinct_attribute(attr.clone()),
|
Some(attr) => builder.set_distinct_field(attr.clone()),
|
||||||
None => builder.reset_distinct_attribute(),
|
None => builder.reset_distinct_field(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ impl From<Settings> for index_controller::Settings<Unchecked> {
|
|||||||
// representing the name of the faceted field + the type of the field. Since the type
|
// representing the name of the faceted field + the type of the field. Since the type
|
||||||
// was not known in the V1 of the dump we are just going to assume everything is a
|
// was not known in the V1 of the dump we are just going to assume everything is a
|
||||||
// String
|
// String
|
||||||
attributes_for_faceting: settings.attributes_for_faceting.map(|o| o.map(|vec| vec.into_iter().map(|key| (key, String::from("string"))).collect())),
|
attributes_for_faceting: settings.attributes_for_faceting.map(|o| o.map(|vec| vec.into_iter().collect())),
|
||||||
// we need to convert the old `Vec<String>` into a `BTreeSet<String>`
|
// we need to convert the old `Vec<String>` into a `BTreeSet<String>`
|
||||||
ranking_rules: settings.ranking_rules.map(|o| o.map(|vec| vec.into_iter().filter_map(|criterion| {
|
ranking_rules: settings.ranking_rules.map(|o| o.map(|vec| vec.into_iter().filter_map(|criterion| {
|
||||||
match criterion.as_str() {
|
match criterion.as_str() {
|
||||||
|
@ -75,7 +75,7 @@ macro_rules! make_setting_route {
|
|||||||
|
|
||||||
make_setting_route!(
|
make_setting_route!(
|
||||||
"/indexes/{index_uid}/settings/attributes-for-faceting",
|
"/indexes/{index_uid}/settings/attributes-for-faceting",
|
||||||
std::collections::HashMap<String, String>,
|
std::collections::HashSet<String>,
|
||||||
attributes_for_faceting
|
attributes_for_faceting
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user