public void TestNumberRangeWithInt() { // Field. string field = "number"; // Lucene index. using (IndexReader reader = IndexReader.Open(this._indexDir, true)) { // Bobo reader. using (BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader, this._facetHandlers)) { // Request. BrowseRequest browseRequest = new BrowseRequest(); browseRequest.Count = 10; browseRequest.Offset = 0; browseRequest.FetchStoredFields = true; // Selection. BrowseSelection sel = new BrowseSelection(field); browseRequest.AddSelection(sel); // Query. MatchAllDocsQuery query = new MatchAllDocsQuery(); // Output. FacetSpec spec = new FacetSpec(); spec.OrderBy = FacetSpec.FacetSortSpec.OrderValueAsc; spec.MaxCount = 10; browseRequest.SetFacetSpec(field, spec); // Browse. IBrowsable browser = new BoboBrowser(boboReader); using (BrowseResult result = browser.Browse(browseRequest)) { // Results. int totalHits = result.NumHits; BrowseHit[] hits = result.Hits; IDictionary <String, IFacetAccessible> facetMap = result.FacetMap; IFacetAccessible facets = facetMap[field]; List <BrowseFacet> facetVals = facets.GetFacets().ToList(); // Check. Assert.AreEqual(10, totalHits); Assert.AreEqual(5, facetVals.Count()); Assert.AreEqual("[0000000000 TO 0000001000](3)", facetVals[0].ToString()); Assert.AreEqual("[0000001000 TO 0000010000](3)", facetVals[1].ToString()); Assert.AreEqual("[0000010000 TO 0000100000](2)", facetVals[2].ToString()); Assert.AreEqual("[0000100000 TO 0001000000](3)", facetVals[3].ToString()); Assert.AreEqual("[0001000000 TO *](3)", facetVals[4].ToString()); } } } }
public void TestWithSingleCommit() { string text = "text"; Document doc1 = new Document(); doc1.Add(new TextField(text, "Foo1", Field.Store.YES)); m_indexWriter.AddDocument(doc1); Document doc2 = new Document(); doc2.Add(new TextField(text, "Foo2", Field.Store.YES)); m_indexWriter.AddDocument(doc2); Document doc3 = new Document(); doc3.Add(new TextField(text, "Foo3", Field.Store.YES)); m_indexWriter.AddDocument(doc3); m_indexWriter.Commit(); List <IFacetHandler> handlerList = new List <IFacetHandler>(); DirectoryReader reader = BoboMultiReader.Open(m_indexWriter, true); BoboMultiReader boboMultiReader = BoboMultiReader.GetInstance(reader, handlerList); BrowseRequest br = new BrowseRequest(); br.Count = (10); br.Offset = (0); QueryParser parser = new QueryParser(LuceneVersion.LUCENE_48, "text", new StandardAnalyzer(LuceneVersion.LUCENE_48)); Lucene.Net.Search.Query q = parser.Parse("Foo*"); br.Query = (q); BoboBrowser browser = new BoboBrowser(boboMultiReader); BrowseResult result = browser.Browse(br); int totalHits = result.NumHits; BrowseHit[] hits = result.Hits; Assert.AreEqual(3, totalHits, "should be 3 hits"); Assert.AreEqual(0, hits[0].DocId, "should be doc 0"); Assert.AreEqual(1, hits[1].DocId, "should be doc 1"); Assert.AreEqual(2, hits[2].DocId, "should be doc 2"); result.Dispose(); }
public void TestPriceRangeWithFloatAndSelection() { // Field. string field = "pricefloat"; // Lucene index. using (DirectoryReader reader = DirectoryReader.Open(this._indexDir)) { // Bobo reader. using (BoboMultiReader boboReader = BoboMultiReader.GetInstance(reader, this._facetHandlers)) { // Request. BrowseRequest browseRequest = new BrowseRequest(); browseRequest.Count = 10; browseRequest.Offset = 0; browseRequest.FetchStoredFields = true; // Selection. BrowseSelection sel = new BrowseSelection(field); sel.AddValue("[000000.000 TO 000999.220]"); browseRequest.AddSelection(sel); // Query. MatchAllDocsQuery query = new MatchAllDocsQuery(); // Output. FacetSpec spec = new FacetSpec(); spec.OrderBy = FacetSpec.FacetSortSpec.OrderValueAsc; spec.MaxCount = 10; browseRequest.SetFacetSpec(field, spec); // Browse. IBrowsable browser = new BoboBrowser(boboReader); using (BrowseResult result = browser.Browse(browseRequest)) { // Results. int totalHits = result.NumHits; BrowseHit[] hits = result.Hits; IDictionary <String, IFacetAccessible> facetMap = result.FacetMap; IFacetAccessible facets = facetMap[field]; List <BrowseFacet> facetVals = facets.GetFacets().ToList(); // Check. Assert.AreEqual(7, totalHits); Assert.AreEqual(1, facetVals.Count); Assert.AreEqual("[000000.000 TO 000999.220](7)", facetVals[0].ToString()); } } } }
public BoboResult(BrowseResult browseResult) { this.Choices = new Dictionary<string, Choice>(); this.Hits = new List<Hit>(); // populate the data from the browse result this.Time = browseResult.Time; this.NumHits = browseResult.NumHits; this.TotalDocs = browseResult.TotalDocs; foreach (var entry in browseResult.FacetMap) { string name = entry.Key; IEnumerable<BrowseFacet> facets = entry.Value.GetFacets(); var choiceObject = new Choice(); //var choiceList = new List<FacetResult>(); int totalCount = 0; foreach (var facet in facets) { var choice = new FacetResult(); choice.FacetValueHitCount = facet.FacetValueHitCount; choice.Value = facet.Value; choiceObject.ChoiceList.Add(choice); totalCount += facet.FacetValueHitCount; } choiceObject.TotalCount = totalCount; this.Choices.Add(name, choiceObject); } if (browseResult.Hits != null && browseResult.Hits.Count() > 0) { foreach (var hit in browseResult.Hits) { var ht = new Hit(); ht.FieldValues = hit.FieldValues; ht.DocId = hit.DocId; ht.Score = hit.Score; this.Hits.Add(ht); } } }
public void TestMultiValPath() { DirectoryReader reader = DirectoryReader.Open(directory); BoboMultiReader boboReader = BoboMultiReader.GetInstance(reader, facetHandlers); BoboBrowser browser = new BoboBrowser(boboReader); BrowseRequest req = new BrowseRequest(); BrowseSelection sel = new BrowseSelection(PathHandlerName); sel.AddValue("/a"); var propMap = new Dictionary <String, String>(); propMap.Put(PathFacetHandler.SEL_PROP_NAME_DEPTH, "0"); propMap.Put(PathFacetHandler.SEL_PROP_NAME_STRICT, "false"); sel.SetSelectionProperties(propMap); req.AddSelection(sel); FacetSpec fs = new FacetSpec(); fs.MinHitCount = (1); req.SetFacetSpec(PathHandlerName, fs); BrowseResult res = browser.Browse(req); Assert.AreEqual(res.NumHits, 1); IFacetAccessible fa = res.GetFacetAccessor(PathHandlerName); ICollection <BrowseFacet> facets = fa.GetFacets(); Console.WriteLine(facets); Assert.AreEqual(1, facets.Count); BrowseFacet facet = facets.Get(0); Assert.AreEqual(2, facet.FacetValueHitCount); }
public virtual BrowseResult Browse(BrowseRequest req) { if (_reader == null) return new BrowseResult(); BrowseResult result = new BrowseResult(); long start = System.Environment.TickCount; SortCollector collector = GetSortCollector(req.Sort, req.Query, req.Offset, req.Count, req.FetchStoredFields, req.TermVectorsToFetch, false, req.GroupBy, req.MaxPerGroup, req.CollectDocIdCache); IDictionary<string, IFacetAccessible> facetCollectors = new Dictionary<string, IFacetAccessible>(); Browse(req, collector, facetCollectors); BrowseHit[] hits = null; try { hits = collector.TopDocs; } catch (Exception e) { logger.Error(e.Message, e); hits = new BrowseHit[0]; } var q = req.Query; if (q == null) { q = new MatchAllDocsQuery(); } if (req.ShowExplanation) { foreach (BrowseHit hit in hits) { try { Explanation expl = Explain(q, hit.DocId); hit.Explanation = expl; } catch (Exception e) { logger.Error(e.Message, e); } } } result.Hits = hits; result.NumHits = collector.TotalHits; result.NumGroups = collector.TotalGroups; result.GroupAccessibles = collector.GroupAccessibles; result.SortCollector = collector; result.TotalDocs = _reader.NumDocs(); result.AddAll(facetCollectors); long end = System.Environment.TickCount; result.Time = (end - start); return result; }
public virtual BrowseResult Browse(BrowseRequest req) { if (_reader == null) { return(new BrowseResult()); } BrowseResult result = new BrowseResult(); long start = System.Environment.TickCount; SortCollector collector = GetSortCollector(req.Sort, req.Query, req.Offset, req.Count, req.FetchStoredFields, req.TermVectorsToFetch, false, req.GroupBy, req.MaxPerGroup, req.CollectDocIdCache); IDictionary <string, IFacetAccessible> facetCollectors = new Dictionary <string, IFacetAccessible>(); Browse(req, collector, facetCollectors); BrowseHit[] hits = null; try { hits = collector.TopDocs; } catch (Exception e) { logger.Error(e.Message, e); hits = new BrowseHit[0]; } var q = req.Query; if (q == null) { q = new MatchAllDocsQuery(); } if (req.ShowExplanation) { foreach (BrowseHit hit in hits) { try { Explanation expl = Explain(q, hit.DocId); hit.Explanation = expl; } catch (Exception e) { logger.Error(e.Message, e); } } } result.Hits = hits; result.NumHits = collector.TotalHits; result.NumGroups = collector.TotalGroups; result.GroupAccessibles = collector.GroupAccessibles; result.SortCollector = collector; result.TotalDocs = _reader.NumDocs(); result.AddAll(facetCollectors); long end = System.Environment.TickCount; result.Time = (end - start); return(result); }
/// <summary> /// Generates a merged BrowseResult from the supplied <see cref="T:BrowseRequest"/>. /// </summary> /// <param name="req"><see cref="T:BrowseRequest"/> for generating the facets.</param> /// <returns><see cref="T:BrowseResult"/> of the results corresponding to the <see cref="T:BrowseRequest"/>.</returns> public virtual BrowseResult Browse(BrowseRequest req) { BrowseResult result = new BrowseResult(); // index empty if (m_subBrowsers == null || m_subBrowsers.Length == 0) { return(result); } long start = System.Environment.TickCount; int offset = req.Offset; int count = req.Count; if (offset < 0 || count < 0) { throw new ArgumentOutOfRangeException("both offset and count must be > 0: " + offset + "/" + count); } SortCollector collector = GetSortCollector(req.Sort, req.Query, offset, count, req.FetchStoredFields, req.TermVectorsToFetch, req.GroupBy, req.MaxPerGroup, #pragma warning disable 612, 618 req.CollectDocIdCache); #pragma warning restore 612, 618 var facetCollectors = new Dictionary <string, IFacetAccessible>(); Browse(req, collector, facetCollectors, 0); if (req.MapReduceWrapper != null) { result.MapReduceResult = req.MapReduceWrapper.Result; } BrowseHit[] hits = null; try { hits = collector.TopDocs; } catch (Exception e) { logger.ErrorException(e.Message, e); result.AddError(e.Message); hits = new BrowseHit[0]; } var q = req.Query; if (req.ShowExplanation) { foreach (BrowseHit hit in hits) { try { int doc = hit.DocId; int idx = ReaderIndex(doc); int deBasedDoc = doc - ReaderBase(idx); Explanation expl = m_subBrowsers[idx].Explain(q, deBasedDoc); hit.SetExplanation(expl); } catch (Exception e) { logger.ErrorException(e.Message, e); result.AddError(e.Message); } } } result.Hits = hits; result.NumHits = collector.TotalHits; result.NumGroups = collector.TotalGroups; result.GroupAccessibles = collector.GroupAccessibles; result.SortCollector = collector; result.TotalDocs = this.NumDocs; result.AddAll(facetCollectors); long end = System.Environment.TickCount; result.Time = (end - start); // set the transaction ID to trace transactions result.Tid = req.Tid; return(result); }
///<summary>browses the index.</summary> ///<param name="req">browse request </param> ///<returns> browse result </returns> public virtual BrowseResult Browse(BrowseRequest req) // throws BrowseException { if (reader == null) { return new BrowseResult(); } BrowseResult result = new BrowseResult(); long start = System.Environment.TickCount; int offset = req.Offset; int count = req.Count; if (offset < 0 || count <= 0) { throw new ArgumentException("the offset must be >= 0 and count must be > 0: " + offset + "/" + count); } TopDocsSortedHitCollector myHC = GetSortedHitCollector(req.Sort, offset, count, req.FetchStoredFields); Dictionary<string, IFacetAccessible> facetCollectors = new Dictionary<string, IFacetAccessible>(); Browse(req, myHC, facetCollectors); BrowseHit[] hits = null; try { hits = myHC.GetTopDocs(); } catch (System.IO.IOException e) { logger.Error(e.Message, e); hits = new BrowseHit[0]; } result.Hits = hits; result.NumHits = myHC.GetTotalHits(); result.TotalDocs = reader.NumDocs(); result.AddAll(facetCollectors); long end = System.Environment.TickCount; result.Time = end - start; return result; }