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; }
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; }
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; }