Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Add stop words #135

Merged
merged 3 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion meilisearch-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ main_error = "0.1.0"
meilisearch-error = { path = "../meilisearch-error" }
meilisearch-tokenizer = { git = "https://github.com/meilisearch/Tokenizer.git", branch = "main" }
memmap = "0.7.0"
milli = { git = "https://github.com/meilisearch/milli.git", rev = "b7b23cd" }
milli = { git = "https://github.com/meilisearch/milli.git", rev = "2bcdd8844c4ec9f6f8a34617ea0e4321fa633c0c" }
mime = "0.3.16"
once_cell = "1.5.2"
parking_lot = "0.11.1"
Expand Down
15 changes: 14 additions & 1 deletion meilisearch-http/src/index/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod search;
mod updates;

use std::collections::HashSet;
use std::collections::{BTreeSet, HashSet};
use std::ops::Deref;
use std::sync::Arc;

Expand Down Expand Up @@ -51,11 +51,24 @@ impl Index {
.map(|c| c.to_string())
.collect();

let stop_words = self
.stop_words(&txn)?
.map(|stop_words| -> anyhow::Result<BTreeSet<_>> {
Ok(stop_words
.stream()
.into_strs()?
.into_iter()
.collect())
})
.transpose()?
.unwrap_or_else(BTreeSet::new);

Ok(Settings {
displayed_attributes: Some(Some(displayed_attributes)),
searchable_attributes: Some(Some(searchable_attributes)),
attributes_for_faceting: Some(Some(faceted_attributes)),
ranking_rules: Some(Some(criteria)),
stop_words: Some(Some(stop_words)),
})
}

Expand Down
19 changes: 16 additions & 3 deletions meilisearch-http/src/index/updates.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{BTreeSet, HashMap};
use std::io;
use std::num::NonZeroUsize;

Expand Down Expand Up @@ -44,8 +44,12 @@ pub struct Settings {
)]
pub ranking_rules: Option<Option<Vec<String>>>,

// TODO we are missing the stopWords, synonyms and distinctAttribute for the GET settings
// request
#[serde(
default,
deserialize_with = "deserialize_some",
skip_serializing_if = "Option::is_none"
)]
pub stop_words: Option<Option<BTreeSet<String>>>,
}

impl Settings {
Expand All @@ -55,6 +59,7 @@ impl Settings {
searchable_attributes: Some(None),
attributes_for_faceting: Some(None),
ranking_rules: Some(None),
stop_words: Some(None),
}
}
}
Expand Down Expand Up @@ -170,6 +175,14 @@ impl Index {
}
}

// We transpose the settings JSON struct into a real setting update.
if let Some(ref stop_words) = settings.stop_words {
match stop_words {
Some(stop_words) => builder.set_stop_words(stop_words.clone()),
_ => builder.reset_stop_words(),
}
}

let result = builder
.execute(|indexing_step, update_id| info!("update {}: {:?}", update_id, indexing_step));

Expand Down
43 changes: 0 additions & 43 deletions meilisearch-http/src/routes/settings/attributes_for_faceting.rs

This file was deleted.

25 changes: 0 additions & 25 deletions meilisearch-http/src/routes/settings/displayed_attributes.rs

This file was deleted.

9 changes: 8 additions & 1 deletion meilisearch-http/src/routes/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ make_setting_route!(
searchable_attributes
);

make_setting_route!(
"/indexes/{index_uid}/settings/stop-words",
std::collections::BTreeSet<String>,
stop_words
);

//make_setting_route!(
//"/indexes/{index_uid}/settings/distinct-attribute",
//String,
Expand Down Expand Up @@ -122,7 +128,8 @@ macro_rules! create_services {
create_services!(
attributes_for_faceting,
displayed_attributes,
searchable_attributes
searchable_attributes,
stop_words
);

#[post("/indexes/{index_uid}/settings", wrap = "Authentication::Private")]
Expand Down
34 changes: 0 additions & 34 deletions meilisearch-http/src/routes/settings/searchable_attributes.rs

This file was deleted.

33 changes: 0 additions & 33 deletions meilisearch-http/src/routes/settings/stop_words.rs

This file was deleted.

13 changes: 8 additions & 5 deletions meilisearch-http/tests/settings/get_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ async fn get_settings() {
let (response, code) = index.settings().await;
assert_eq!(code, 200);
let settings = response.as_object().unwrap();
assert_eq!(settings.keys().len(), 4);
assert_eq!(settings.keys().len(), 5);
assert_eq!(settings["displayedAttributes"], json!(["*"]));
assert_eq!(settings["searchableAttributes"], json!(["*"]));
assert_eq!(settings["attributesForFaceting"], json!({}));
assert_eq!(
settings["rankingRules"],
json!([
"typo",
"words",
"typo",
"proximity",
"attribute",
"wordsPosition",
"exactness"
])
);
assert_eq!(settings["stopWords"], json!([]));
}

#[actix_rt::test]
Expand Down Expand Up @@ -78,13 +78,14 @@ async fn reset_all_settings() {
let server = Server::new().await;
let index = server.index("test");
index
.update_settings(json!({"displayedAttributes": ["foo"], "searchableAttributes": ["bar"]}))
.update_settings(json!({"displayedAttributes": ["foo"], "searchableAttributes": ["bar"], "stopWords": ["the"] }))
.await;
index.wait_update_id(0).await;
let (response, code) = index.settings().await;
assert_eq!(code, 200);
assert_eq!(response["displayedAttributes"], json!(["foo"]));
assert_eq!(response["searchableAttributes"], json!(["bar"]));
assert_eq!(response["stopWords"], json!(["the"]));

index.delete_settings().await;
index.wait_update_id(1).await;
Expand All @@ -93,6 +94,7 @@ async fn reset_all_settings() {
assert_eq!(code, 200);
assert_eq!(response["displayedAttributes"], json!(["*"]));
assert_eq!(response["searchableAttributes"], json!(["*"]));
assert_eq!(response["stopWords"], json!([]));
}

#[actix_rt::test]
Expand Down Expand Up @@ -166,5 +168,6 @@ macro_rules! test_setting_routes {
test_setting_routes!(
attributes_for_faceting,
displayed_attributes,
searchable_attributes
searchable_attributes,
stop_words
);