Geodist with where or match

90 Views Asked by At

I need combine this 2 query in one, and sort by Id,

select GEODIST(40, 50, latitude,longitude, {in=degrees, out=meters}) AS distance, id FROM offersRT WHERE distance<=1000 LIMIT 0,30;

and

select 0 as distance, id FROM offersRT WHERE MATCH('@location_path_id 39644') LIMIT 0,30;

I use Manticore 3.6.0.

I can't use OR statement like

WHERE distance<=1000 or MATCH('@location_path_id 39644')

i also try like this:

SELECT id FROM (
      select 0 as distance, id FROM offersRT WHERE MATCH('@location_path_id 39644') LIMIT 0,30;
      select GEODIST(40, 50, latitude,longitude, {in=degrees, out=meters}) AS distance, id FROM offersRT WHERE distance<=1000 LIMIT 0,30;
);

and not working too.

Is there any other option to do this?

1

There are 1 best solutions below

2
barryhunter On

Well it MATCH('@location_path_id 39644') doesnt really need to use the 'keywords' index. Its not a really a keyword match, and something that can easily be done with an attribute filter. Ie can just make location_path_id an attribute.

Manticore at least should then support OR directly in the WHERE (it just doesn't with MATCH)

SELECT GEODIST(40, 50, latitude,longitude, {in=degrees, out=meters}) AS distance, id 
FROM offersRT WHERE distance<=1000 OR location_path_id = 39644 LIMIT 0,30;

But if that doesn't work, can definitely implement the 'OR' in the SELECT section

SELECT GEODIST(40, 50, latitude,longitude, {in=degrees, out=meters})<=100 + location_path_id = 39644 AS filter, id 
FROM offersRT WHERE filter > 0 LIMIT 0,30;

The second form should work even in Sphinx.