Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search 思考斯芬克斯:单一模型的多重指数?_Search_Thinking Sphinx - Fatal编程技术网

Search 思考斯芬克斯:单一模型的多重指数?

Search 思考斯芬克斯:单一模型的多重指数?,search,thinking-sphinx,Search,Thinking Sphinx,我正在使用Thinking Sphinx以两种不同的模式进行搜索: 在单个型号上进行完整搜索,以实现正常搜索功能 在所有型号中全面搜索自动完成下拉功能 为了这个问题,让我们假设我有一个人和一个国家的模式 在执行常规搜索时,我希望获取所有国家/地区名称与搜索字符串匹配的人。为了实现这一点,我在人员索引中添加了一个国家名称索引。到目前为止一切顺利 当搜索填充我的“自动完成”下拉列表时,我希望显示与我的搜索字符串匹配的所有国家和所有人。问题就在这里出现了。在进行应用程序范围的搜索时,我现在得到: 名称

我正在使用Thinking Sphinx以两种不同的模式进行搜索:

  • 在单个型号上进行完整搜索,以实现正常搜索功能
  • 在所有型号中全面搜索自动完成下拉功能
  • 为了这个问题,让我们假设我有一个人和一个国家的模式

    在执行常规搜索时,我希望获取所有国家/地区名称与搜索字符串匹配的人。为了实现这一点,我在人员索引中添加了一个国家名称索引。到目前为止一切顺利

    当搜索填充我的“自动完成”下拉列表时,我希望显示与我的搜索字符串匹配的所有国家和所有人。问题就在这里出现了。在进行应用程序范围的搜索时,我现在得到:

  • 名称与我的搜索字符串匹配的所有国家/地区
  • 所有名字和我的搜索字符串匹配的医生,不幸的是
  • 属于与搜索字符串匹配的国家的所有医生

  • 最后一部分为用户提供了一些令人困惑的自动完成结果。有没有什么简单的方法可以通过使用内置功能来避免这种情况,例如在Person模型上有两个索引,并选择用于每种搜索的索引?

    我认为您的模型如下所示:

    class Person < ActiveRecord::Base
      belongs_to :country
      define_index
        indexes :name
        indexes country(:name), :as => country_name
      end
    end
    
    class Country < ActiveRecord::Base
      has_many :people # has_many :persons # depending on your singular/plural case
      define_index
        indexes :name
      end
    end
    
    但是,如果要在一个模型上创建多个索引,可以像下面的示例那样进行:

    class Person < ActiveRecord::Base
      belongs_to :country
      define_index :my_first_in do
        indexes :name
        indexes country(:name)
      end
      define_index :my_second_in do
        indexes :name
      end
    end
    
    class-Person
    我认为您的模型如下所示:

    class Person < ActiveRecord::Base
      belongs_to :country
      define_index
        indexes :name
        indexes country(:name), :as => country_name
      end
    end
    
    class Country < ActiveRecord::Base
      has_many :people # has_many :persons # depending on your singular/plural case
      define_index
        indexes :name
      end
    end
    
    但是,如果要在一个模型上创建多个索引,可以像下面的示例那样进行:

    class Person < ActiveRecord::Base
      belongs_to :country
      define_index :my_first_in do
        indexes :name
        indexes country(:name)
      end
      define_index :my_second_in do
        indexes :name
      end
    end
    
    class-Person
    以上答案的sphinx v3语法:

    ThinkingSphinx::Index.define :country, name: "my_first_in", with: :active_record
      indexes name
    end
    

    以上答案的sphinx v3语法:

    ThinkingSphinx::Index.define :country, name: "my_first_in", with: :active_record
      indexes name
    end
    

    您可以指定Sphinx新版本的版本号吗?这是v3以后的语法您可以指定Sphinx新版本的版本号吗?这是v3以后的语法,仅供遇到此问题但不确定的人使用-此
    define\u index
    语法用于v3之前的Thinking Sphinx版本。仅供参考任何人遇到这个问题都不确定-这个
    define_index
    语法适用于v3之前的Thinking Sphinx版本。