/// <summary> /// Creates a browser request from the passed in key value pair query string to handle a multirequest(ex. 2x f_category in query) /// </summary> /// <param name="querystring"></param> /// <param name="page"></param> /// <param name="useOffset"></param> /// <param name="itemsPerPage"></param> /// <returns></returns> public virtual BrowseRequest CreateMultiBrowseRequest(List <KeyValuePair <string, string> > querystring, int?page = null, bool useOffset = false, int itemsPerPage = 10) { Query query = null; var compiledQuery = BuildBaseQuery(querystring); if (compiledQuery != null) { var luceneParams = compiledQuery as LuceneSearchCriteria; query = luceneParams?.Query ?? throw new ArgumentException("Provided ISearchCriteria dos not match the allowed ISearchCriteria. Ensure you only use an ISearchCriteria created from the current SearcherProvider"); } var offset = 0; if (!page.HasValue) { page = 1; } var count = page.Value * itemsPerPage; if (useOffset) { offset = (page.Value - 1) * itemsPerPage; count = itemsPerPage; } var browseRequest = new BrowseRequest { Offset = offset, Count = count, Query = query, FetchStoredFields = true, Sort = DetermineSort(querystring) }; var queryStringKeys = querystring.Select(x => x.Key); foreach (var facetField in FacetFields.Where(x => queryStringKeys.Contains(x.Alias.FacetFieldAlias()))) { var facetKvps = querystring.Where(x => x.Key == facetField.Alias.FacetFieldAlias()); foreach (var facetKvp in facetKvps) { var facetValue = facetKvp.Value; if (!string.IsNullOrWhiteSpace(facetValue)) { var sel = browseRequest.GetSelection(facetKvp.Key) ?? new BrowseSelection(facetKvp.Key); sel.AddValue(facetValue); sel.SelectionOperation = facetField.SelectionOperation; browseRequest.RemoveSelection(facetKvp.Key); browseRequest.AddSelection(sel); } } } return(browseRequest); }
/// <summary> /// Adds facet constraints to a browse request. /// </summary> /// <param name="br">The browse request.</param> /// <param name="facetConstraintsSet">The facet constraints for this request.</param> private void AddFacetConstraints(BrowseRequest br, IEnumerable <FacetConstraints> facetConstraintsSet) { // add facet constraints specified in query to the browse request foreach (var facetConstraints in facetConstraintsSet) { if (this.config.IsFacetConfigured(facetConstraints.FacetName)) { var bs = br.GetSelection(facetConstraints.FacetName) ?? new BrowseSelection(facetConstraints.FacetName); foreach (var constraint in facetConstraints.Constraints) { bs.AddValue(constraint); } br.AddSelection(bs); } } }
public void AddSelection(string name, string val, bool isNot) { BrowseSelection sel = m_req.GetSelection(name); if (sel == null) { sel = new BrowseSelection(name); } if (isNot) { sel.AddNotValue(val); } else { sel.AddValue(val); } m_req.AddSelection(sel); }
public void Test8AndPropertiesPlsExclusion() { BrowseRequest request = CreateRequest(1, BrowseSelection.ValueOperation.ValueOperationAnd, "prop1", "prop3"); request.GetSelection(AttributeHandlerName).AddNotValue("prop7"); BrowseResult res = browser.Browse(request); Console.WriteLine(res); Assert.AreEqual(res.NumHits, 1); Assert.AreEqual(res.Hits[0].DocId, 2); IEnumerable <BrowseFacet> facets = res.GetFacetAccessor(AttributeHandlerName).GetFacets(); Assert.AreEqual(facets.Count(), 3); Assert.AreEqual(facets.Get(0).Value, "prop1=val2"); Assert.AreEqual(facets.Get(0).FacetValueHitCount, 1); Assert.AreEqual(facets.Get(1).Value, "prop3=val2"); Assert.AreEqual(facets.Get(1).FacetValueHitCount, 1); Assert.AreEqual(facets.Get(2).Value, "prop3=val3"); Assert.AreEqual(facets.Get(2).FacetValueHitCount, 1); }
public void Test1Filter() { BrowseRequest request = CreateRequest(1, "prop3"); FacetCountCollectorSource facetCountCollectorSource = attributesFacetHandler.GetFacetCountCollectorSource(request.GetSelection(AttributeHandlerName), request.GetFacetSpec(AttributeHandlerName)); RandomAccessFilter randomAccessFilter = attributesFacetHandler.BuildFilter(request.GetSelection(AttributeHandlerName)); DocIdSetIterator iterator = randomAccessFilter.GetDocIdSet(boboReader).Iterator(); int docId = iterator.NextDoc(); int[] docIds = new int[2]; int i = 0; while (docId != DocIdSetIterator.NO_MORE_DOCS) { docIds[i] = docId; i++; docId = iterator.NextDoc(); } Assert.AreEqual(Arrays.ToString(new int[] { 1, 2 }), Arrays.ToString(docIds)); BrowseResult res = browser.Browse(request); Assert.AreEqual(res.NumHits, 2); IFacetAccessible fa = res.GetFacetAccessor(AttributeHandlerName); IEnumerable <BrowseFacet> facets = fa.GetFacets(); Console.WriteLine(facets); Assert.AreEqual(3, facets.Count()); BrowseFacet facet = facets.Get(0); Assert.AreEqual(1, facet.FacetValueHitCount); }