From 8379c77e5b22540843bab3e7ce6be34c1949b813 Mon Sep 17 00:00:00 2001 From: Lucas Jeub Date: Wed, 11 Dec 2024 09:50:12 +0100 Subject: [PATCH] set properties as default field so old queries continue to work (this gives a nice fallback behaviour where it will search the explicitly defined field if there is a conflict) --- raphtory-graphql/src/lib.rs | 2 +- raphtory/src/search/mod.rs | 45 ++++++++++++++++++++++++++++++------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/raphtory-graphql/src/lib.rs b/raphtory-graphql/src/lib.rs index ad44e8129..628c6f039 100644 --- a/raphtory-graphql/src/lib.rs +++ b/raphtory-graphql/src/lib.rs @@ -76,7 +76,7 @@ mod graphql_test { let query = r#" { graph(path: "lotr") { - searchNodes(query: "temporal_properties.kind:wizard", limit: 10, offset: 0) { + searchNodes(query: "kind:wizard", limit: 10, offset: 0) { name } } diff --git a/raphtory/src/search/mod.rs b/raphtory/src/search/mod.rs index 5b48ce951..9d0dad2b8 100644 --- a/raphtory/src/search/mod.rs +++ b/raphtory/src/search/mod.rs @@ -43,6 +43,7 @@ use serde_json::json; use std::{collections::HashMap, iter, ops::Deref, sync::Arc}; use tantivy::{ collector::TopDocs, + query::QueryParser, schema::{ Field, JsonObjectOptions, Schema, SchemaBuilder, TextFieldIndexing, Value, FAST, INDEXED, STORED, TEXT, @@ -408,6 +409,36 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph { Some(e_view) } + fn node_parser(&self) -> Result { + let temporal_properties = self + .node_index + .schema() + .get_field(fields::TEMPORAL_PROPERTIES)?; + let const_properties = self + .node_index + .schema() + .get_field(fields::CONSTANT_PROPERTIES)?; + Ok(QueryParser::for_index( + &self.node_index, + vec![temporal_properties, const_properties], + )) + } + + fn edge_parser(&self) -> Result { + let temporal_properties = self + .edge_index + .schema() + .get_field(fields::TEMPORAL_PROPERTIES)?; + let const_properties = self + .edge_index + .schema() + .get_field(fields::CONSTANT_PROPERTIES)?; + Ok(QueryParser::for_index( + &self.edge_index, + vec![temporal_properties, const_properties], + )) + } + pub fn search_nodes( &self, q: &str, @@ -415,8 +446,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph { offset: usize, ) -> Result>, GraphError> { let searcher = self.node_reader.searcher(); - let query_parser = tantivy::query::QueryParser::for_index(&self.node_index, vec![]); - + let query_parser = self.node_parser()?; let query = query_parser.parse_query(q)?; let ranking = TopDocs::with_limit(limit).and_offset(offset); @@ -437,7 +467,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph { pub fn search_node_count(&self, q: &str) -> Result { let searcher = self.node_reader.searcher(); - let query_parser = tantivy::query::QueryParser::for_index(&self.node_index, vec![]); + let query_parser = self.node_parser()?; let query = query_parser.parse_query(q)?; let count = searcher.search(&query, &tantivy::collector::Count)?; @@ -447,7 +477,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph { pub fn search_edge_count(&self, q: &str) -> Result { let searcher = self.edge_reader.searcher(); - let query_parser = tantivy::query::QueryParser::for_index(&self.edge_index, vec![]); + let query_parser = self.edge_parser()?; let query = query_parser.parse_query(q)?; let count = searcher.search(&query, &tantivy::collector::Count)?; @@ -462,8 +492,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph { offset: usize, ) -> Result>, GraphError> { let searcher = self.edge_reader.searcher(); - let query_parser = tantivy::query::QueryParser::for_index(&self.edge_index, vec![]); - + let query_parser = self.edge_parser()?; let query = query_parser.parse_query(q)?; let ranking = TopDocs::with_limit(limit).and_offset(offset); @@ -491,7 +520,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph { levenshtein_distance: u8, ) -> Result>, GraphError> { let searcher = self.node_reader.searcher(); - let mut query_parser = tantivy::query::QueryParser::for_index(&self.node_index, vec![]); + let mut query_parser = self.node_parser()?; self.node_index .schema() @@ -525,7 +554,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph { levenshtein_distance: u8, ) -> Result>, GraphError> { let searcher = self.edge_reader.searcher(); - let mut query_parser = tantivy::query::QueryParser::for_index(&self.edge_index, vec![]); + let mut query_parser = self.edge_parser()?; self.edge_index .schema() .fields()