mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 20:07:09 +02:00
adapt meilisearch-http to the new schemaless option
This commit is contained in:
parent
21d122a870
commit
4f0ead625b
13 changed files with 143 additions and 359 deletions
|
@ -1,6 +1,14 @@
|
|||
use std::sync::Mutex;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
static RANKING_RULE_REGEX: Lazy<Mutex<regex::Regex>> = Lazy::new(|| {
|
||||
let regex = regex::Regex::new(r"(asc|dsc)\(([a-zA-Z0-9-_]*)\)").unwrap();
|
||||
Mutex::new(regex)
|
||||
});
|
||||
|
||||
|
||||
#[derive(Default, Clone, Serialize, Deserialize)]
|
||||
pub struct Settings {
|
||||
|
@ -17,8 +25,36 @@ pub struct Settings {
|
|||
impl Into<SettingsUpdate> for Settings {
|
||||
fn into(self) -> SettingsUpdate {
|
||||
let settings = self.clone();
|
||||
|
||||
let ranking_rules = match settings.ranking_rules {
|
||||
Some(rules) => {
|
||||
let mut final_rules = Vec::new();
|
||||
for rule in rules {
|
||||
let parsed_rule = match rule.as_str() {
|
||||
"_typo" => RankingRule::Typo,
|
||||
"_words" => RankingRule::Words,
|
||||
"_proximity" => RankingRule::Proximity,
|
||||
"_attribute" => RankingRule::Attribute,
|
||||
"_words_position" => RankingRule::WordsPosition,
|
||||
"_exact" => RankingRule::Exact,
|
||||
_ => {
|
||||
let captures = RANKING_RULE_REGEX.lock().unwrap().captures(&rule).unwrap();
|
||||
match captures[0].as_ref() {
|
||||
"asc" => RankingRule::Asc(captures[1].to_string()),
|
||||
"dsc" => RankingRule::Dsc(captures[1].to_string()),
|
||||
_ => continue
|
||||
}
|
||||
}
|
||||
};
|
||||
final_rules.push(parsed_rule);
|
||||
}
|
||||
Some(final_rules)
|
||||
}
|
||||
None => None
|
||||
};
|
||||
|
||||
SettingsUpdate {
|
||||
ranking_rules: settings.ranking_rules.into(),
|
||||
ranking_rules: ranking_rules.into(),
|
||||
ranking_distinct: settings.ranking_distinct.into(),
|
||||
attribute_identifier: settings.attribute_identifier.into(),
|
||||
attributes_searchable: settings.attributes_searchable.into(),
|
||||
|
@ -57,9 +93,21 @@ impl<T> UpdateState<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum RankingRule {
|
||||
Typo,
|
||||
Words,
|
||||
Proximity,
|
||||
Attribute,
|
||||
WordsPosition,
|
||||
Exact,
|
||||
Asc(String),
|
||||
Dsc(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SettingsUpdate {
|
||||
pub ranking_rules: UpdateState<Vec<String>>,
|
||||
pub ranking_rules: UpdateState<Vec<RankingRule>>,
|
||||
pub ranking_distinct: UpdateState<String>,
|
||||
pub attribute_identifier: UpdateState<String>,
|
||||
pub attributes_searchable: UpdateState<Vec<String>>,
|
||||
|
|
|
@ -8,6 +8,7 @@ use meilisearch_schema::Schema;
|
|||
|
||||
use crate::database::MainT;
|
||||
use crate::RankedMap;
|
||||
use crate::settings::RankingRule;
|
||||
|
||||
const CREATED_AT_KEY: &str = "created-at";
|
||||
const RANKING_RULES_KEY: &str = "ranking-rules-key";
|
||||
|
@ -188,12 +189,12 @@ impl Main {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn ranking_rules<'txn>(&self, reader: &'txn heed::RoTxn<MainT>) -> ZResult<Option<Vec<String>>> {
|
||||
self.main.get::<_, Str, SerdeBincode<Vec<String>>>(reader, RANKING_RULES_KEY)
|
||||
pub fn ranking_rules<'txn>(&self, reader: &'txn heed::RoTxn<MainT>) -> ZResult<Option<Vec<RankingRule>>> {
|
||||
self.main.get::<_, Str, SerdeBincode<Vec<RankingRule>>>(reader, RANKING_RULES_KEY)
|
||||
}
|
||||
|
||||
pub fn put_ranking_rules(self, writer: &mut heed::RwTxn<MainT>, value: Vec<String>) -> ZResult<()> {
|
||||
self.main.put::<_, Str, SerdeBincode<Vec<String>>>(writer, RANKING_RULES_KEY, &value)
|
||||
pub fn put_ranking_rules(self, writer: &mut heed::RwTxn<MainT>, value: Vec<RankingRule>) -> ZResult<()> {
|
||||
self.main.put::<_, Str, SerdeBincode<Vec<RankingRule>>>(writer, RANKING_RULES_KEY, &value)
|
||||
}
|
||||
|
||||
pub fn delete_ranking_rules(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<bool> {
|
||||
|
|
|
@ -43,22 +43,6 @@ use crate::{query_builder::QueryBuilder, update, DocIndex, DocumentId, Error, MR
|
|||
type BEU64 = zerocopy::U64<byteorder::BigEndian>;
|
||||
type BEU16 = zerocopy::U16<byteorder::BigEndian>;
|
||||
|
||||
// #[derive(Debug, Copy, Clone, AsBytes, FromBytes)]
|
||||
// #[repr(C)]
|
||||
// pub struct DocumentAttrKey {
|
||||
// docid: BEU64,
|
||||
// indexed_pos: BEU16,
|
||||
// }
|
||||
|
||||
// impl DocumentAttrKey {
|
||||
// fn new(docid: DocumentId, indexed_pos: IndexedPos) -> DocumentAttrKey {
|
||||
// DocumentAttrKey {
|
||||
// docid: BEU64::new(docid.0),
|
||||
// indexed_pos: BEU16::new(indexed_pos.0),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug, Copy, Clone, AsBytes, FromBytes)]
|
||||
#[repr(C)]
|
||||
pub struct DocumentFieldIndexedKey {
|
||||
|
@ -271,7 +255,6 @@ impl Index {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn customs_update(&self, writer: &mut heed::RwTxn<UpdateT>, customs: Vec<u8>) -> ZResult<u64> {
|
||||
let _ = self.updates_notifier.send(UpdateEvent::NewUpdate);
|
||||
update::push_customs_update(writer, self.updates, self.updates_results, customs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue