use of org.neo4j.graphdb.index.IndexHits in project graphdb by neo4j-attic.
the class TestPerformanceAndSanity method makeSureFilesAreClosedProperly.
@Test
public void makeSureFilesAreClosedProperly() throws Exception {
commitTx();
final Index<Node> index = nodeIndex("open-files", LuceneIndexImplementation.EXACT_CONFIG);
final long time = System.currentTimeMillis();
final CountDownLatch latch = new CountDownLatch(30);
for (int t = 0; t < latch.getCount(); t++) {
new Thread() {
public void run() {
for (int i = 0; System.currentTimeMillis() - time < 100 * 1000; i++) {
if (i % 10 == 0) {
if (i % 100 == 0) {
int size = 0;
int type = (int) (System.currentTimeMillis() % 3);
if (type == 0) {
IndexHits<Node> itr = index.get("key", "value5");
try {
itr.getSingle();
} catch (NoSuchElementException e) {
}
size = 99;
} else if (type == 1) {
IndexHits<Node> itr = index.get("key", "value5");
for (; itr.hasNext() && size < 5; size++) {
itr.next();
}
itr.close();
} else {
IndexHits<Node> itr = index.get("key", "crap value");
// Iterate over the hits sometimes (it's always gonna be 0 sized)
if (System.currentTimeMillis() % 10 > 5) {
IteratorUtil.count((Iterator<Node>) itr);
}
}
System.out.println("C iterated " + size + " only");
} else {
int size = IteratorUtil.count((Iterator<Node>) index.get("key", "value5"));
System.out.println("hit size:" + size);
}
} else {
Transaction tx = graphDb.beginTx();
try {
for (int ii = 0; ii < 20; ii++) {
Node node = graphDb.createNode();
index.add(node, "key", "value" + ii);
}
tx.success();
} finally {
tx.finish();
}
}
}
latch.countDown();
}
}.start();
}
latch.await();
}
use of org.neo4j.graphdb.index.IndexHits in project neo4j-mobile-android by neo4j-contrib.
the class LuceneIndex method search.
private IndexHits<Document> search(IndexSearcherRef searcherRef, Query query, QueryContext additionalParametersOrNull, IndexSearcher additionsSearcher, Collection<Long> removed) {
try {
if (additionsSearcher != null && !removed.isEmpty()) {
letThroughAdditions(additionsSearcher, query, removed);
}
IndexSearcher searcher = additionsSearcher == null ? searcherRef.getSearcher() : new IndexSearcher(new MultiReader(searcherRef.getSearcher().getIndexReader(), additionsSearcher.getIndexReader()));
IndexHits<Document> result = null;
if (additionalParametersOrNull != null && additionalParametersOrNull.getTop() > 0) {
result = new TopDocsIterator(query, additionalParametersOrNull, searcher);
} else {
Sort sorting = additionalParametersOrNull != null ? additionalParametersOrNull.getSorting() : null;
boolean forceScore = additionalParametersOrNull == null || !additionalParametersOrNull.getTradeCorrectnessForSpeed();
Hits hits = new Hits(searcher, query, null, sorting, forceScore);
result = new HitsIterator(hits);
}
return result;
} catch (IOException e) {
throw new RuntimeException("Unable to query " + this + " with " + query, e);
}
}
use of org.neo4j.graphdb.index.IndexHits in project blueprints by tinkerpop.
the class Neo4jIndex method count.
/**
* {@inheritDoc}
* <p/>
* The underlying Neo4j graph does not natively support this method within a transaction.
* If the graph is not currently in a transaction, then the operation runs efficiently.
* If the graph is in a transaction, then, for every element, a try/catch is used to determine if its in the current transaction.
*/
public long count(final String key, final Object value) {
if (!this.graph.checkElementsInTransaction()) {
final IndexHits hits = this.rawIndex.get(key, value);
final long count = hits.size();
hits.close();
return count;
} else {
final CloseableIterable<T> hits = this.get(key, value);
long count = 0;
for (final T t : hits) {
count++;
}
hits.close();
return count;
}
}
Aggregations