Martin Braun
Martin Braun

Reputation: 602

Conditional FilterQuery in Solr

Is it possible to conditionally execute a FilterQuery (fq)?

In other words: Only execute it if a certain condition is true.

Example:

I have multiple cities and their geolocation in my solr database. And I additionally store wheter they are important. Now I want to query all cities in a certain range of a geolocation but also always return the important cities.

Or in SQL-like Syntax (I know it's horrible and not even correct SQL, but it explains my needs):

select *
from cities
having distance(cityname, 30, 30) or important(cityname)

So far I haven't found anything like that. I could do that in a custom filter query but I'd rather not want to do that :).

Thanks in advance.

EDIT:

Realworld-like thing I want to use it for:

{!geofilt pt=30.2,23.0 sfield=locationCoordinates d=20 cost=20} or nationWide:true

EDIT2:

Solution:

map(query({!geofilt pt=20.3,30.2 sfield=locationCoordinates d=1}, -1), -1, -1,   nationWide:true)

Negative values should be ok to use in this scenario: http://www.solrtutorial.com/solr-search-relevancy.html

Upvotes: 2

Views: 1639

Answers (1)

Srikanth Venugopalan
Srikanth Venugopalan

Reputation: 9049

You could try using FunctionQuery. There are pre-built functions available or you could write a custom Function Query.

Since you mention city, I am tempted to point you to the Geohash function, but am not sure if this is what you are looking for.

Upvotes: 2

Related Questions