use of org.neo4j.index.lucene.QueryContext in project graphdb by neo4j-attic.
the class TestLuceneIndex method testSortByRelevance.
@Test
public void testSortByRelevance() {
Index<Node> index = nodeIndex("relevance", LuceneIndexImplementation.EXACT_CONFIG);
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
Node node3 = graphDb.createNode();
index.add(node1, "name", "something");
index.add(node2, "name", "something");
index.add(node2, "foo", "yes");
index.add(node3, "name", "something");
index.add(node3, "foo", "yes");
index.add(node3, "bar", "yes");
restartTx();
IndexHits<Node> hits = index.query(new QueryContext("+name:something foo:yes bar:yes").sort(Sort.RELEVANCE));
assertEquals(node3, hits.next());
assertEquals(node2, hits.next());
assertEquals(node1, hits.next());
assertFalse(hits.hasNext());
index.delete();
node1.delete();
node2.delete();
node3.delete();
}
use of org.neo4j.index.lucene.QueryContext in project graphdb by neo4j-attic.
the class TestLuceneIndex method testScoring.
@Test
public void testScoring() {
Index<Node> index = nodeIndex("score-index", LuceneIndexImplementation.FULLTEXT_CONFIG);
Node node1 = graphDb.createNode();
Node node2 = graphDb.createNode();
String key = "text";
// Where the heck did I get this sentence from?
index.add(node1, key, "a time where no one was really awake");
index.add(node2, key, "once upon a time there was");
restartTx();
IndexHits<Node> hits = index.query(key, new QueryContext("once upon a time was").sort(Sort.RELEVANCE));
Node hit1 = hits.next();
float score1 = hits.currentScore();
Node hit2 = hits.next();
float score2 = hits.currentScore();
assertEquals(node2, hit1);
assertEquals(node1, hit2);
assertTrue(score1 > score2);
}
Aggregations