Example usage for org.apache.lucene.facet DrillDownQuery term

List of usage examples for org.apache.lucene.facet DrillDownQuery term

Introduction

In this page you can find the example usage for org.apache.lucene.facet DrillDownQuery term.

Prototype

public static Term term(String field, String dim, String... path) 

Source Link

Document

Creates a drill-down term.

Usage

From source file:com.shaie.facet.NotDrillDownExample.java

License:Apache License

public static void main(String[] args) throws Exception {
    createIndex();//from   ww  w  . j  av  a2  s .com

    try (DirectoryReader indexReader = DirectoryReader.open(indexDir);
            TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);) {
        final IndexSearcher searcher = new IndexSearcher(indexReader);

        // Find the index field which holds the 'Author' facets
        final String indexedField = config.getDimConfig(AUTHOR_FACET).indexFieldName;
        final Query q = new BooleanQuery.Builder()
                // Here you would usually use a different query
                .add(new MatchAllDocsQuery(), Occur.MUST)
                // Exclude results with Author/Lisa
                .add(new TermQuery(DrillDownQuery.term(indexedField, AUTHOR_FACET, "Lisa")), Occur.MUST_NOT)
                .build();

        final TopDocs topDocs = searcher.search(q, 10);
        assert topDocs.scoreDocs.length == 1 : "should have found 1 document with Author/Bob";
        final Document doc = searcher.doc(topDocs.scoreDocs[0].doc);
        System.out.println(doc);
    }
}

From source file:org.meresco.lucene.Lucene.java

License:Open Source License

public Query createDrilldownQuery(Query luceneQuery, List<String[]> drilldownQueries) throws Exception {
    BooleanQuery q = new BooleanQuery(true);
    if (luceneQuery != null)
        q.add(luceneQuery, Occur.MUST);//from   www .  ja va 2s .c  o m
    for (int i = 0; i < drilldownQueries.size(); i += 2) {
        String field = drilldownQueries.get(i)[0];
        String indexFieldName = data.getFacetsConfig().getDimConfig(field).indexFieldName;
        q.add(new TermQuery(DrillDownQuery.term(indexFieldName, field, drilldownQueries.get(i + 1))),
                Occur.MUST);
    }
    return q;
}

From source file:org.meresco.lucene.QueryConverter.java

License:Open Source License

public Term createDrilldownTerm(String field, String... path) {
    String indexFieldName = facetsConfig.getDimConfig(field).indexFieldName;
    return DrillDownQuery.term(indexFieldName, field, path);
}

From source file:org.meresco.lucene.QueryConverterTest.java

License:Open Source License

@Test
public void testDrilldownQuery() {
    JsonObject json = Json.createObjectBuilder()
            .add("query", Json.createObjectBuilder().add("type", "TermQuery").add("term",
                    Json.createObjectBuilder().add("field", "dd-field")
                            .add("path", Json.createArrayBuilder().add("value")).add("type", "DrillDown")))
            .build();//w w  w . j  a  v a2s  . co m
    QueryData q = new QueryData(new StringReader(json.toString()), queryConverter);
    TermQuery query = new TermQuery(DrillDownQuery.term("$facets", "dd-field", "value"));
    assertEquals(query, q.query);
}