use of org.apache.lucene.search.TermQuery in project neo4j-mobile-android by neo4j-contrib.
the class FullTxData method injectOrphans.
private Query injectOrphans(Query query) {
if (query instanceof BooleanQuery) {
BooleanQuery source = (BooleanQuery) query;
BooleanQuery result = new BooleanQuery();
for (BooleanClause clause : source.clauses()) {
result.add(injectOrphans(clause.getQuery()), clause.getOccur());
}
return result;
} else {
BooleanQuery result = new BooleanQuery();
result.add(query, Occur.SHOULD);
result.add(new TermQuery(new Term(ORPHANS_KEY, extractTermField(query))), Occur.SHOULD);
return result;
}
}
use of org.apache.lucene.search.TermQuery in project neo4j by neo4j.
the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldCreateNewDocumentsForNewlyLabeledNodes.
@Test
public void shouldCreateNewDocumentsForNewlyLabeledNodes() throws Exception {
// given
WritableIndexPartition partition = mock(WritableIndexPartition.class);
WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
when(partition.acquireSearcher()).thenReturn(partitionSearcher);
IndexWriter indexWriter = mock(IndexWriter.class);
when(partition.getIndexWriter()).thenReturn(indexWriter);
IndexSearcher searcher = mock(IndexSearcher.class);
when(partitionSearcher.getIndexSearcher()).thenReturn(searcher);
when(searcher.search(new TermQuery(format.rangeTerm(0)), 1)).thenReturn(emptyTopDocs());
when(searcher.search(new TermQuery(format.rangeTerm(1)), 1)).thenReturn(null);
LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
// when
writer.write(labelChanges(0, labels(), labels(6, 7)));
writer.write(labelChanges(1, labels(), labels(6, 8)));
writer.write(labelChanges(1 << format.bitmapFormat().shift, labels(), labels(7)));
writer.close();
// then
verify(partition, times(2)).acquireSearcher();
verify(partitionSearcher, times(2)).getIndexSearcher();
verify(partition, times(2)).getIndexWriter();
verify(partitionSearcher, times(2)).close();
verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document(format.rangeField(0), format.labelField(6, 0x3), format.labelField(7, 0x1), format.labelField(8, 0x2), format.labelSearchField(8))));
verify(indexWriter).updateDocument(eq(format.rangeTerm(1)), match(document(format.rangeField(1), format.labelField(7, 0x1), format.labelSearchField(7))));
verify(index).maybeRefreshBlocking();
verifyNoMoreInteractions(partition);
}
use of org.apache.lucene.search.TermQuery in project neo4j by neo4j.
the class PartitionedLuceneLabelScanWriter method readLabelBitMapsInRange.
private Map<Long, /*range*/
Bitmap> readLabelBitMapsInRange(IndexSearcher searcher, long range) throws IOException {
Map<Long, Bitmap> /*label*/
fields = new HashMap<>();
Term documentTerm = format.rangeTerm(range);
TermQuery query = new TermQuery(documentTerm);
FirstHitCollector hitCollector = new FirstHitCollector();
searcher.search(query, hitCollector);
if (hitCollector.hasMatched()) {
Document document = searcher.doc(hitCollector.getMatchedDoc());
for (IndexableField field : document.getFields()) {
if (!format.isRangeOrLabelField(field)) {
Long label = Long.valueOf(field.name());
fields.put(label, format.readBitmap(field));
}
}
}
return fields;
}
use of org.apache.lucene.search.TermQuery in project neo4j by neo4j.
the class LuceneDocumentStructure method newRangeSeekByStringQuery.
public static Query newRangeSeekByStringQuery(String lower, boolean includeLower, String upper, boolean includeUpper) {
boolean includeLowerBoundary = StringUtils.EMPTY.equals(lower) || includeLower;
boolean includeUpperBoundary = StringUtils.EMPTY.equals(upper) || includeUpper;
TermRangeQuery termRangeQuery = TermRangeQuery.newStringRange(ValueEncoding.String.key(0), lower, upper, includeLowerBoundary, includeUpperBoundary);
if ((includeLowerBoundary != includeLower) || (includeUpperBoundary != includeUpper)) {
BooleanQuery.Builder builder = new BooleanQuery.Builder();
builder.setDisableCoord(true);
if (includeLowerBoundary != includeLower) {
builder.add(new TermQuery(new Term(ValueEncoding.String.key(0), lower)), BooleanClause.Occur.MUST_NOT);
}
if (includeUpperBoundary != includeUpper) {
builder.add(new TermQuery(new Term(ValueEncoding.String.key(0), upper)), BooleanClause.Occur.MUST_NOT);
}
builder.add(termRangeQuery, BooleanClause.Occur.FILTER);
return new ConstantScoreQuery(builder.build());
}
return termRangeQuery;
}
use of org.apache.lucene.search.TermQuery in project neo4j by neo4j.
the class SimpleIndexReader method countIndexedNodes.
@Override
public long countIndexedNodes(long nodeId, Object... propertyValues) {
Query nodeIdQuery = new TermQuery(LuceneDocumentStructure.newTermForChangeOrRemove(nodeId));
Query valueQuery = LuceneDocumentStructure.newSeekQuery(propertyValues);
BooleanQuery.Builder nodeIdAndValueQuery = new BooleanQuery.Builder().setDisableCoord(true);
nodeIdAndValueQuery.add(nodeIdQuery, BooleanClause.Occur.MUST);
nodeIdAndValueQuery.add(valueQuery, BooleanClause.Occur.MUST);
try {
TotalHitCountCollector collector = new TotalHitCountCollector();
getIndexSearcher().search(nodeIdAndValueQuery.build(), collector);
// A <label,propertyKeyId,nodeId> tuple should only match at most a single propertyValue
return collector.getTotalHits();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations