use of org.apache.lucene.search.MatchAllDocsQuery in project textdb by TextDB.
the class WordCountIndexSource method computeWordCount.
private void computeWordCount() throws TextDBException {
try {
HashMap<String, Integer> wordCountMap = new HashMap<>();
DataReader dataReader = RelationManager.getRelationManager().getTableDataReader(predicate.getTableName(), new MatchAllDocsQuery());
dataReader.open();
IndexReader luceneIndexReader = dataReader.getLuceneIndexReader();
for (int i = 0; i < luceneIndexReader.numDocs(); i++) {
Terms termVector = luceneIndexReader.getTermVector(i, predicate.getAttribute());
TermsEnum termsEnum = termVector.iterator();
while (termsEnum.next() != null) {
String key = termsEnum.term().utf8ToString();
wordCountMap.put(key, wordCountMap.get(key) == null ? ((int) termsEnum.totalTermFreq()) : wordCountMap.get(key) + ((int) termsEnum.totalTermFreq()));
}
}
luceneIndexReader.close();
dataReader.close();
sortedWordCountMap = wordCountMap.entrySet().stream().sorted((e1, e2) -> e2.getValue().compareTo(e1.getValue())).collect(Collectors.toList());
wordCountIterator = sortedWordCountMap.iterator();
} catch (IOException e) {
throw new DataFlowException(e);
}
}
use of org.apache.lucene.search.MatchAllDocsQuery in project textdb by TextDB.
the class RelationManager method getMetaData.
public List<TableMetadata> getMetaData() throws Exception {
DataReader dataReader = RelationManager.getRelationManager().getTableDataReader(CatalogConstants.TABLE_CATALOG, new MatchAllDocsQuery());
List<TableMetadata> result = new ArrayList<>();
Tuple t = null;
dataReader.open();
while ((t = dataReader.getNextTuple()) != null) {
String tableName = (String) t.getField(CatalogConstants.TABLE_NAME).getValue();
if (!tableName.equals(CatalogConstants.SCHEMA_CATALOG.toLowerCase()) && !tableName.equals(CatalogConstants.TABLE_CATALOG.toLowerCase())) {
result.add(new TableMetadata(tableName, getTableSchema(tableName)));
}
}
dataReader.close();
return result;
}
use of org.apache.lucene.search.MatchAllDocsQuery in project textdb by TextDB.
the class DataWriterReaderTest method testReadWriteData.
@Test
public void testReadWriteData() throws Exception {
DataReader dataReader = RelationManager.getRelationManager().getTableDataReader(PEOPLE_TABLE, new MatchAllDocsQuery());
Tuple nextTuple = null;
List<Tuple> returnedTuples = new ArrayList<Tuple>();
dataReader.open();
while ((nextTuple = dataReader.getNextTuple()) != null) {
returnedTuples.add(nextTuple);
}
dataReader.close();
boolean equals = containsAllResults(TestConstants.getSamplePeopleTuples(), returnedTuples);
Assert.assertTrue(equals);
}
use of org.apache.lucene.search.MatchAllDocsQuery in project lucene-solr by apache.
the class TestPointVectorStrategy method testFieldOptions.
@Test
public void testFieldOptions() throws IOException, ParseException {
// It's not stored; test it isn't.
this.strategy = PointVectorStrategy.newInstance(ctx, getClass().getSimpleName());
adoc("99", "POINT(-5.0 8.2)");
commit();
SearchResults results = executeQuery(new MatchAllDocsQuery(), 1);
Document document = results.results.get(0).document;
assertNull("not stored", document.getField(strategy.getFieldName() + PointVectorStrategy.SUFFIX_X));
assertNull("not stored", document.getField(strategy.getFieldName() + PointVectorStrategy.SUFFIX_Y));
deleteAll();
// Now we mark it stored. We also disable pointvalues...
FieldType fieldType = new FieldType(PointVectorStrategy.DEFAULT_FIELDTYPE);
fieldType.setStored(true);
//disable point values
fieldType.setDimensions(0, 0);
this.strategy = new PointVectorStrategy(ctx, getClass().getSimpleName(), fieldType);
adoc("99", "POINT(-5.0 8.2)");
commit();
results = executeQuery(new MatchAllDocsQuery(), 1);
document = results.results.get(0).document;
assertEquals("stored", -5.0, document.getField(strategy.getFieldName() + PointVectorStrategy.SUFFIX_X).numericValue());
assertEquals("stored", 8.2, document.getField(strategy.getFieldName() + PointVectorStrategy.SUFFIX_Y).numericValue());
// Test a query fails without point values
expectThrows(UnsupportedOperationException.class, () -> {
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(-10.0, 10.0, -5.0, 5.0));
this.strategy.makeQuery(args);
});
}
use of org.apache.lucene.search.MatchAllDocsQuery in project lucene-solr by apache.
the class TestDrillDownQuery method testNoDrillDown.
public void testNoDrillDown() throws Exception {
Query base = new MatchAllDocsQuery();
DrillDownQuery q = new DrillDownQuery(config, base);
Query rewrite = q.rewrite(reader).rewrite(reader);
assertEquals(base, rewrite);
}
Aggregations