Gunjan
Gunjan

Reputation: 1237

filtering results in solr

I'm trying to build auto suggest functionality using Solr. The index contains different locations within a city and looks something like

id: unique id
name: the complete name
type: can be one of 'location_zone', 'location_subzone', 'location_city', 'outlet', 'landmark' ...
city: city id

now when the user types something, I want it to return suggestion only from the current city and of type location_*. something similar to WHERE city_id = 1 AND type="location_%" in SQL.

I guess one way to do it is by faceting but is that the right way? will it still search in all documents and then filter the results or will it apply the condition first as mysql would do it

PS: I'm new to solr and would appreciate if you can point out any mistakes in the approach

Upvotes: 0

Views: 3299

Answers (1)

Karl Johansson
Karl Johansson

Reputation: 1751

Solr does provide filtering, using the fq parameter. What you're looking for should be something along the lines of:

&fq=city_id:1&fq=type:location_*&q=...

This page illustrates very well how and when to use filter queries in Solr.

Upvotes: 2

Related Questions