From 1b6224c9aed9608856a71bda0b59931e97b26e5c Mon Sep 17 00:00:00 2001 From: Chad Currie Date: Wed, 6 Dec 2023 03:36:58 +1300 Subject: [PATCH] Add examples to docs --- docs/articles/searching.md | 111 +++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/docs/articles/searching.md b/docs/articles/searching.md index 6b2fd025..aa7a1c15 100644 --- a/docs/articles/searching.md +++ b/docs/articles/searching.md @@ -437,6 +437,117 @@ var createdFacetResults = results.GetFacet("Created"); // Returns the facets for var firstRangeValue = createdFacetResults.Facet("first"); // Gets the IFacetValue for the facet "first" ``` +### DrillDown Query + +DrillDown query is used to drill down and sideways on facets. + +#### Basic MatchAll Query example + +```csharp +// Setup + +// Create a config +var facetsConfig = new FacetsConfig(); +facetConfigs.SetHierarchical("publishDate", true); + +services.AddExamineLuceneIndex("MyIndex", + // Set the indexing of your fields to use the facet type + fieldDefinitions: new FieldDefinitionCollection( + new FieldDefinition("publishDate", FieldDefinitionTypes.FacetTaxonomyFullText), + new FieldDefinition("Author", FieldDefinitionTypes.FacetTaxonomyFullText) + ), + // Pass your config + facetsConfig: facetsConfig, + // Enable the Taxonomy sidecar index, required for Heirachy facets + useTaxonomyIndex: true + ); + + +var searcher = myIndex.Searcher; +var results = searcher.CreateQuery() + .DrillDownQuery( + dims => + { + // Specify the dimensions to drill down on + dims.AddDimension("Author", "Lisa"); + }, + null // Optional base query to drill down over + , + sideways => + { + // Drill Sideways for the top 10 facets + sideways.SetTopN(10); + }, + BooleanOperation.Or // Default operation for boolean subqueries + ) + .WithFacets((Action)(facets => + { + //Fetch the facets + facets.FacetString("publishDate", x => x.MaxCount(10)); + facets.FacetString("Author", x => x.MaxCount(10)); + })); + .Execute(); + +var publishDateResults = results.GetFacet("publishDate"); // Returns the facets for the specific field publishDate +var AuthorFacetResults = results.GetFacet("Author"); // Returns the facets for the specific field publishDate + +``` + +#### Basic BaseQuery example + +```csharp +// Setup + +// Create a config +var facetsConfig = new FacetsConfig(); +facetConfigs.SetHierarchical("publishDate", true); + +services.AddExamineLuceneIndex("MyIndex", + // Set the indexing of your fields to use the facet type + fieldDefinitions: new FieldDefinitionCollection( + new FieldDefinition("publishDate", FieldDefinitionTypes.FacetTaxonomyFullText), + new FieldDefinition("Author", FieldDefinitionTypes.FacetTaxonomyFullText) + ), + // Pass your config + facetsConfig: facetsConfig, + // Enable the Taxonomy sidecar index, required for Heirachy facets + useTaxonomyIndex: true + ); + + +var searcher = myIndex.Searcher; +var results = searcher.CreateQuery() + .DrillDownQuery( + dims => + { + // Specify the dimensions to drill down on + dims.AddDimension("Author", "Lisa"); + }, + baseQuery => // Optional base query to drill down over + { + return baseQuery.Field(ExamineFieldNames.CategoryFieldName, "content"); + } + , + sideways => + { + // Drill Sideways for the top 10 facets + sideways.SetTopN(10); + }, + BooleanOperation.Or // Default operation for boolean subqueries + ) + .WithFacets((Action)(facets => + { + //Fetch the facets + facets.FacetString("publishDate", x => x.MaxCount(10)); + facets.FacetString("Author", x => x.MaxCount(10)); + })); + .Execute(); + +var publishDateResults = results.GetFacet("publishDate"); // Returns the facets for the specific field publishDate +var AuthorFacetResults = results.GetFacet("Author"); // Returns the facets for the specific field publishDate + +``` + ## Lucene queries Find a reference to how to write Lucene queries in the [Lucene 4.8.0 docs](https://lucene.apache.org/core/4_8_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description).