使用 Thinking Sphinx 在 sphinx 中搜索多边形
Searching in polygons in sphinx using Thinking Sphinx
我已经设置了用于实时索引的 thinking sphinx,它工作得很好并且使用 geodist 进行搜索 well.But 现在我想在多边形内搜索记录。
Sphinx 文档在 Geo-distance searching
中对其进行了很好的解释
现在我想通过思维狮身人面像来使用这个功能。
Thinking sphinx 确实解释了 geodist 搜索 Here
但它没有说明如何在多边形内搜索。
有人可以帮我做吗?
Thinking Sphinx 没有内置任何东西来为多边形搜索提供简洁的界面,但肯定可以使用该功能。
您需要生成您想要的 SphinxQL SELECT
子句,相应地对其进行过滤,and/or 您可以使用 AttributesPane
访问您的自定义属性。希望以下代码清晰:
search = Model.search("foo",
:select => "*, CONTAINS(GEOPOLY2D(...), ...) AS inside",
:with => {:inside => true}
); ""
search.context[:panes] << ThinkingSphinx::Panes::AttributesPane
search.collect { |instance| instance.sphinx_attributes["inside"] }
只有在 IRB 或 Rails 控制台中 运行 时才需要第一个语句末尾的 ; ""
- 你想避免调用 search
一种在添加窗格之前评估结果的方法。搜索结果通常是延迟加载的,但 IRB 调用 inspect
来打印语句结果,这消除了延迟优势。
窗格在 a blog post I wrote, and the source code for the AttributesPane class is very simple. You may also want to write a custom middleware class that uses your own options and translates them into the polygon functions - the Geographer class 中讨论(将 :geo
翻译成 GEODIST
)是一个很好的参考。
我已经设置了用于实时索引的 thinking sphinx,它工作得很好并且使用 geodist 进行搜索 well.But 现在我想在多边形内搜索记录。
Sphinx 文档在 Geo-distance searching
中对其进行了很好的解释现在我想通过思维狮身人面像来使用这个功能。 Thinking sphinx 确实解释了 geodist 搜索 Here 但它没有说明如何在多边形内搜索。
有人可以帮我做吗?
Thinking Sphinx 没有内置任何东西来为多边形搜索提供简洁的界面,但肯定可以使用该功能。
您需要生成您想要的 SphinxQL SELECT
子句,相应地对其进行过滤,and/or 您可以使用 AttributesPane
访问您的自定义属性。希望以下代码清晰:
search = Model.search("foo",
:select => "*, CONTAINS(GEOPOLY2D(...), ...) AS inside",
:with => {:inside => true}
); ""
search.context[:panes] << ThinkingSphinx::Panes::AttributesPane
search.collect { |instance| instance.sphinx_attributes["inside"] }
只有在 IRB 或 Rails 控制台中 运行 时才需要第一个语句末尾的 ; ""
- 你想避免调用 search
一种在添加窗格之前评估结果的方法。搜索结果通常是延迟加载的,但 IRB 调用 inspect
来打印语句结果,这消除了延迟优势。
窗格在 a blog post I wrote, and the source code for the AttributesPane class is very simple. You may also want to write a custom middleware class that uses your own options and translates them into the polygon functions - the Geographer class 中讨论(将 :geo
翻译成 GEODIST
)是一个很好的参考。