示例#1
0
 public static Query createDrillDownQuery(String field, String[] paths) {
   DrillDownQuery query = new DrillDownQuery(config);
   for (int i = 0; i < paths.length; i++) {
     query.add(field, paths[i]);
   }
   return query;
 }
  /** 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;
  }
  /** User drills down on the specified range. */
  public TopDocs drillDown(DoubleRange range) throws IOException {

    // Passing no baseQuery means we drill down on all
    // documents ("browse only"):
    DrillDownQuery q = new DrillDownQuery(null);
    final ValueSource vs = getDistanceValueSource();
    q.add(
        "field",
        range.getQuery(getBoundingBoxQuery(ORIGIN_LATITUDE, ORIGIN_LONGITUDE, range.max), vs));
    DrillSideways ds =
        new DrillSideways(searcher, config, (TaxonomyReader) null) {
          @Override
          protected Facets buildFacetsResult(
              FacetsCollector drillDowns,
              FacetsCollector[] drillSideways,
              String[] drillSidewaysDims)
              throws IOException {
            assert drillSideways.length == 1;
            return new DoubleRangeFacetCounts(
                "field", vs, drillSideways[0], ONE_KM, TWO_KM, FIVE_KM, TEN_KM);
          }
        };
    return ds.search(q, 10).hits;
  }
  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;
  }