Skip to content

Commit

Permalink
Merge master into update
Browse files Browse the repository at this point in the history
  • Loading branch information
ljeub-pometry committed Dec 12, 2024
2 parents 1583a53 + b56e18a commit 2a8148b
Show file tree
Hide file tree
Showing 4 changed files with 681 additions and 531 deletions.
27 changes: 15 additions & 12 deletions python/tests/test_index.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from raphtory import Graph

# Range queries are not supported for properties in tantivy (as of 0.22) because they are implemented as json.
# See https://github.com/quickwit-oss/tantivy/issues/1709

def test_search_in_python():
g = Graph()
Expand Down Expand Up @@ -53,10 +55,11 @@ def test_search_in_python():
assert len(index.search_nodes("name: IN [ben, hamza]")) == 2

# Property tests
assert len(index.search_nodes("value:<120 OR value_f:>30")) == 3
assert len(index.search_nodes("value:[0 TO 60]")) == 2
assert len(index.search_nodes("value:[0 TO 60}")) == 1 # } == exclusive
assert len(index.search_nodes("value:>59 AND value_str:abc123")) == 1
# assert len(index.search_nodes("value:<120 OR value_f:>30")) == 3
assert len(index.search_nodes("value:199")) == 1
# assert len(index.search_nodes("value:[0 TO 60]")) == 2
# assert len(index.search_nodes("value:[0 TO 60}")) == 1 # } == exclusive
# assert len(index.search_nodes("value:>59 AND value_str:abc123")) == 1

# edge tests
assert len(index.search_edges("from:ben")) == 2
Expand All @@ -65,10 +68,10 @@ def test_search_in_python():
assert len(index.search_edges("to: IN [ben, hamza]")) == 2

# edge prop tests
assert len(index.search_edges("value:<120 OR value_f:>30")) == 3
assert len(index.search_edges("value:[0 TO 60]")) == 2
assert len(index.search_edges("value:[0 TO 60}")) == 1 # } == exclusive
assert len(index.search_edges("value:>59 AND value_str:abc123")) == 1
# assert len(index.search_edges("value:<120 OR value_f:>30")) == 3
# assert len(index.search_edges("value:[0 TO 60]")) == 2
# assert len(index.search_edges("value:[0 TO 60}")) == 1 # } == exclusive
# assert len(index.search_edges("value:>59 AND value_str:abc123")) == 1

# Multiple history points test
g = Graph()
Expand All @@ -85,13 +88,13 @@ def test_search_in_python():
index = g.index()

# The semantics here are that the expressions independently need to evaluate at ANY point in the lifetime of the node - hence hamza is returned even though at no point does he have both these values at the same time
assert len(index.search_nodes("value:<70 AND value_f:<19.2")) == 1
# assert len(index.search_nodes("value:<70 AND value_f:<19.2")) == 1

g.add_node(
4, "hamza", properties={"value": 100, "value_f": 11.3, "value_str": "dsc2312"}
)
# the graph isn't currently reindexed so this will not return hamza even though he now has a value which fits the bill
assert len(index.search_nodes("value:>99")) == 0
# assert len(index.search_nodes("value:>99")) == 0


def test_type_search():
Expand Down Expand Up @@ -151,10 +154,10 @@ def test_search_with_windows():
# Testing if windowing works - ben shouldn't be included and Hamza should only have max value of 70
assert len(w_index.search_nodes("name:ben")) == 0
assert len(w_index.search_nodes("value:70")) == 1
assert len(w_index.search_nodes("value:>80")) == 0
# assert len(w_index.search_nodes("value:>80")) == 0

assert len(w_index.search_edges("from:ben")) == 0
assert len(w_index.search_edges("from:haaroon AND value:>70")) == 0
# assert len(w_index.search_edges("from:haaroon AND value:>70")) == 0
assert len(w_index.search_edges("from:haaroon AND to:hamza")) == 1


