mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 20:15:07 +08:00
Introduce an optimization when the searchable attributes are ordered
This commit is contained in:
parent
01c4f5abcd
commit
a31db33e93
@ -69,6 +69,21 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||||||
|
|
||||||
let result = match value {
|
let result = match value {
|
||||||
Some(fields_names) => {
|
Some(fields_names) => {
|
||||||
|
let mut fields_ids_map = current_fields_ids_map.clone();
|
||||||
|
let searchable_fields: Vec<_> =
|
||||||
|
fields_names.iter()
|
||||||
|
.map(|name| fields_ids_map.insert(name))
|
||||||
|
.collect::<Option<Vec<_>>>()
|
||||||
|
.context("field id limit reached")?;
|
||||||
|
|
||||||
|
// If the searchable fields are ordered we don't have to generate a new `FieldsIdsMap`.
|
||||||
|
if searchable_fields.windows(2).all(|win| win[0] < win[1]) {
|
||||||
|
(
|
||||||
|
fields_ids_map,
|
||||||
|
Some(searchable_fields),
|
||||||
|
current_displayed_fields.map(ToOwned::to_owned),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
// We create or generate the fields ids corresponding to those names.
|
// We create or generate the fields ids corresponding to those names.
|
||||||
let mut fields_ids_map = FieldsIdsMap::new();
|
let mut fields_ids_map = FieldsIdsMap::new();
|
||||||
let mut searchable_fields = Vec::new();
|
let mut searchable_fields = Vec::new();
|
||||||
@ -97,6 +112,7 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
(fields_ids_map, Some(searchable_fields), displayed_fields)
|
(fields_ids_map, Some(searchable_fields), displayed_fields)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
None => (
|
None => (
|
||||||
current_fields_ids_map.clone(),
|
current_fields_ids_map.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user