【问题标题】:Geodist with where or matchGeodist 与 where 或 match
【发布时间】:2021-08-30 12:15:49
【问题描述】:

我需要将这 2 个查询合二为一,并按 Id 排序,

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

和

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

我使用 Manticore 3.6.0。

我不能像这样使用 OR 语句

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

我也这样尝试:

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;
);

也没有工作。

还有其他选择吗?

【问题讨论】:

    标签: full-text-search sphinx sphinxql manticore-search


    【解决方案1】:

    它 MATCH('@location_path_id 39644') 并不真的需要使用“关键字”索引。它不是一个真正的关键字匹配,并且可以通过属性过滤器轻松完成。即可以将location_path_id 设为属性。

    Manticore 至少应该在 WHERE 中直接支持 OR(它只是不支持 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;
    

    但是如果这不起作用,绝对可以在SELECT部分​​实现'OR'

    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;
    

    第二种形式即使在 Sphinx 中也应该可以工作。

    【讨论】:

    • MATCH('@location_path_id 39644') 必须是关键字索引,因为它们包含多个 id,例如“39644 123 983 23234”等。按属性搜索需要全索引扫描。我没有找到解决方案,所以我重构了所有代码,只使用一个匹配 location_path_id 的查询。
    • 这样的多个值可以进入特殊的多值属性 (MVA) 类型。它专门用于保存多个 id。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 2019-09-27
    • 2021-06-07
    相关资源
    最近更新 更多