Search in sources :

Example 61 with MatchAllDocsQuery

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);
    }
}
Also used : DataReader(edu.uci.ics.textdb.storage.DataReader) HashMap(java.util.HashMap) IndexReader(org.apache.lucene.index.IndexReader) Terms(org.apache.lucene.index.Terms) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) IOException(java.io.IOException) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermsEnum(org.apache.lucene.index.TermsEnum)

Example 62 with MatchAllDocsQuery

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;
}
Also used : ArrayList(java.util.ArrayList) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Example 63 with MatchAllDocsQuery

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);
}
Also used : ArrayList(java.util.ArrayList) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Test(org.junit.Test)

Example 64 with MatchAllDocsQuery

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);
    });
}
Also used : SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Document(org.apache.lucene.document.Document) FieldType(org.apache.lucene.document.FieldType) Test(org.junit.Test)

Example 65 with MatchAllDocsQuery

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);
}
Also used : Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Aggregations

MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)288 IndexSearcher (org.apache.lucene.search.IndexSearcher)169 Directory (org.apache.lucene.store.Directory)133 Document (org.apache.lucene.document.Document)122 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)122 IndexReader (org.apache.lucene.index.IndexReader)120 TopDocs (org.apache.lucene.search.TopDocs)91 Sort (org.apache.lucene.search.Sort)71 SortField (org.apache.lucene.search.SortField)64 Query (org.apache.lucene.search.Query)53 BooleanQuery (org.apache.lucene.search.BooleanQuery)50 TermQuery (org.apache.lucene.search.TermQuery)49 FacetsCollector (org.apache.lucene.facet.FacetsCollector)40 Facets (org.apache.lucene.facet.Facets)34 Term (org.apache.lucene.index.Term)33 ArrayList (java.util.ArrayList)32 DirectoryReader (org.apache.lucene.index.DirectoryReader)30 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)28 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)23 FacetResult (org.apache.lucene.facet.FacetResult)22