Search in sources :

Example 1 with LuceneQueryVisitor

use of org.apache.cxf.jaxrs.ext.search.lucene.LuceneQueryVisitor in project cxf by apache.

the class TikaLuceneContentExtractorTest method getHits.

private ScoreDoc[] getHits(final String expression, final Map<String, Class<?>> fieldTypes) throws IOException {
    IndexReader reader = DirectoryReader.open(directory);
    IndexSearcher searcher = new IndexSearcher(reader);
    try {
        LuceneQueryVisitor<SearchBean> visitor = new LuceneQueryVisitor<SearchBean>("ct", "contents");
        visitor.setPrimitiveFieldTypeMap(fieldTypes);
        visitor.visit(parser.parse(expression));
        ScoreDoc[] hits = searcher.search(visitor.getQuery(), null, 1000).scoreDocs;
        assertNotNull(hits);
        return hits;
    } finally {
        reader.close();
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) IndexReader(org.apache.lucene.index.IndexReader) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) LuceneQueryVisitor(org.apache.cxf.jaxrs.ext.search.lucene.LuceneQueryVisitor) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Aggregations

SearchBean (org.apache.cxf.jaxrs.ext.search.SearchBean)1 LuceneQueryVisitor (org.apache.cxf.jaxrs.ext.search.lucene.LuceneQueryVisitor)1 IndexReader (org.apache.lucene.index.IndexReader)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1