Question

A Lucene Query is generated as so:

Query luceneQuery = builder.all().createQuery();

Then facets are applied.

I'm not sure if when facets are applied the luceneQuery is ANDed and ORed with other Querys resulting in a new Lucene Query. Alternatively, perhaps a bunch of BitSets's are applied to the original Query to refine the results. (I don't know).

If a new query is generated I'd like to retrieve it. If not, I need a rethink. That's the crux of the question.

Why:

I'm applying a faceted search on a field with multiple possible values.

E.g. TMovie.class many-to-many TTag.class (multiple-value-facet)

I'm filtering on TMovie where TTag is some value.

Anyway, the filtering works but there is a known problem whereby the Facet-counts returned are incorrect. Detailed here: Add faceting over multivalued to application using Hibernate Search and https://forum.hibernate.org/viewtopic.php?f=9&t=1010472

I'm using this solution: http://sujitpal.blogspot.ie/2007/04/lucene-search-within-search-with.html (see comment on new API under article)

The BitSet solution (in this example at least) generates counts based on the original Lucene Query. This works perfectly. However.....

If alternate (different, not TTags) facets are applied to the original query some complications arise. The Bitset solution calculates on the original Lucene query. It does not calculate on the lucene query now reduced by the application of alternate Facets (a different FacetSelection) (or even TTag Facets themselves for that matter). I.e. the count calculations are irrespective of any other FacetSelection Facets applied.

So...

A. can I get the new Lucene query after facets are applied? The BitSet solution applied to this would be correct.

B. Any other alternative suggestions?

Thanks so much.. All comments welcome.

John

Was it helpful?

Solution

Regarding your first question, applying a facet is not modifying the original query, it uses a custom Collector called FacetCollector - see https://github.com/hibernate/hibernate-search/blob/master/engine/src/main/java/org/hibernate/search/query/collector/impl/FacetCollector.java. Under the hood the collector uses a Lucene FieldCache for doing the facet count. There is also the root of the limitation for multi-value faceting. FieldCache does not support multiple values per field.

Anyways, no additional queries are applied during faceting and the original query is unmodified. The benefit of course is performance. The solution you are pointing to probably works as well, but relies on running multiple queries. However, it might be a valid work around for your use case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top