/// <summary> /// Create a new <see cref="DrillSideways"/> instance, where some /// dimensions were indexed with <see cref="SortedSetDocValuesFacetField"/> /// and others were indexed with <see cref="FacetField"/>. /// </summary> public DrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader taxoReader, SortedSetDocValuesReaderState state) { this.m_searcher = searcher; this.m_config = config; this.m_taxoReader = taxoReader; this.m_state = state; }
public static void TestFlexLuceneRAM(string[] args) { StandardAnalyzer analyzer = new StandardAnalyzer(); FlexLucene.Store.Directory index = (FlexLucene.Store.Directory) new RAMDirectory(); config = new IndexWriterConfig((Analyzer)analyzer); cnf = new FacetsConfig(); cnf.SetIndexFieldName("title", "facet_title"); cnf.SetIndexFieldName("isbn", "facet_isbn"); LuceneTest.taxoDir = (FlexLucene.Store.Directory) new RAMDirectory(); LuceneTest.taxoWriter = (TaxonomyWriter) new FlexLucene.Facet.Taxonomy.Directory.DirectoryTaxonomyWriter(LuceneTest.taxoDir, IndexWriterConfigOpenMode.CREATE); IndexWriter w = new IndexWriter(index, LuceneTest.config); addDoc(w, "Lucene in Action", "9900001"); addDoc(w, "Lucene for Dummies", "9900002"); addDoc(w, "Lucene for Dummies 2", "9900003"); w.close(); String querystr = "isbn:99*"; Query q = new QueryParser("title", (Analyzer)analyzer).Parse(querystr); int hitsPerPage = 10; IndexReader reader = (IndexReader)DirectoryReader.Open(index); IndexSearcher searcher = new IndexSearcher(reader); TopScoreDocCollector collector = TopScoreDocCollector.Create(hitsPerPage); searcher.Search(q, (Collector)collector); ScoreDoc[] hits = collector.TopDocs().ScoreDocs; Console.WriteLine("Found " + hits.Length + " hits."); for (int i = 0; i < hits.Length; ++i) { int docId = hits [i].Doc; Document d = searcher.Doc(docId); Console.WriteLine(i + 1 + ". " + d.Get("isbn") + "\t" + d.Get("title")); } SortedSetDocValuesReaderState state = (SortedSetDocValuesReaderState) new DefaultSortedSetDocValuesReaderState(reader, "facet_isbn"); FacetsCollector fc = new FacetsCollector(); FacetsCollector.Search(searcher, q, 10, (Collector)fc); Facets facets = (Facets) new SortedSetDocValuesFacetCounts(state, fc); FacetResult result = facets.GetTopChildren(10, "isbn", new String[0]); for (int j = 0; j < result.ChildCount; ++j) { LabelAndValue lv = result.LabelValues [j]; Console.WriteLine(String.Format("Label={0}, Value={1}", lv.Label, lv.Value)); } reader.close(); }
/// <summary> /// Create a new <see cref="DrillSideways"/> instance, assuming the categories were /// indexed with <see cref="SortedSetDocValuesFacetField"/>. /// </summary> public DrillSideways(IndexSearcher searcher, FacetsConfig config, SortedSetDocValuesReaderState state) : this(searcher, config, null, state) { }