Example usage for org.apache.lucene.facet.taxonomy FastTaxonomyFacetCounts FastTaxonomyFacetCounts

List of usage examples for org.apache.lucene.facet.taxonomy FastTaxonomyFacetCounts FastTaxonomyFacetCounts

Introduction

In this page you can find the example usage for org.apache.lucene.facet.taxonomy FastTaxonomyFacetCounts FastTaxonomyFacetCounts.

Prototype

public FastTaxonomyFacetCounts(String indexFieldName, IndexReader reader, TaxonomyReader taxoReader,
        FacetsConfig config) throws IOException 

Source Link

Document

Create FastTaxonomyFacetCounts , using the specified indexFieldName for ordinals, and counting all non-deleted documents in the index.

Usage

From source file:com.czw.search.lucene.example.facet.MultiCategoryListsFacetsExample.java

License:Apache License

/** User runs a query and counts facets. */
private List<FacetResult> search() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    FacetsCollector fc = new FacetsCollector();

    // MatchAllDocsQuery is for "browsing" (counts facets
    // for all non-deleted docs in the index); normally
    // you'd use a "normal" query:
    FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);

    // Retrieve results
    List<FacetResult> results = new ArrayList<>();

    // Count both "Publish Date" and "Author" dimensions
    Facets author = new FastTaxonomyFacetCounts("author", taxoReader, config, fc);
    results.add(author.getTopChildren(10, "Author"));

    Facets pubDate = new FastTaxonomyFacetCounts("pubdate", taxoReader, config, fc);
    results.add(pubDate.getTopChildren(10, "Publish Date"));

    indexReader.close();/*from ww  w .  ja  va  2s. c o  m*/
    taxoReader.close();

    return results;
}

From source file:com.semantic.swing.facet.FacetJTabbedPane.java

public void handleResult(QueryResultEvent event) throws IOException {
    PlugInManager pluginManager = ApplicationContext.instance().get(ApplicationContext.PLUGIN_MANAGER);

    IndexManager lucene = ApplicationContext.instance().get(IndexManager.LUCENE_MANAGER);
    IndexSearcher searcher = event.getCurrentSearcher();

    /* facet collector */
    FacetsCollector fc = new FacetsCollector();
    FacetsConfig cfg = event.getFacetConfig();
    FacetsCollector.search(searcher, event.getQuery(), 5, fc);

    for (IFieldProperty def : pluginManager.allInstances(IFieldProperty.class)) {
        if (def.hasFacet()) {
            try {
                String indexFieldName = cfg.getDimConfig(def.getName()).indexFieldName;

                Facets facets = new FastTaxonomyFacetCounts(indexFieldName, lucene.getTaxoReader(), cfg, fc);

                faceted.get(def.getName()).setResult(facets.getTopChildren(5, def.getName()),
                        Collections.emptyList());
            } catch (Exception e) {
                e.printStackTrace();/*from   w  w w  .  j  a  v  a 2  s.com*/
            }
        }
    }
}

From source file:com.semantic.swing.facet.FacetOverview.java

@Override
public void handleEvent(QueryResultEvent event) {
    try {//  w  w w . j a v a 2  s.c  o  m
        FacetsConfig cfg = event.getFacetConfig();

        Map<IFieldProperty, List<String>> labels = getSelectedLabels();
        //            DrillDownQuery dq = createDq(cfg);
        // clean
        removeAll();

        PlugInManager pluginManager = ApplicationContext.instance().get(ApplicationContext.PLUGIN_MANAGER);

        IndexManager lucene = ApplicationContext.instance().get(IndexManager.LUCENE_MANAGER);
        IndexSearcher searcher = event.getCurrentSearcher();

        // facet collector
        FacetsCollector fc = new FacetsCollector();
        FacetsCollector.search(searcher, event.getQuery(), 5, fc);

        //            DrillSideways.DrillSidewaysResult r = null;
        //            if (dq != null) {
        //                DrillSideways ds = new DrillSideways(searcher, cfg, lucene.getTaxoReader());
        //                r = ds.search(dq, 5);
        //            }
        for (IFieldProperty def : pluginManager.allInstances(IFieldProperty.class)) {
            if (def.hasFacet()) {
                try {
                    String indexFieldName = cfg.getDimConfig(def.getName()).indexFieldName;

                    //                        if (r != null) {
                    //                            System.out.println(r.facets.getTopChildren(5, indexFieldName));
                    //                        }
                    Facets facets = new FastTaxonomyFacetCounts(indexFieldName, lucene.getTaxoReader(), cfg,
                            fc);

                    FacetResult result = facets.getTopChildren(5, def.getName());
                    if (result != null && result.childCount > 0) {
                        FacetFieldPanel facetView = new FacetFieldPanel(def);
                        facetView.setResult(result,
                                labels.containsKey(def) ? labels.get(def) : Collections.emptyList());
                        add(facetView);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        repaint();
    } catch (IOException ex) {
        Logger.getLogger(FacetOverview.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.zghw.lucene.demo.MultiCategoryListsFacetsExample.java

License:Apache License

/** User runs a query and counts facets. */
private List<FacetResult> search() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    FacetsCollector fc = new FacetsCollector();

    // MatchAllDocsQuery is for "browsing" (counts facets
    // for all non-deleted docs in the index); normally
    // you'd use a "normal" query:
    FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, fc);

    // Retrieve results
    List<FacetResult> results = new ArrayList<FacetResult>();

    // Count both "Publish Date" and "Author" dimensions
    Facets author = new FastTaxonomyFacetCounts("author", taxoReader, config, fc);
    results.add(author.getTopChildren(10, "Author"));

    Facets pubDate = new FastTaxonomyFacetCounts("pubdate", taxoReader, config, fc);
    results.add(pubDate.getTopChildren(10, "Publish Date"));

    indexReader.close();/*from  ww w. j  av a2  s  . c o m*/
    taxoReader.close();

    return results;
}