gpt4 book ai didi

search - Thinking Sphinx全应用搜索: filtering by an attribute that only exist in some models

转载 作者:行者123 更新时间:2023-12-02 07:03:30 25 4
gpt4 key购买 nike

我想搜索多个模型并按某些模型具有而某些模型没有的特定属性进行过滤。我希望具有该属性的模型能够被过滤,但没有该属性的模型则忽略它。

目前只有具有该属性的模型才会返回结果。有没有办法通过某种方式忽略属性过滤器来使其他模型也返回结果?

最佳答案

找到了一种方法。在没有此类属性的模型的索引上,可以像这样创建一个虚拟模型:

has "0", :type => :integer, :as => :the_attribute_name

然后在执行应用程序范围内的搜索时:

@results = ThinkingSphinx.search(@search_term, 
:with => {:the_attribute_name => [@the_attribute_value, 0]}
)

顺便说一句,这假设具有此属性的模型不允许使用零值。如果零是这些模型中的有效属性,则可以使用另一个值(例如 9999999)。请注意,属性不能接受负整数。

关于search - Thinking Sphinx全应用搜索: filtering by an attribute that only exist in some models,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4110726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com