Skip to content

Commit

Permalink
Merge branch 'fix/tantivy' of github.com:Pometry/Raphtory into fix/ta…
Browse files Browse the repository at this point in the history
…ntivy
  • Loading branch information
shivamka1 committed Dec 11, 2024
2 parents 0523021 + 8379c77 commit 5beb7e9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion raphtory-graphql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
45 changes: 37 additions & 8 deletions raphtory/src/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, IndexRecordOption, JsonObjectOptions, Schema, SchemaBuilder, TextFieldIndexing,
TextOptions, Value, FAST, INDEXED, STORED, TEXT,
Expand Down Expand Up @@ -426,15 +427,44 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph<G> {
Some(e_view)
}

fn node_parser(&self) -> Result<QueryParser, GraphError> {
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<QueryParser, GraphError> {
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,
limit: usize,
offset: usize,
) -> Result<Vec<NodeView<G>>, 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);
Expand All @@ -455,7 +485,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph<G> {

pub fn search_node_count(&self, q: &str) -> Result<usize, 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 count = searcher.search(&query, &tantivy::collector::Count)?;
Expand All @@ -465,7 +495,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph<G> {

pub fn search_edge_count(&self, q: &str) -> Result<usize, 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 count = searcher.search(&query, &tantivy::collector::Count)?;
Expand All @@ -480,8 +510,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph<G> {
offset: usize,
) -> Result<Vec<EdgeView<G, G>>, 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);
Expand Down Expand Up @@ -509,7 +538,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph<G> {
levenshtein_distance: u8,
) -> Result<Vec<NodeView<G>>, 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()
Expand Down Expand Up @@ -543,7 +572,7 @@ impl<'graph, G: GraphViewOps<'graph>> IndexedGraph<G> {
levenshtein_distance: u8,
) -> Result<Vec<EdgeView<G>>, 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()
Expand Down

0 comments on commit 5beb7e9

Please sign in to comment.