public void TestFacetSelectionFilter() { var query = new MatchAllDocsQuery(); Console.WriteLine(string.Format("query: <{0}>", query.ToString())); var request = new BrowseRequest() { Count = 10, Offset = 0, Query = query }; var authors = new string[] { "kathy", "sierra" };//kathy&sierra var sectionFilter = new BrowseSelection("author"); sectionFilter.Values = authors; sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd; request.AddSelection(sectionFilter); var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), new IFacetHandler[] { new MultiValueFacetHandler("author") })); var result = browser.Browse(request); Console.WriteLine("==========================="); for (var i = 0; i < result.Hits.Length; i++) { var doc = browser.Doc(result.Hits[i].DocId); var category = _categories.First(k => k.Value == int.Parse(doc.GetField("category").StringValue)).Key; Console.WriteLine(string.Format("{2} - {0} ${1} by {3}", doc.GetField("name").StringValue, doc.GetField("price").StringValue, category, doc.GetField("author").StringValue)); } }
public void TestMultiValPath() { IndexReader reader = IndexReader.Open(directory, true); BoboIndexReader boboReader = BoboIndexReader.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); IEnumerable<BrowseFacet> facets = fa.GetFacets(); Console.WriteLine(facets); Assert.AreEqual(1, facets.Count()); BrowseFacet facet = facets.Get(0); Assert.AreEqual(2, facet.FacetValueHitCount); }
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 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 void TestRangeFacetHandler() { var query = new MatchAllDocsQuery(); Console.WriteLine(string.Format("query: <{0}>", query.ToString())); var testRangeFacetHandlers = new List <IFacetHandler>(); //testRangeFacetHandlers.Add(new RangeFacetHandler("year", true));//auto range // NightOwl888 - Auto range is no longer a feature. testRangeFacetHandlers.Add(new RangeFacetHandler("year", new List <string>(new string[] { "[* TO 2000]", "[2000 TO 2005]", "[2006 TO 2010]", "[2011 TO *]" }))); //testRangeFacetHandlers.Add(new RangeFacetHandler("price", "price", new NumberFieldFactory(), true)); // NightOwl888 - Auto range is no longer a feature. for (var i = 0; i < testRangeFacetHandlers.Count; i++) { var request = new BrowseRequest() { Count = 100, Offset = 0, Query = query, Sort = new Lucene.Net.Search.Sort(new SortField("price", SortField.DOUBLE, false)).GetSort() }; var sectionFilter = new BrowseSelection("category"); sectionFilter.NotValues = new string[] { "5" }; sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd; request.AddSelection(sectionFilter); var faceHandler = testRangeFacetHandlers[i]; var faceHandlers = new IFacetHandler[] { faceHandler, new SimpleFacetHandler("category") }; var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers)); var factSpec = new FacetSpec() { OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc }; request.SetFacetSpec(faceHandler.Name, factSpec); var result = browser.Browse(request); Console.WriteLine(string.Format("total hits:{0}", result.NumHits)); foreach (var facet in result.FacetMap[faceHandler.Name].GetFacets()) { Console.WriteLine(facet.ToString()); } Console.WriteLine(""); } }
private static void DoBrowse(BoboBrowser browser) { String q = "java"; QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_CURRENT, "b", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT)); Query query = parser.Parse(q); BrowseRequest br = new BrowseRequest(); //br.setQuery(query); br.Offset = 0; br.Count = 0; BrowseSelection geoSel = new BrowseSelection("geo_region"); geoSel.AddValue("5227"); BrowseSelection industrySel = new BrowseSelection("industry_norm"); industrySel.AddValue("1"); //br.AddSelection(geoSel); br.AddSelection(industrySel); FacetSpec regionSpec = new FacetSpec(); regionSpec.ExpandSelection = true; regionSpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc; regionSpec.MaxCount = 5; FacetSpec industrySpec=new FacetSpec(); industrySpec.ExpandSelection = true; industrySpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc; industrySpec.MaxCount = 5; FacetSpec numEndorserSpec=new FacetSpec(); numEndorserSpec.ExpandSelection = true; br.SetFacetSpec("industry_norm", industrySpec); br.SetFacetSpec("geo_region", regionSpec); br.SetFacetSpec("num_endorsers_norm", numEndorserSpec); long start = System.Environment.TickCount; BrowseResult res = browser.Browse(br); long end = System.Environment.TickCount; Console.WriteLine("result: " + res); Console.WriteLine("took: " + (end-start)); }
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 void TestFacetNameForSimpleFacetHandler() { BrowseRequest br = new BrowseRequest(); br.Count = 20; br.Offset = 0; BrowseSelection colorSel = new BrowseSelection("mycolor"); colorSel.AddValue("yellow"); br.AddSelection(colorSel); BrowseSelection makeSel = new BrowseSelection("make"); makeSel.AddValue("rav4"); br.AddSelection(makeSel); FacetSpec spec = new FacetSpec(); spec.ExpandSelection = true; spec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc; spec.MaxCount = 15; br.SetFacetSpec("mycolor", spec); br.SetFacetSpec("id", spec); br.SetFacetSpec("make", spec); BrowseResult result = null; BoboBrowser boboBrowser = null; int expectedHitNum = 3; try { Directory ramIndexDir = CreateIndex(); IndexReader srcReader = IndexReader.Open(ramIndexDir, true); boboBrowser = new BoboBrowser(BoboIndexReader.GetInstance(srcReader, _facetHandlers, null)); result = boboBrowser.Browse(br); Assert.AreEqual(expectedHitNum, result.NumHits); } catch (BrowseException e) { Assert.Fail(e.Message); } catch (System.IO.IOException ioe) { Assert.Fail(ioe.Message); } finally { if (boboBrowser != null) { try { boboBrowser.Close(); } catch (System.IO.IOException e) { Assert.Fail(e.Message); } } } }
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 TestRangeFacetHandler() { var query = new MatchAllDocsQuery(); Console.WriteLine(string.Format("query: <{0}>", query.ToString())); var testRangeFacetHandlers = new List<IFacetHandler>(); //testRangeFacetHandlers.Add(new RangeFacetHandler("year", true));//auto range // NightOwl888 - Auto range is no longer a feature. testRangeFacetHandlers.Add(new RangeFacetHandler("year", new List<string>(new string[] { "[* TO 2000]", "[2000 TO 2005]", "[2006 TO 2010]", "[2011 TO *]" }))); //testRangeFacetHandlers.Add(new RangeFacetHandler("price", "price", new NumberFieldFactory(), true)); // NightOwl888 - Auto range is no longer a feature. for (var i = 0; i < testRangeFacetHandlers.Count; i++) { var request = new BrowseRequest() { Count = 100, Offset = 0, Query = query, Sort = new Lucene.Net.Search.Sort(new SortField("price", SortField.DOUBLE, false)).GetSort() }; var sectionFilter = new BrowseSelection("category"); sectionFilter.NotValues = new string[] { "5" }; sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd; request.AddSelection(sectionFilter); var faceHandler = testRangeFacetHandlers[i]; var faceHandlers = new IFacetHandler[] { faceHandler, new SimpleFacetHandler("category") }; var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers)); var factSpec = new FacetSpec() { OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc }; request.SetFacetSpec(faceHandler.Name, factSpec); var result = browser.Browse(request); Console.WriteLine(string.Format("total hits:{0}", result.NumHits)); foreach (var facet in result.FacetMap[faceHandler.Name].GetFacets()) { Console.WriteLine(facet.ToString()); } Console.WriteLine(""); } }
public void TestFacetSelectionFilter() { var query = new MatchAllDocsQuery(); Console.WriteLine(string.Format("query: <{0}>", query.ToString())); var request = new BrowseRequest() { Count = 10, Offset = 0, Query = query }; var authors = new string[] { "kathy", "sierra" };//kathy&sierra var sectionFilter = new BrowseSelection("author"); sectionFilter.Values = authors; sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd; request.AddSelection(sectionFilter); var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), new IFacetHandler[] { new MultiValueFacetHandler("author") })); var result = browser.Browse(request); Console.WriteLine("==========================="); for (var i = 0; i < result.Hits.Length; i++) { var doc = browser.Doc(result.Hits[i].DocId); var category = _categories.First(k => k.Value == int.Parse(doc.GetField("category").StringValue)).Key; Console.WriteLine(string.Format("{2} - {0} ${1} by {3}", doc.GetField("name").StringValue, doc.GetField("price").StringValue, category, doc.GetField("author").StringValue)); } }
public void TestNotValuesForRangeFacetHandler() { Console.WriteLine("TestNotValuesForRangeFacetHandler"); BrowseResult result = null; BoboBrowser boboBrowser=null; using (Directory ramIndexDir = CreateIndexTwo()) { using (IndexReader srcReader = IndexReader.Open(ramIndexDir, true)) { using (boboBrowser = new BoboBrowser(BoboIndexReader.GetInstance(srcReader, _facetHandlers, null))) { BrowseRequest br = new BrowseRequest(); br.Count = (20); br.Offset = (0); if (_idRanges == null) { log.Error("_idRanges cannot be null in order to test NOT on RangeFacetHandler"); } BrowseSelection idSel = new BrowseSelection("idRange"); //int rangeIndex = 2; // Not used idSel.AddNotValue(_idRanges[0]); int expectedHitNum = 1; br.AddSelection(idSel); BooleanQuery q = new BooleanQuery(); q.Add(NumericRangeQuery.NewIntRange("NUM", 10, 10, true, true), Occur.MUST_NOT); q.Add(new MatchAllDocsQuery(), Occur.MUST); br.Query = q; result = boboBrowser.Browse(br); Assert.AreEqual(expectedHitNum, result.NumHits); for (int i = 0; i < result.NumHits; i++) { Console.WriteLine(result.Hits[i]); } } } } }
public void TestNotValuesForSimpleFacetHandler() { BrowseRequest br = new BrowseRequest(); br.Count = 20; br.Offset = 0; BrowseSelection colorSel = new BrowseSelection("color"); colorSel.AddValue("red"); br.AddSelection(colorSel); BrowseSelection idSel = new BrowseSelection("id"); idSel.AddNotValue("0"); br.AddSelection(idSel); BrowseResult result = null; BoboBrowser boboBrowser = null; int expectedHitNum = (_documentSize / 2) - 1; using (Directory ramIndexDir = CreateIndex()) { using (IndexReader srcReader = IndexReader.Open(ramIndexDir, true)) { using (boboBrowser = new BoboBrowser(BoboIndexReader.GetInstance(srcReader, _facetHandlers, null))) { result = boboBrowser.Browse(br); Assert.AreEqual(expectedHitNum, result.NumHits); StringBuilder buffer = new StringBuilder(); BrowseHit[] hits = result.Hits; for (int i = 0; i < hits.Length; ++i) { int expectedID = (i + 1) * 2; Assert.AreEqual(expectedID, int.Parse(hits[i].GetField("id"))); if (i != 0) { buffer.Append('\n'); } buffer.Append("id=" + hits[i].GetField("id") + "," + "color=" + hits[i].GetField("color")); } log.Info(buffer.ToString()); } } } }
public void TestFacetNameForSimpleFacetHandler() { BrowseRequest br = new BrowseRequest(); br.Count = 20; br.Offset = 0; BrowseSelection colorSel = new BrowseSelection("mycolor"); colorSel.AddValue("yellow"); br.AddSelection(colorSel); BrowseSelection makeSel = new BrowseSelection("make"); makeSel.AddValue("rav4"); br.AddSelection(makeSel); FacetSpec spec = new FacetSpec(); spec.ExpandSelection = true; spec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc; spec.MaxCount = 15; br.SetFacetSpec("mycolor", spec); br.SetFacetSpec("id", spec); br.SetFacetSpec("make", spec); int expectedHitNum = 3; Directory ramIndexDir = CreateIndex(); using (IndexReader srcReader = IndexReader.Open(ramIndexDir, true)) { using (BoboIndexReader boboReader = BoboIndexReader.GetInstance(srcReader, _facetHandlers, null)) { using (BoboBrowser boboBrowser = new BoboBrowser(boboReader)) { using (BrowseResult result = boboBrowser.Browse(br)) { Assert.AreEqual(expectedHitNum, result.NumHits); } } } } }
public void TestIndexReload() { try { RAMDirectory idxDir = new RAMDirectory(); Document[] docs = BoboTestCase.BuildData(); BoboIndexReader.WorkArea workArea = new BoboIndexReader.WorkArea(); BrowseRequest req; BrowseSelection sel; BoboBrowser browser; BrowseResult result; IndexWriter writer = new IndexWriter(idxDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED); writer.Close(); int dup = 0; for (int j = 0; j < 50; j++) { IndexReader idxReader = IndexReader.Open(idxDir, true); BoboIndexReader reader = BoboIndexReader.GetInstance(idxReader, _fconf, workArea); req = new BrowseRequest(); req.Offset = 0; req.Count = 10; sel = new BrowseSelection("color"); sel.AddValue("red"); req.AddSelection(sel); browser = new BoboBrowser(reader); result = browser.Browse(req); Assert.AreEqual(3 * dup, result.NumHits); req = new BrowseRequest(); req.Offset = 0; req.Count = 10; sel = new BrowseSelection("tag"); sel.AddValue("dog"); req.AddSelection(sel); browser = new BoboBrowser(reader); result = browser.Browse(req); Assert.AreEqual(2 * dup, result.NumHits); req = new BrowseRequest(); req.Offset = 0; req.Count = 10; sel = new BrowseSelection("tag"); sel.AddValue("funny"); req.AddSelection(sel); browser = new BoboBrowser(reader); result = browser.Browse(req); Assert.AreEqual(3 * dup, result.NumHits); writer = new IndexWriter(idxDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.UNLIMITED); for (int k = 0; k <= j; k++) { for (int i = 0; i < docs.Length; i++) { writer.AddDocument(docs[i]); } dup++; } writer.Close(); } idxDir.Close(); } catch (Exception e) { Assert.Fail(e.Message); } }
public BrowseRequest ConvertBrowseRequest(BoboRequest boboRequest) { Query query = this.queryBuilder.ParseQuery(boboRequest.Query, boboRequest.Df); Sort sort = this.queryBuilder.ParseSort(boboRequest.Sort); var browseRequest = new BrowseRequest(); browseRequest.Offset = boboRequest.Start; browseRequest.Count = boboRequest.Rows; browseRequest.Query = query; if (sort != null) { SortField[] sortFields = sort.GetSort(); if (sortFields != null && sortFields.Length > 0) { browseRequest.Sort = sortFields; } } var selMap = new Dictionary<string, BrowseSelection>(); foreach (var selection in boboRequest.Selections) { BrowseSelection sel = selMap.ContainsKey(selection.Name) ? selMap[selection.Name] : null; if (sel == null) { sel = new BrowseSelection(selection.Name); selMap.Add(selection.Name, sel); } foreach (var val in selection.Values) { sel.AddValue(val); } sel.SelectionOperation = selection.SelectionOperation; sel.SetSelectionProperty("depth", selection.Depth.ToString()); sel.SetSelectionProperty("strict", selection.Strict.ToString().ToLower()); } if (selMap.Count > 0) { var sels = selMap.Values; foreach (var sel in sels) { browseRequest.AddSelection(sel); } } if (boboRequest.Facet == true) { foreach (var facet in boboRequest.Facets) { FacetSpec fspec = new FacetSpec(); browseRequest.SetFacetSpec(facet.Name, fspec); fspec.MinHitCount = facet.MinCount == int.MinValue ? 0 : facet.MinCount; fspec.MaxCount = facet.Limit == int.MinValue ? 100 : facet.Limit; fspec.ExpandSelection = facet.Expand; fspec.OrderBy = ParseFacetSort(facet.Sort, FacetSpec.FacetSortSpec.OrderHitsDesc); } } return browseRequest; }