Introduce the sort search parameter

This commit is contained in:
Kerollmops 2021-08-24 12:31:35 +02:00
parent ea4c831de0
commit e0f73fe742
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
2 changed files with 23 additions and 7 deletions

View file

@ -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,