Expand Down
47 changes: 47 additions & 0 deletions raphtory/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use chrono::{DateTime, NaiveDateTime, Utc};
use itertools::Itertools;
use raphtory_api::core::storage::arc_str::ArcStr;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::{
cmp::Ordering,
collections::HashMap,
Expand Down Expand Up @@ -757,6 +758,52 @@ impl<T: Into<Prop>> IntoProp for T {
}
}

impl From<Prop> for Value {
fn from(prop: Prop) -> Self {
match prop {
Prop::Str(value) => Value::String(value.to_string()),
Prop::U8(value) => Value::Number(value.into()),
Prop::U16(value) => Value::Number(value.into()),
Prop::I32(value) => Value::Number(value.into()),
Prop::I64(value) => Value::Number(value.into()),
Prop::U32(value) => Value::Number(value.into()),
Prop::U64(value) => Value::Number(value.into()),
Prop::F32(value) => serde_json::Number::from_f64(value as f64)
.map(Value::Number)
.unwrap_or(Value::Null),
Prop::F64(value) => serde_json::Number::from_f64(value)
.map(Value::Number)
.unwrap_or(Value::Null),
Prop::Bool(value) => Value::Bool(value),
Prop::List(values) => Value::Array(values.iter().cloned().map(Value::from).collect()),
Prop::Map(map) => {
let json_map: serde_json::Map<String, Value> = map
.iter()
.map(|(k, v)| (k.to_string(), Value::from(v.clone())))
.collect();
Value::Object(json_map)
}
Prop::NDTime(value) => Value::String(value.to_string()),
Prop::DTime(value) => Value::String(value.to_string()),
Prop::Document(doc) => json!({
"content": doc.content,
"life": Value::from(doc.life),
}),
_ => Value::Null,
}
}
}

impl From<Lifespan> for Value {
fn from(lifespan: Lifespan) -> Self {
match lifespan {
Lifespan::Interval { start, end } => json!({ "start": start, "end": end }),
Lifespan::Event { time } => json!({ "time": time }),
Lifespan::Inherited => Value::String("inherited".to_string()),
}
}
}

#[cfg(feature = "io")]
mod serde_value_into_prop {
use std::collections::HashMap;
Expand Down
10 changes: 5 additions & 5 deletions raphtory/src/search/into_indexed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<G: StaticGraphViewOps + IntoDynamic> DynamicIndexedGraph for WindowedGraph<
.into_dynamic(),
node_index: self.graph.node_index,
edge_index: self.graph.edge_index,
reader: self.graph.reader,
node_reader: self.graph.node_reader,
edge_reader: self.graph.edge_reader,
}
}
Expand All @@ -43,7 +43,7 @@ impl<G: StaticGraphViewOps + IntoDynamic> DynamicIndexedGraph for LayeredGraph<I
graph: l.into_dynamic(),
node_index: self.graph.node_index,
edge_index: self.graph.edge_index,
reader: self.graph.reader,
node_reader: self.graph.node_reader,
edge_reader: self.graph.edge_reader,
}
}
Expand All @@ -56,7 +56,7 @@ impl<G: StaticGraphViewOps + IntoDynamic> DynamicIndexedGraph for NodeSubgraph<I
graph: g.into_dynamic(),
node_index: self.graph.node_index,
edge_index: self.graph.edge_index,
reader: self.graph.reader,
node_reader: self.graph.node_reader,
edge_reader: self.graph.edge_reader,
}
}
Expand All @@ -71,7 +71,7 @@ impl<G: StaticGraphViewOps + IntoDynamic> DynamicIndexedGraph
graph: g.into_dynamic(),
node_index: self.graph.node_index,
edge_index: self.graph.edge_index,
reader: self.graph.reader,
node_reader: self.graph.node_reader,
edge_reader: self.graph.edge_reader,
}
}
Expand All @@ -83,7 +83,7 @@ impl<G: StaticGraphViewOps + IntoDynamic> DynamicIndexedGraph for IndexedGraph<G
graph: self.graph.into_dynamic(),
node_index: self.node_index,
edge_index: self.edge_index,
reader: self.reader,
node_reader: self.node_reader,
edge_reader: self.edge_reader,
}
}
Expand Down
Loading

0 comments on commit 2a8148b

Please sign in to comment.