mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 18:17:39 +08:00
Replace the BTreeMap by an IndexMap to return values in order
This commit is contained in:
parent
34b2e98fe9
commit
a385642ec3
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2731,6 +2731,7 @@ dependencies = [
|
|||||||
"grenad",
|
"grenad",
|
||||||
"heed",
|
"heed",
|
||||||
"hnsw",
|
"hnsw",
|
||||||
|
"indexmap",
|
||||||
"insta",
|
"insta",
|
||||||
"itertools",
|
"itertools",
|
||||||
"json-depth-checker",
|
"json-depth-checker",
|
||||||
|
@ -14,14 +14,27 @@ default-run = "meilisearch"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-cors = "0.6.4"
|
actix-cors = "0.6.4"
|
||||||
actix-http = { version = "3.3.1", default-features = false, features = ["compress-brotli", "compress-gzip", "rustls"] }
|
actix-http = { version = "3.3.1", default-features = false, features = [
|
||||||
actix-web = { version = "4.3.1", default-features = false, features = ["macros", "compress-brotli", "compress-gzip", "cookies", "rustls"] }
|
"compress-brotli",
|
||||||
|
"compress-gzip",
|
||||||
|
"rustls",
|
||||||
|
] }
|
||||||
|
actix-web = { version = "4.3.1", default-features = false, features = [
|
||||||
|
"macros",
|
||||||
|
"compress-brotli",
|
||||||
|
"compress-gzip",
|
||||||
|
"cookies",
|
||||||
|
"rustls",
|
||||||
|
] }
|
||||||
actix-web-static-files = { git = "https://github.com/kilork/actix-web-static-files.git", rev = "2d3b6160", optional = true }
|
actix-web-static-files = { git = "https://github.com/kilork/actix-web-static-files.git", rev = "2d3b6160", optional = true }
|
||||||
anyhow = { version = "1.0.70", features = ["backtrace"] }
|
anyhow = { version = "1.0.70", features = ["backtrace"] }
|
||||||
async-stream = "0.3.5"
|
async-stream = "0.3.5"
|
||||||
async-trait = "0.1.68"
|
async-trait = "0.1.68"
|
||||||
bstr = "1.4.0"
|
bstr = "1.4.0"
|
||||||
byte-unit = { version = "4.0.19", default-features = false, features = ["std", "serde"] }
|
byte-unit = { version = "4.0.19", default-features = false, features = [
|
||||||
|
"std",
|
||||||
|
"serde",
|
||||||
|
] }
|
||||||
bytes = "1.4.0"
|
bytes = "1.4.0"
|
||||||
clap = { version = "4.2.1", features = ["derive", "env"] }
|
clap = { version = "4.2.1", features = ["derive", "env"] }
|
||||||
crossbeam-channel = "0.5.8"
|
crossbeam-channel = "0.5.8"
|
||||||
@ -57,7 +70,10 @@ prometheus = { version = "0.13.3", features = ["process"] }
|
|||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rayon = "1.7.0"
|
rayon = "1.7.0"
|
||||||
regex = "1.7.3"
|
regex = "1.7.3"
|
||||||
reqwest = { version = "0.11.16", features = ["rustls-tls", "json"], default-features = false }
|
reqwest = { version = "0.11.16", features = [
|
||||||
|
"rustls-tls",
|
||||||
|
"json",
|
||||||
|
], default-features = false }
|
||||||
rustls = "0.20.8"
|
rustls = "0.20.8"
|
||||||
rustls-pemfile = "1.0.2"
|
rustls-pemfile = "1.0.2"
|
||||||
segment = { version = "0.2.2", optional = true }
|
segment = { version = "0.2.2", optional = true }
|
||||||
@ -71,7 +87,12 @@ sysinfo = "0.28.4"
|
|||||||
tar = "0.4.38"
|
tar = "0.4.38"
|
||||||
tempfile = "3.5.0"
|
tempfile = "3.5.0"
|
||||||
thiserror = "1.0.40"
|
thiserror = "1.0.40"
|
||||||
time = { version = "0.3.20", features = ["serde-well-known", "formatting", "parsing", "macros"] }
|
time = { version = "0.3.20", features = [
|
||||||
|
"serde-well-known",
|
||||||
|
"formatting",
|
||||||
|
"parsing",
|
||||||
|
"macros",
|
||||||
|
] }
|
||||||
tokio = { version = "1.27.0", features = ["full"] }
|
tokio = { version = "1.27.0", features = ["full"] }
|
||||||
tokio-stream = "0.1.12"
|
tokio-stream = "0.1.12"
|
||||||
toml = "0.7.3"
|
toml = "0.7.3"
|
||||||
@ -90,7 +111,7 @@ brotli = "3.3.4"
|
|||||||
insta = "1.29.0"
|
insta = "1.29.0"
|
||||||
manifest-dir-macros = "0.1.16"
|
manifest-dir-macros = "0.1.16"
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
meili-snap = {path = "../meili-snap"}
|
meili-snap = { path = "../meili-snap" }
|
||||||
temp-env = "0.3.3"
|
temp-env = "0.3.3"
|
||||||
urlencoding = "2.1.2"
|
urlencoding = "2.1.2"
|
||||||
yaup = "0.2.1"
|
yaup = "0.2.1"
|
||||||
@ -99,7 +120,10 @@ yaup = "0.2.1"
|
|||||||
anyhow = { version = "1.0.70", optional = true }
|
anyhow = { version = "1.0.70", optional = true }
|
||||||
cargo_toml = { version = "0.15.2", optional = true }
|
cargo_toml = { version = "0.15.2", optional = true }
|
||||||
hex = { version = "0.4.3", optional = true }
|
hex = { version = "0.4.3", optional = true }
|
||||||
reqwest = { version = "0.11.16", features = ["blocking", "rustls-tls"], default-features = false, optional = true }
|
reqwest = { version = "0.11.16", features = [
|
||||||
|
"blocking",
|
||||||
|
"rustls-tls",
|
||||||
|
], default-features = false, optional = true }
|
||||||
sha-1 = { version = "0.10.1", optional = true }
|
sha-1 = { version = "0.10.1", optional = true }
|
||||||
static-files = { version = "0.2.3", optional = true }
|
static-files = { version = "0.2.3", optional = true }
|
||||||
tempfile = { version = "3.5.0", optional = true }
|
tempfile = { version = "3.5.0", optional = true }
|
||||||
@ -109,7 +133,17 @@ zip = { version = "0.6.4", optional = true }
|
|||||||
[features]
|
[features]
|
||||||
default = ["analytics", "meilisearch-types/all-tokenizations", "mini-dashboard"]
|
default = ["analytics", "meilisearch-types/all-tokenizations", "mini-dashboard"]
|
||||||
analytics = ["segment"]
|
analytics = ["segment"]
|
||||||
mini-dashboard = ["actix-web-static-files", "static-files", "anyhow", "cargo_toml", "hex", "reqwest", "sha-1", "tempfile", "zip"]
|
mini-dashboard = [
|
||||||
|
"actix-web-static-files",
|
||||||
|
"static-files",
|
||||||
|
"anyhow",
|
||||||
|
"cargo_toml",
|
||||||
|
"hex",
|
||||||
|
"reqwest",
|
||||||
|
"sha-1",
|
||||||
|
"tempfile",
|
||||||
|
"zip",
|
||||||
|
]
|
||||||
chinese = ["meilisearch-types/chinese"]
|
chinese = ["meilisearch-types/chinese"]
|
||||||
hebrew = ["meilisearch-types/hebrew"]
|
hebrew = ["meilisearch-types/hebrew"]
|
||||||
japanese = ["meilisearch-types/japanese"]
|
japanese = ["meilisearch-types/japanese"]
|
||||||
|
@ -6,6 +6,7 @@ use std::time::Instant;
|
|||||||
use deserr::Deserr;
|
use deserr::Deserr;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use index_scheduler::RoFeatures;
|
use index_scheduler::RoFeatures;
|
||||||
|
use indexmap::IndexMap;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use meilisearch_auth::IndexSearchRules;
|
use meilisearch_auth::IndexSearchRules;
|
||||||
use meilisearch_types::deserr::DeserrJsonError;
|
use meilisearch_types::deserr::DeserrJsonError;
|
||||||
@ -279,7 +280,7 @@ pub struct SearchResult {
|
|||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub hits_info: HitsInfo,
|
pub hits_info: HitsInfo,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub facet_distribution: Option<BTreeMap<String, BTreeMap<String, u64>>>,
|
pub facet_distribution: Option<BTreeMap<String, IndexMap<String, u64>>>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub facet_stats: Option<BTreeMap<String, FacetStats>>,
|
pub facet_stats: Option<BTreeMap<String, FacetStats>>,
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ heed = { git = "https://github.com/meilisearch/heed", tag = "v0.12.6", default-f
|
|||||||
"sync-read-txn",
|
"sync-read-txn",
|
||||||
] }
|
] }
|
||||||
hnsw = { version = "0.11.0", features = ["serde1"] }
|
hnsw = { version = "0.11.0", features = ["serde1"] }
|
||||||
|
indexmap = { version = "1.9.3", features = ["serde"] }
|
||||||
json-depth-checker = { path = "../json-depth-checker" }
|
json-depth-checker = { path = "../json-depth-checker" }
|
||||||
levenshtein_automata = { version = "0.2.1", features = ["fst_automaton"] }
|
levenshtein_automata = { version = "0.2.1", features = ["fst_automaton"] }
|
||||||
memmap2 = "0.5.10"
|
memmap2 = "0.5.10"
|
||||||
|
@ -4,6 +4,7 @@ use std::{fmt, mem};
|
|||||||
|
|
||||||
use heed::types::ByteSlice;
|
use heed::types::ByteSlice;
|
||||||
use heed::BytesDecode;
|
use heed::BytesDecode;
|
||||||
|
use indexmap::IndexMap;
|
||||||
use roaring::RoaringBitmap;
|
use roaring::RoaringBitmap;
|
||||||
|
|
||||||
use crate::error::UserError;
|
use crate::error::UserError;
|
||||||
@ -83,7 +84,7 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
field_id: FieldId,
|
field_id: FieldId,
|
||||||
facet_type: FacetType,
|
facet_type: FacetType,
|
||||||
candidates: &RoaringBitmap,
|
candidates: &RoaringBitmap,
|
||||||
distribution: &mut BTreeMap<String, u64>,
|
distribution: &mut IndexMap<String, u64>,
|
||||||
) -> heed::Result<()> {
|
) -> heed::Result<()> {
|
||||||
match facet_type {
|
match facet_type {
|
||||||
FacetType::Number => {
|
FacetType::Number => {
|
||||||
@ -153,7 +154,7 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
field_id: FieldId,
|
field_id: FieldId,
|
||||||
candidates: &RoaringBitmap,
|
candidates: &RoaringBitmap,
|
||||||
order_by: OrderBy,
|
order_by: OrderBy,
|
||||||
distribution: &mut BTreeMap<String, u64>,
|
distribution: &mut IndexMap<String, u64>,
|
||||||
) -> heed::Result<()> {
|
) -> heed::Result<()> {
|
||||||
let search_function = match order_by {
|
let search_function = match order_by {
|
||||||
OrderBy::Lexicographic => lexicographically_iterate_over_facet_distribution,
|
OrderBy::Lexicographic => lexicographically_iterate_over_facet_distribution,
|
||||||
@ -184,7 +185,7 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
field_id: FieldId,
|
field_id: FieldId,
|
||||||
candidates: &RoaringBitmap,
|
candidates: &RoaringBitmap,
|
||||||
order_by: OrderBy,
|
order_by: OrderBy,
|
||||||
distribution: &mut BTreeMap<String, u64>,
|
distribution: &mut IndexMap<String, u64>,
|
||||||
) -> heed::Result<()> {
|
) -> heed::Result<()> {
|
||||||
let search_function = match order_by {
|
let search_function = match order_by {
|
||||||
OrderBy::Lexicographic => lexicographically_iterate_over_facet_distribution,
|
OrderBy::Lexicographic => lexicographically_iterate_over_facet_distribution,
|
||||||
@ -219,10 +220,10 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn facet_values(&self, field_id: FieldId) -> heed::Result<BTreeMap<String, u64>> {
|
fn facet_values(&self, field_id: FieldId) -> heed::Result<IndexMap<String, u64>> {
|
||||||
use FacetType::{Number, String};
|
use FacetType::{Number, String};
|
||||||
|
|
||||||
let mut distribution = BTreeMap::new();
|
let mut distribution = IndexMap::new();
|
||||||
match (self.order_by, &self.candidates) {
|
match (self.order_by, &self.candidates) {
|
||||||
(OrderBy::Lexicographic, Some(cnd)) if cnd.len() <= CANDIDATES_THRESHOLD => {
|
(OrderBy::Lexicographic, Some(cnd)) if cnd.len() <= CANDIDATES_THRESHOLD => {
|
||||||
// Classic search, candidates were specified, we must return facet values only related
|
// Classic search, candidates were specified, we must return facet values only related
|
||||||
@ -318,7 +319,7 @@ impl<'a> FacetDistribution<'a> {
|
|||||||
Ok(distribution)
|
Ok(distribution)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(&self) -> Result<BTreeMap<String, BTreeMap<String, u64>>> {
|
pub fn execute(&self) -> Result<BTreeMap<String, IndexMap<String, u64>>> {
|
||||||
let fields_ids_map = self.index.fields_ids_map(self.rtxn)?;
|
let fields_ids_map = self.index.fields_ids_map(self.rtxn)?;
|
||||||
let filterable_fields = self.index.filterable_fields(self.rtxn)?;
|
let filterable_fields = self.index.filterable_fields(self.rtxn)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user