private void HandleTermsFacet(string index, Facet facet, IndexQuery indexQuery, IndexSearcher currentIndexSearcher, Dictionary <string, IEnumerable <FacetValue> > results) { var terms = database.ExecuteGetTermsQuery(index, facet.Name, null, database.Configuration.MaxPageSize); var termResults = new List <FacetValue>(); var baseQuery = database.IndexStorage.GetLuceneQuery(index, indexQuery, database.IndexQueryTriggers); foreach (var term in terms) { var termQuery = new TermQuery(new Term(facet.Name, term)); var joinedQuery = new BooleanQuery(); joinedQuery.Add(baseQuery, BooleanClause.Occur.MUST); joinedQuery.Add(termQuery, BooleanClause.Occur.MUST); var topDocs = currentIndexSearcher.Search(joinedQuery, 1); if (topDocs.TotalHits > 0) { termResults.Add(new FacetValue { Count = topDocs.TotalHits, Range = term }); } } results[facet.Name] = termResults; }
public static FacetResults ExecuteGetTermsQuery(this DocumentDatabase self, string index, IndexQuery query, string facetSetupDoc, int start, int?pageSize) { var facetSetup = self.Documents.Get(facetSetupDoc, null); if (facetSetup == null) { throw new InvalidOperationException("Could not find facets document: " + facetSetupDoc); } var facets = facetSetup.DataAsJson.JsonDeserialization <FacetSetup>().Facets; return(self.ExecuteGetTermsQuery(index, query, facets, start, pageSize)); }
public static FacetResults ExecuteGetTermsQuery(this DocumentDatabase self, string index, IndexQuery query, string facetSetupDoc) { return(self.ExecuteGetTermsQuery(index, query, facetSetupDoc, 0, null)); }
///<summary> /// Get the possible terms for the specified field in the index /// You can page through the results by use fromValue parameter as the /// starting point for the next query ///</summary> ///<returns></returns> public IEnumerable <string> GetTerms(string index, string field, string fromValue, int pageSize) { CurrentOperationContext.Headers.Value = OperationsHeaders; return(database.ExecuteGetTermsQuery(index, field, fromValue, pageSize)); }