sphinx 发出(丢弃)搜索字段
sphinx emit (discard) search fields
假设我们有一些搜索参数,如(作者、流派、成本),我们必须获得 N=15
行
查询:select ... where author=a and genre=b and cost=b LIMIT N
我们必须得到 N
行,但我们只找到了 2 行。然后我们必须发出参数成本。
查询:select ... where author=a and genre=b LIMIT N
现在我们有 10 < N
行,所以我们必须发出 author
查询:select ... where author=a LIMIT N
等等..
如何以正确的方式进行(我认为进行多次查询很昂贵,
进行如下查询:select if (author=a and genre=b and cost=c, 1, 0) as f, if (author=a and genre=b, 1, 0) as s, ... order by f desc, s desc, ...
也很昂贵,因为 table 有更多 500 000 行
您可以使用
提高效率
select ...,author=a + genre=b + cost=c as f from order by d desc
(如果想保持优先级可以做(author=a * 4) + ...
等)
但一般来说,您没有 MATCH(),因此查询将始终是完整的 table 扫描。它将必须检查并可能对 table 中的每一行进行排序。
没有办法让它真正高效。 (除了预先计算值并将它们存储在索引中 - 甚至可以预先计算字段中的值以利用全文索引)
假设我们有一些搜索参数,如(作者、流派、成本),我们必须获得 N=15
行
查询:select ... where author=a and genre=b and cost=b LIMIT N
我们必须得到 N
行,但我们只找到了 2 行。然后我们必须发出参数成本。
查询:select ... where author=a and genre=b LIMIT N
现在我们有 10 < N
行,所以我们必须发出 author
查询:select ... where author=a LIMIT N
等等..
如何以正确的方式进行(我认为进行多次查询很昂贵,
进行如下查询:select if (author=a and genre=b and cost=c, 1, 0) as f, if (author=a and genre=b, 1, 0) as s, ... order by f desc, s desc, ...
也很昂贵,因为 table 有更多 500 000 行
您可以使用
提高效率select ...,author=a + genre=b + cost=c as f from order by d desc
(如果想保持优先级可以做(author=a * 4) + ...
等)
但一般来说,您没有 MATCH(),因此查询将始终是完整的 table 扫描。它将必须检查并可能对 table 中的每一行进行排序。
没有办法让它真正高效。 (除了预先计算值并将它们存储在索引中 - 甚至可以预先计算字段中的值以利用全文索引)