思考Sphinx应用程序范围的搜索:按仅存在于某些模型中的属性进行过滤
我想搜索多个模型并按某些模型具有而某些模型没有的特定属性进行过滤。我希望具有该属性的模型被过滤,但没有该属性的模型则忽略它。
目前只有具有该属性的模型才会返回结果。有没有办法通过某种方式忽略属性过滤器来使其他模型也返回结果?
I want to search on multiple models and filter by a certain attribute that some models have and some do not. I want the models with the attribute to get filtered but the ones without it to just ignore it.
Currently only the models with the attribute will return results. Is there a way to make the other models return results as well by somehow ignoring the attribute filter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了一种方法来做到这一点。在不具有此类属性的模型的索引上,可以像这样创建一个虚拟索引:
然后在执行应用程序范围搜索时:
顺便说一句,这假设具有此属性的模型不允许使用零值属性。
如果零是这些模型中的有效属性,则可以使用另一个值(例如 9999999)。
请注意,属性不能接受负整数。
Found a way to do it. On the indexes of the models that do not have such an attribute, a dummy one can be created like so:
Then when performing the application-wide search:
Btw, this assumes that a zero value is not allowed on the models that do have this attribute.
If zero is a valid attribute in those model then another value (e.g. 9999999) can be used.
Be aware that attributes cannot accept negative integers.
我必须在 default_sphinx_scope 中执行此操作,并且应用程序太大,我无法检查每个模型并为那些没有该属性的模型执行此操作。因此,我按照以下方式进行了操作:
仅当存在
status
列时才应用scope
。干杯。I had to do this in a
default_sphinx_scope
and the application being too big I couldn't check every model and do that for those who have doesn't have the attribute. So I did it with following:It applied the
scope
only when thestatus
column was present. Cheers.