Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store: Populate all search indexes for an entity #4808

Merged
merged 1 commit into from
Aug 22, 2023
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
10 changes: 4 additions & 6 deletions store/postgres/src/relational_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1812,23 +1812,21 @@ struct FulltextValues<'a>(HashMap<&'a Word, Vec<(&'a str, Value)>>);

impl<'a> FulltextValues<'a> {
fn new(table: &'a Table, rows: &'a WriteChunk<'a>) -> Self {
let mut map = HashMap::new();
let mut map: HashMap<&Word, Vec<(&str, Value)>> = HashMap::new();
for column in table.columns.iter().filter(|column| column.is_fulltext()) {
for row in rows {
let mut fulltext = Vec::new();
if let Some(fields) = column.fulltext_fields.as_ref() {
let fulltext_field_values = fields
.iter()
.filter_map(|field| row.entity.get(field))
.cloned()
.collect::<Vec<Value>>();
if !fulltext_field_values.is_empty() {
fulltext.push((column.field.as_str(), Value::List(fulltext_field_values)));
map.entry(row.id)
.or_default()
.push((column.field.as_str(), Value::List(fulltext_field_values)));
}
}
if !fulltext.is_empty() {
map.insert(row.id, fulltext);
}
}
}
Self(map)
Expand Down
27 changes: 27 additions & 0 deletions store/test-store/tests/postgres/relational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ const THINGS_GQL: &str = r#"
]
}
]
) @fulltext(
name: "userSearch2"
language: en
algorithm: rank
include: [
{
entity: "User",
fields: [
{ name: "name"},
{ name: "email"},
]
}
]
) @fulltext(
name: "nullableStringsSearch"
language: en
Expand Down Expand Up @@ -1198,6 +1211,20 @@ fn check_find() {
"Jono & [email protected]".into(),
)),
);
// Test with a second fulltext search; we had a bug that caused only
// one search index to be populated (see issue #4794)
let checker = checker
.check(
vec!["3"],
user_query().filter(EntityFilter::Equal("userSearch2".into(), "Shaq:*".into())),
)
.check(
vec!["1"],
user_query().filter(EntityFilter::Equal(
"userSearch2".into(),
"Jono & [email protected]".into(),
)),
);

// list contains
fn drinks_query(v: Vec<&str>) -> EntityQuery {
Expand Down