From 9204778b97c0faf299ce6460d455e99fdf185435 Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Thu, 17 Aug 2023 12:29:07 -0700 Subject: [PATCH] store: Populate all search indexes for an entity In commit ad1c6ead, we inadvertently made it so that only one search index per entitiy would be populated. With thse changes, all of them will be populated again. Fixes https://github.com/graphprotocol/graph-node/issues/4794 --- store/postgres/src/relational_queries.rs | 10 +++---- store/test-store/tests/postgres/relational.rs | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/store/postgres/src/relational_queries.rs b/store/postgres/src/relational_queries.rs index 1de09778538..c1a45cd5ecd 100644 --- a/store/postgres/src/relational_queries.rs +++ b/store/postgres/src/relational_queries.rs @@ -1812,10 +1812,9 @@ 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() @@ -1823,12 +1822,11 @@ impl<'a> FulltextValues<'a> { .cloned() .collect::>(); 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) diff --git a/store/test-store/tests/postgres/relational.rs b/store/test-store/tests/postgres/relational.rs index 146bed87192..830a7113b58 100644 --- a/store/test-store/tests/postgres/relational.rs +++ b/store/test-store/tests/postgres/relational.rs @@ -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 @@ -1198,6 +1211,20 @@ fn check_find() { "Jono & achangedemail@email.com".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 & achangedemail@email.com".into(), + )), + ); // list contains fn drinks_query(v: Vec<&str>) -> EntityQuery {