private TopDocsName facetsWithSearch(String query) throws IOException, ParseException {

    FacetsCollector fc = new FacetsCollector();

    ComplexPhraseQueryParser queryParser =
        new ComplexPhraseQueryParser("content", new StandardAnalyzer());

    Query luceneQuery = queryParser.parse(query);

    TopDocs docs = FacetsCollector.search(indexSearcher, luceneQuery, 400, fc);

    List<TopDocName> topDocNames = new ArrayList<TopDocName>();

    for (ScoreDoc scoreDoc : docs.scoreDocs) {
      String filename = indexSearcher.doc(scoreDoc.doc).get("filename");
      float score = scoreDoc.score;
      TopDocName docname = new TopDocName(score, filename.substring(0, filename.length()));
      topDocNames.add(docname);
    }

    List<FacetResult> facetResults = new ArrayList<FacetResult>();

    // Count both "Publish Date" and "Author" dimensions
    Facets facets = new FastTaxonomyFacetCounts(taxoReader, taxoConfig, fc);
    facetResults.add(facets.getTopChildren(11, "person"));
    facetResults.add(facets.getTopChildren(20, "objects"));
    TopDocsName results = new TopDocsName(1.0f, topDocNames, facetResults);

    return results;
  }
  /** User runs a query and aggregates facets by summing their association values. */
  private List<FacetResult> sumAssociations() 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);

    Facets tags = new TaxonomyFacetSumIntAssociations("$tags", taxoReader, config, fc);
    Facets genre = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);

    // Retrieve results
    List<FacetResult> results = new ArrayList<>();
    results.add(tags.getTopChildren(10, "tags"));
    results.add(genre.getTopChildren(10, "genre"));

    indexReader.close();
    taxoReader.close();

    return results;
  }
  private List<FacetResult> facetsOnly() throws IOException {

    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:
    TopDocs docs = FacetsCollector.search(indexSearcher, new MatchAllDocsQuery(), 10, fc);

    //        indexSearcher.search(new MatchAllDocsQuery(), null /*Filter */, fc);

    // Retrieve results
    List<FacetResult> results = new ArrayList<FacetResult>();
    System.out.println("results size: " + results.size());

    // Count both "Publish Date" and "Author" dimensions
    Facets facets = new FastTaxonomyFacetCounts(taxoReader, taxoConfig, fc);

    results.add(facets.getTopChildren(20, "objects"));
    //        results.add(facets.getTopChildren(10, "Publish Date"));

    List<FacetResult> result = facets.getAllDims(10);

    //        indexReader.close();
    //        taxoReader.close();

    return result;
  }
Пример #4
0
 private Facets runFacetedSearch(Request req, User user) throws IOException, ParseException {
   FacetsCollector fc = new FacetsCollector();
   Query query = searchService.getQuery(req);
   FacetsCollector.search(getSearcher(req, user), query, req.pageSize, fc);
   // TODO: support faceting for sortedsetdocvalue based fields (e.g. from)
   Facets facets = new LongRangeFacetCounts(req.trendField.name(), fc, buildRanges(req));
   return facets;
 }
Пример #5
0
 /**
  * Create {@code TaxonomyFacetCounts}, which also counts all facet labels. Use this for a
  * non-default {@link OrdinalsReader}; otherwise use {@link FastTaxonomyFacetCounts}.
  */
 public TaxonomyFacetCounts(
     OrdinalsReader ordinalsReader,
     TaxonomyReader taxoReader,
     FacetsConfig config,
     FacetsCollector fc)
     throws IOException {
   super(ordinalsReader.getIndexFieldName(), taxoReader, config);
   this.ordinalsReader = ordinalsReader;
   count(fc.getMatchingDocs());
 }
  /** User drills down on 'tags/solr'. */
  private FacetResult drillDown() throws IOException {
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    IndexSearcher searcher = new IndexSearcher(indexReader);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(config);

    // Now user drills down on Publish Date/2010:
    q.add("tags", "solr");
    FacetsCollector fc = new FacetsCollector();
    FacetsCollector.search(searcher, q, 10, fc);

    // Retrieve results
    Facets facets = new TaxonomyFacetSumFloatAssociations("$genre", taxoReader, config, fc);
    FacetResult result = facets.getTopChildren(10, "genre");

    indexReader.close();
    taxoReader.close();

    return result;
  }
  private TopDocsName drillDown(Map<String, String> facets_value) throws IOException {

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):

    DrillDownQuery q = new DrillDownQuery(taxoConfig);

    for (Map.Entry<String, String> entry : facets_value.entrySet()) {
      q.add(entry.getKey(), entry.getValue());
    }

    FacetsCollector fc = new FacetsCollector();
    TopDocs docs = FacetsCollector.search(indexSearcher, q, 100000, fc);

    List<TopDocName> topDocNames = new ArrayList<TopDocName>();

    for (ScoreDoc scoreDoc : docs.scoreDocs) {
      String filename = indexSearcher.doc(scoreDoc.doc).get("filename");
      String videoID = indexSearcher.doc(scoreDoc.doc).get("videoID");
      String frameNumber = indexSearcher.doc(scoreDoc.doc).get("frameNumber");
      float score = scoreDoc.score;
      TopDocName docname = new TopDocName(score, filename, videoID, frameNumber);
      topDocNames.add(docname);
    }

    List<FacetResult> facetResults = new ArrayList<FacetResult>();

    // Count both "Publish Date" and "Author" dimensions
    Facets facets = new FastTaxonomyFacetCounts(taxoReader, taxoConfig, fc);
    facetResults.add(facets.getTopChildren(11, "person"));
    facetResults.add(facets.getTopChildren(20, "objects"));
    facetResults.add(facets.getTopChildren(200, "background"));
    TopDocsName results = new TopDocsName(1.0f, topDocNames, facetResults);

    return results;
  }