0

I have a database of books, each which has a list of subjects attached. I would like to build a query so that when a user searches for a subject, Solr returns a list of subjects that follow the query alphabetically. For example, if the user were to make the query "whale", then I would like Solr to return the list of subjects "whale hunting", "whales", "wheat", etc. I'm only interested in the aggregation of subjects, not in the items that match the query.

However, there is an issue in that a book can have multiple subjects. If a document has subjects "arctic" and "whale", then the query "whale" matches "whale", but "arctic" shows up in my facets as well, which I don't want. I'd like to avoid having to parse through all the results, since that is a potentially expensive operation.

What's the best solution for this? Is there any way to tell Solr to only return facets where the facet is [whale* TO *]? Or can I build my query so that it will only consider the subject that matches to be a part of the facets?

I've looked at and have tinkered a little with the JSON request API, which seems like it could be the solution, but I'm having trouble getting the various filters etc. to work.

Andy
  • 151
  • 7

1 Answers1

0

The facet.prefix Parameter

The facet.prefix parameter limits the terms on which to facet to those starting with the given string prefix. This does not limit the query in any way, only the facets that would be returned in response to the query. This parameter can be specified on a per-field basis with the syntax of f..facet.prefix.

[Example]

facet.prefix=whales

This will return only those subjects which contains whales as prefix.

There is another parameter facet.contains limits the terms on which to facet to those containing the given substring.

P.S :- Above Parameter does not limit the query in any way, only the facets that would be returned in response to the query.

Sanjay Dutt
  • 2,192
  • 16
  • 16
  • Ah, I saw the facet.prefix parameter, and it would work for the most part, but unfortunately I need an alphabetical list. If I set the prefix to be "whale", it would return "whales" but not "wheat." I need something a little more flexible than that. Thanks for the idea though! – Andy Mar 20 '17 at 22:06