use of org.neo4j.index.lucene.QueryContext in project graphdb by neo4j-attic.
the class TestLuceneIndex method testTopHits.
@Test
public void testTopHits() {
Index<Relationship> index = relationshipIndex("topdocs", LuceneIndexImplementation.FULLTEXT_CONFIG);
EntityCreator<Relationship> creator = RELATIONSHIP_CREATOR;
String key = "text";
Relationship rel1 = creator.create(key, "one two three four five six seven eight nine ten");
Relationship rel2 = creator.create(key, "one two three four five six seven eight other things");
Relationship rel3 = creator.create(key, "one two three four five six some thing else");
Relationship rel4 = creator.create(key, "one two three four five what ever");
Relationship rel5 = creator.create(key, "one two three four all that is good and bad");
Relationship rel6 = creator.create(key, "one two three hill or something");
Relationship rel7 = creator.create(key, "one two other time than this");
index.add(rel2, key, rel2.getProperty(key));
index.add(rel1, key, rel1.getProperty(key));
index.add(rel3, key, rel3.getProperty(key));
index.add(rel7, key, rel7.getProperty(key));
index.add(rel5, key, rel5.getProperty(key));
index.add(rel4, key, rel4.getProperty(key));
index.add(rel6, key, rel6.getProperty(key));
String query = "one two three four five six seven";
for (int i = 0; i < 2; i++) {
assertContainsInOrder(index.query(key, new QueryContext(query).top(3).sort(Sort.RELEVANCE)), rel1, rel2, rel3);
restartTx();
}
}
use of org.neo4j.index.lucene.QueryContext in project graphdb by neo4j-attic.
the class TestLuceneIndex method testSortingWithTopHitsInPartCommittedPartLocal.
@Test
public void testSortingWithTopHitsInPartCommittedPartLocal() {
Index<Node> index = nodeIndex("mix", LuceneIndexImplementation.FULLTEXT_CONFIG);
Node first = graphDb.createNode();
Node second = graphDb.createNode();
Node third = graphDb.createNode();
Node fourth = graphDb.createNode();
String key = "key";
index.add(third, key, "ccc");
index.add(second, key, "bbb");
restartTx();
index.add(fourth, key, "ddd");
index.add(first, key, "aaa");
assertContainsInOrder(index.query(key, new QueryContext("*").sort(key)), first, second, third, fourth);
assertContainsInOrder(index.query(key, new QueryContext("*").sort(key).top(2)), first, second);
}
use of org.neo4j.index.lucene.QueryContext in project graphdb by neo4j-attic.
the class TestLuceneIndex method shouldNotGetLatestTxModificationsWhenChoosingSpeedQueries.
@Test
public void shouldNotGetLatestTxModificationsWhenChoosingSpeedQueries() {
Index<Node> index = nodeIndex("indexFooBar", LuceneIndexImplementation.EXACT_CONFIG);
Node node = graphDb.createNode();
index.add(node, "key", "value");
QueryContext queryContext = new QueryContext("value").tradeCorrectnessForSpeed();
assertThat(index.query("key", queryContext), isEmpty());
assertThat(index.query("key", "value"), contains(node));
}
use of org.neo4j.index.lucene.QueryContext in project neo4j by neo4j.
the class TestLuceneIndex method queryAndSortNodesByNumericProperty.
private void queryAndSortNodesByNumericProperty(Index<Node> index, String numericProperty, Function<Integer, ? extends Number> expectedValueProvider) {
try (Transaction transaction = graphDb.beginTx()) {
QueryContext queryContext = new QueryContext(numericProperty + ":**");
queryContext.sort(new Sort(new SortedNumericSortField(numericProperty, SortField.Type.INT, false)));
IndexHits<Node> nodes = index.query(queryContext);
int nodeIndex = 0;
for (Node node : nodes) {
assertEquals("Nodes should be sorted by numeric property", expectedValueProvider.apply(nodeIndex++), node.getProperty(numericProperty));
}
transaction.success();
}
}
use of org.neo4j.index.lucene.QueryContext in project neo4j by neo4j.
the class TestLuceneIndex method queryAndSortNodesByStringProperty.
private void queryAndSortNodesByStringProperty(Index<Node> index, String stringProperty, Function<Integer, String> expectedValueProvider) {
try (Transaction transaction = graphDb.beginTx()) {
QueryContext queryContext = new QueryContext(stringProperty + ":**");
queryContext.sort(new Sort(new SortedSetSortField(stringProperty, true)));
IndexHits<Node> nodes = index.query(queryContext);
int nodeIndex = 0;
for (Node node : nodes) {
assertEquals("Nodes should be sorted by string property", expectedValueProvider.apply(nodeIndex++), node.getProperty(stringProperty));
}
transaction.success();
}
}
Aggregations