graph_api_test/index/
vertex_full_text.rs

1#[cfg(feature = "vertex-full-text-index")]
2use crate::{PersonMut, assert_elements_eq, populate_graph};
3#[cfg(feature = "vertex-full-text-index")]
4use graph_api_lib::VertexReferenceMut;
5
6use crate::{Edge, Vertex};
7use graph_api_lib::Graph;
8
9/// Tests that a vertex can be added to the graph and that the indexed field
10/// search returns the added vertex.
11///
12/// This function creates a vertex, adds it to the graph, and then verifies
13/// that a search for the indexed field of the added vertex returns the
14/// expected result.
15#[cfg(feature = "vertex-full-text-index")]
16pub fn test_index<T>(graph: &mut T)
17where
18    T: Graph<Vertex = Vertex, Edge = Edge> + graph_api_lib::SupportsVertexFullTextIndex,
19{
20    let refs = populate_graph(graph);
21    let collected = graph
22        .walk()
23        .vertices(Vertex::person_by_biography("graph"))
24        .collect::<Vec<_>>();
25    assert_elements_eq!(graph, collected, vec![refs.bryn]);
26}
27#[cfg(not(feature = "vertex-full-text-index"))]
28pub fn test_index<T>(_graph: &mut T)
29where
30    T: Graph<Vertex = Vertex, Edge = Edge>,
31{
32}
33
34/// Tests that a vertex can be removed from the graph, and that the indexed field
35/// search no longer returns the removed vertex.
36///
37/// This function creates a vertex, adds it to the graph, and then removes it.
38/// It then verifies that a search for the indexed field of the removed vertex
39/// returns an empty result.
40#[cfg(all(feature = "vertex-full-text-index", feature = "element-removal"))]
41pub fn test_index_remove<T>(graph: &mut T)
42where
43    T: Graph<Vertex = Vertex, Edge = Edge>
44        + graph_api_lib::SupportsVertexFullTextIndex
45        + graph_api_lib::SupportsElementRemoval,
46{
47    let refs = populate_graph(graph);
48    graph.remove_vertex(refs.bryn);
49    assert_eq!(
50        graph
51            .walk()
52            .vertices(Vertex::person_by_biography("graph"))
53            .count(),
54        0
55    );
56}
57
58#[cfg(not(all(feature = "vertex-full-text-index", feature = "element-removal")))]
59pub fn test_index_remove<T>(_graph: &mut T)
60where
61    T: Graph<Vertex = Vertex, Edge = Edge>,
62{
63}
64
65/// Tests that a vertex's indexed field can be updated and that the graph's
66/// search functionality reflects this change.
67///
68/// This function creates a vertex, adds it to the graph, updates the indexed
69/// field of the vertex, and then performs searches to verify that:
70///
71/// - The old value of the indexed field is no longer present in the graph
72/// - The new value of the indexed field is correctly associated
73///   with the updated vertex
74#[cfg(feature = "vertex-full-text-index")]
75pub fn test_index_update<T>(graph: &mut T)
76where
77    T: Graph<Vertex = Vertex, Edge = Edge> + graph_api_lib::SupportsVertexFullTextIndex,
78{
79    let refs = populate_graph(graph);
80    graph
81        .vertex_mut(refs.bryn)
82        .expect("bryn must exist")
83        .project_mut::<PersonMut<_, _>>()
84        .expect("must be a person")
85        .set_biography("Developed a graphql proxy in Rust".to_string());
86    assert_eq!(
87        graph
88            .walk()
89            .vertices(Vertex::person_by_biography("graph"))
90            .count(),
91        0
92    );
93    assert_eq!(
94        graph
95            .walk()
96            .vertices(Vertex::person_by_biography("proxy"))
97            .count(),
98        1
99    );
100}
101
102#[cfg(not(feature = "vertex-full-text-index"))]
103pub fn test_index_update<T>(_graph: &mut T)
104where
105    T: Graph<Vertex = Vertex, Edge = Edge>,
106{
107}