use of org.neo4j.index.lucene.ValueContext in project neo4j by neo4j.
the class TestLuceneIndex method updateIndex.
@Test
public void updateIndex() throws Exception {
String TEXT = "text";
String NUMERIC = "numeric";
String TEXT_1 = "text_1";
Index<Node> index = nodeIndex(LuceneIndexImplementation.EXACT_CONFIG);
Node n = graphDb.createNode();
index.add(n, NUMERIC, new ValueContext(5).indexNumeric());
index.add(n, TEXT, "text");
index.add(n, TEXT_1, "text");
commitTx();
beginTx();
assertNotNull(index.query(QueryContext.numericRange(NUMERIC, 5, 5, true, true)).getSingle());
assertNotNull(index.get(TEXT_1, "text").getSingle());
index.remove(n, TEXT, "text");
index.add(n, TEXT, "text 1");
commitTx();
beginTx();
assertNotNull(index.get(TEXT_1, "text").getSingle());
assertNotNull(index.query(QueryContext.numericRange(NUMERIC, 5, 5, true, true)).getSingle());
}
use of org.neo4j.index.lucene.ValueContext in project neo4j by neo4j.
the class TestLuceneIndex method queryIndexWithSortByNumeric.
@Test
public void queryIndexWithSortByNumeric() throws Exception {
Index<Node> index = nodeIndex();
commitTx();
String numericProperty = "NODE_ID";
try (Transaction transaction = graphDb.beginTx()) {
for (int i = 0; i < 15; i++) {
Node node = graphDb.createNode();
node.setProperty(numericProperty, i);
index.add(node, numericProperty, new ValueContext(i).indexNumeric());
}
transaction.success();
}
queryAndSortNodesByNumericProperty(index, numericProperty);
}
use of org.neo4j.index.lucene.ValueContext in project neo4j by neo4j.
the class TestLuceneIndex method testRemoveNumericValues.
@Test
public void testRemoveNumericValues() {
Index<Node> index = nodeIndex(LuceneIndexImplementation.EXACT_CONFIG);
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
String key = "key";
index.add(node1, key, new ValueContext(15).indexNumeric());
index.add(node2, key, new ValueContext(5).indexNumeric());
index.remove(node1, key, new ValueContext(15).indexNumeric());
assertThat(index.query(NumericRangeQuery.newIntRange(key, 0, 20, false, false)), Contains.contains(node2));
index.remove(node2, key, new ValueContext(5).indexNumeric());
assertThat(index.query(NumericRangeQuery.newIntRange(key, 0, 20, false, false)), emptyIterable());
restartTx();
assertThat(index.query(NumericRangeQuery.newIntRange(key, 0, 20, false, false)), emptyIterable());
index.add(node1, key, new ValueContext(15).indexNumeric());
index.add(node2, key, new ValueContext(5).indexNumeric());
restartTx();
assertThat(index.query(NumericRangeQuery.newIntRange(key, 0, 20, false, false)), Contains.contains(node1, node2));
index.remove(node1, key, new ValueContext(15).indexNumeric());
assertThat(index.query(NumericRangeQuery.newIntRange(key, 0, 20, false, false)), Contains.contains(node2));
restartTx();
assertThat(index.query(NumericRangeQuery.newIntRange(key, 0, 20, false, false)), Contains.contains(node2));
}
use of org.neo4j.index.lucene.ValueContext in project neo4j by neo4j.
the class TestLuceneIndex method queryIndexWithSortByNumericAfterOtherPropertyUpdate.
@Test
public void queryIndexWithSortByNumericAfterOtherPropertyUpdate() {
Index<Node> index = nodeIndex();
commitTx();
String yearProperty = "year";
String priceProperty = "price";
Label nodeLabel = Label.label("priceyNodes");
try (Transaction transaction = graphDb.beginTx()) {
for (int i = 0; i < 15; i++) {
Node node = graphDb.createNode(nodeLabel);
node.setProperty(yearProperty, i);
node.setProperty(priceProperty, i);
index.add(node, yearProperty, new ValueContext(i).indexNumeric());
index.add(node, priceProperty, new ValueContext(i).indexNumeric());
}
transaction.success();
}
doubleNumericPropertyValueForAllNodesWithLabel(index, priceProperty, nodeLabel);
queryAndSortNodesByNumericProperty(index, yearProperty);
queryAndSortNodesByNumericProperty(index, priceProperty, (value) -> value * 2);
}
use of org.neo4j.index.lucene.ValueContext in project neo4j by neo4j.
the class TestLuceneBatchInsert method testNumericValueArrays.
@Test
public void testNumericValueArrays() {
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(inserter);
BatchInserterIndex batchIndex = provider.nodeIndex("mine", EXACT_CONFIG);
long nodeId1 = inserter.createNode(null);
batchIndex.add(nodeId1, map("number", new ValueContext[] { numeric(45), numeric(98) }));
long nodeId2 = inserter.createNode(null);
batchIndex.add(nodeId2, map("number", new ValueContext[] { numeric(47), numeric(100) }));
batchIndex.flush();
IndexHits<Long> batchIndexResult1 = batchIndex.query("number", newIntRange("number", 47, 98, true, true));
assertThat(batchIndexResult1, contains(nodeId1, nodeId2));
assertThat(batchIndexResult1.size(), is(2));
IndexHits<Long> batchIndexResult2 = batchIndex.query("number", newIntRange("number", 44, 46, true, true));
assertThat(batchIndexResult2, contains(nodeId1));
assertThat(batchIndexResult2.size(), is(1));
IndexHits<Long> batchIndexResult3 = batchIndex.query("number", newIntRange("number", 99, 101, true, true));
assertThat(batchIndexResult3, contains(nodeId2));
assertThat(batchIndexResult3.size(), is(1));
IndexHits<Long> batchIndexResult4 = batchIndex.query("number", newIntRange("number", 47, 98, false, false));
assertThat(batchIndexResult4, Matchers.emptyIterable());
provider.shutdown();
switchToGraphDatabaseService();
try (Transaction transaction = db.beginTx()) {
Node node1 = db.getNodeById(nodeId1);
Node node2 = db.getNodeById(nodeId2);
Index<Node> index = db.index().forNodes("mine");
IndexHits<Node> indexResult1 = index.query("number", newIntRange("number", 47, 98, true, true));
assertThat(indexResult1, contains(node1, node2));
assertThat(indexResult1.size(), is(2));
IndexHits<Node> indexResult2 = index.query("number", newIntRange("number", 44, 46, true, true));
assertThat(indexResult2, contains(node1));
assertThat(indexResult2.size(), is(1));
IndexHits<Node> indexResult3 = index.query("number", newIntRange("number", 99, 101, true, true));
assertThat(indexResult3, contains(node2));
assertThat(indexResult3.size(), is(1));
IndexHits<Node> indexResult4 = index.query("number", newIntRange("number", 47, 98, false, false));
assertThat(indexResult4, Matchers.emptyIterable());
transaction.success();
}
}
Aggregations