Hardik Dobariya
Hardik Dobariya

Reputation: 349

Get all facets in lucene.net using SimpleFacetedSearch

I am trying to implement faceted search by using the SimpleFacetedSearch example that was added to Lucene 2.9.4 and I want to know whether is it possible to get all the facets in Lucene.NET using SimpleFacetedSearch?

Say for example i have three columns indexed

ID A B
1 | F1 | E1
2 | F2 | E2
3 | F1 | E1
4 | F3 | E3
5 | F2 | E2

According to my understanding of SimpleFacetedSearch, I have to parse a query, pass it to SimpleFacetedSearch and then search it - which will only get facets matched with the parsed query.

But I want all of the facets without having to parse a query: that is, the facet counts of all possible facets in the index.

Say in above table i want the output as

A=F1(2),F2(2),F3(1)

B=E1(2),E2(2),E3(1)

In short I do not want to parse any query and want all facets returned for the entire index. Thanks

Upvotes: 2

Views: 1196

Answers (1)

Scott Simontis
Scott Simontis

Reputation: 818

You can use the MatchAllDocsQuery query, so you would create your query as Query query = new MatchAllDocsQuery(). Then you simply call Search with that query passed. You do not have to parse it since this is part of Lucene's query API, you must only parse a query when it is coming from the user. Basically, use a QueryParser when your query is being generated by a user, but use the Query API to add terms when you want to programmatically generate queries, I do not think they did a good job of teaching that in the example code for SFS.

Do keep in mind that max values are set in SimpleFacetedSearch, mainly MAXFACETS=2048, which means an exception will be thrown if you have more than 2048 facet combinations present. You can tweak this value if you need to, but keep in mind that faceting is an expensive operation and you will increase the search time by going through so many facets.

I am not sure you understand faceting by the example you gave. Sample output would be { (F1,E1) - 2, (F2, E2) - 2, (F3, E3) - 1 } where the sets are in parentheses with the count after the dash.

Upvotes: 1

Related Questions