Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4.0 Facet Drill Down and Drill Sideways support #364

Open
wants to merge 15 commits into
base: release/4.0
Choose a base branch
from

Conversation

nzdev
Copy link
Contributor

@nzdev nzdev commented Dec 5, 2023

Adds support for Facet Drill Down and Drill Sideways
Adds tests for Facet Drill Down and Drill Sideways
See GivenTaxonomyIndexFacetDrillDownSubquery_Returns_ExpectedTotals_Facet test for usage.
Add examples to docs

DrillDown Query

DrillDown query is used to drill down and sideways on facets.

Basic MatchAll Query example

// 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<IFacetOperations>)(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

// 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<IFacetOperations>)(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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant