Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Added facet values aren't used to filter results #3

Closed
ronaldbarendse opened this issue Sep 23, 2020 · 1 comment
Closed

Added facet values aren't used to filter results #3

ronaldbarendse opened this issue Sep 23, 2020 · 1 comment

Comments

@ronaldbarendse
Copy link
Contributor

While using Examine.Facets.MultiFacets, I noticed the values added to a facet aren't used to filter the results and the TotalItemCount reflects the cumulative facet hits, not the amount of returned results.

I've added/configured the FacetSearcher in a component using:

if (this.examineManager.TryGetIndex("ExternalIndex", out var index) &&
    index is LuceneIndex luceneIndex)
{
    var searcher = new MultiFacetSearcher("FacetSearcher", luceneIndex.GetIndexWriter(), luceneIndex.DefaultAnalyzer, luceneIndex.FieldValueTypeCollection);
    this.examineManager.AddSearcher(searcher);

    luceneIndex.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition("creatorName", FieldDefinitionTypes.Raw));
}
if (this.examineManager.TryGetSearcher(Constants.ExternalFacetSearcher, out var searcher))
{
    var query = searcher.CreateQuery(IndexTypes.Content).Facet("creatorName").And().NodeTypeAlias("newsMessage");
    var results = query.Execute();
    var sameResultsCount = results.Count() == results.TotalItemCount; // False, although this should be True
    var sameHitsCount = results.GetFacet("creatorName").Sum(f => f.Hits) == results.TotalItemCount; // True, although this doesn't have to be the case
}
@callumbwhyte
Copy link
Owner

Hey @ronaldbarendse,

Thanks for using Examine Facets!

By default both BoboBrowse and MultiFacets return all facets for a given search - this is because MinHits is 0, so even facets without a match in the given result set are returned. If you wish to only return matching facets you must set MinHits to an appropriate level, like so:

query.Facet("field", "value").MinHits(1);

However, an issue in v1.0.0 means the MinHits() method hasn't been working... 🤪 This is fixed in v1.1.0!

Cheers,
Callum

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

No branches or pull requests

2 participants