mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 12:27:13 +02:00
Introduce the sort search parameter
This commit is contained in:
parent
ea4c831de0
commit
e0f73fe742
2 changed files with 23 additions and 7 deletions
|
@ -1,15 +1,17 @@
|
|||
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
||||
use std::str::FromStr;
|
||||
use std::time::Instant;
|
||||
|
||||
use either::Either;
|
||||
use heed::RoTxn;
|
||||
use indexmap::IndexMap;
|
||||
use meilisearch_tokenizer::{Analyzer, AnalyzerConfig, Token};
|
||||
use milli::{FieldId, FieldsIdsMap, FilterCondition, MatchingWords};
|
||||
use milli::{AscDesc, FieldId, FieldsIdsMap, FilterCondition, MatchingWords};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::index::error::FacetError;
|
||||
use crate::index::IndexError;
|
||||
|
||||
use super::error::Result;
|
||||
use super::Index;
|
||||
|
@ -49,6 +51,7 @@ pub struct SearchQuery {
|
|||
#[serde(default = "Default::default")]
|
||||
pub matches: bool,
|
||||
pub filter: Option<Value>,
|
||||
pub sort: Option<Vec<String>>,
|
||||
pub facets_distribution: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
|
@ -104,6 +107,15 @@ impl Index {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(ref sort) = query.sort {
|
||||
let sort = match sort.iter().map(|s| AscDesc::from_str(s)).collect() {
|
||||
Ok(sorts) => sorts,
|
||||
Err(err) => return Err(IndexError::Milli(err.into())),
|
||||
};
|
||||
|
||||
search.sort_criteria(sort);
|
||||
}
|
||||
|
||||
let milli::SearchResult {
|
||||
documents_ids,
|
||||
matching_words,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue