首页 \ 问答 \ 思考Sphinx没有将相关数据索引到搜索到的模型(Thinking Sphinx not indexing associated data to model searched by)

思考Sphinx没有将相关数据索引到搜索到的模型(Thinking Sphinx not indexing associated data to model searched by)

在我的Product.rb中

 define_index do
     indexes :name, :sortable => true
     indexes brand

     has :id, kosher_id, gluten_free_id, lactose_free_id
     has stores(:id),        :as => 'store_ids'
     has locations(:id),     :as => 'location_ids'
     has categories(:id),    :as => 'category_ids'
     has kosher(:passover),  :as => 'kosher_passover'
   end

在我的搜索课中

  def self.for_locations_by_query(query, options = {})
     query, categories = @@coder.decode(query).gsub(/(\b\w+\b)/, "+\\0"), @@coder.decode(options.delete(:categories))
     origin, page = @@coder.decode(options.delete(:origin)), @@coder.decode(options.delete(:page))
     per_page, sort_order = @@coder.decode(options.delete(:per_page)), @@coder.decode(options.delete(:sort_order))
     distance, classifications = @@coder.decode(options.delete(:distance)), @@coder.decode(options.delete(:classifications))

     with                        = {}
     with[:store_ids]            = Location.all(:origin => origin, :within => distance).collect(&:store_id).uniq unless origin.blank? or distance.blank?
     with[:category_ids]         = categories.split(',') unless categories.blank?

     without                     = {}
     without[:kosher_id]         = 0 if classifications.split(',').include? 'kosher'
     without[:gluten_free_id]    = 0 if classifications.split(',').include? 'gluten_free'
     without[:lactose_free_id]   = 0 if classifications.split(',').include? 'lactose_free'
     without[:kosher_passover]   = 0 if classifications.split(',').include? 'kosher_passover'

     products  = Product.search(query, :with => with, :without => without, :per_page => 20, :page => 1)
     stores    = products.collect { |p| p.stores }.flatten.uniq
     locations = stores.collect { |s| s.locations.find(:all, :origin => origin, :within => distance) }.flatten.uniq
     locations.sort_by_distance_from(origin)
     locations.each { |l| l.dist = l.distance }

     locations = locations.paginate(:page => page, :per_page => per_page)

     return { :total_entries => locations.total_entries, :size => locations.size, :locations => locations }
    end

* .sphinx.conf文件 - 产品型号

source product_core_0
{
  type = mysql
  sql_host = [FILTERED]
  sql_user = [FILTERED]
  sql_pass = [FILTERED]
  sql_db = [FILTERED]
  sql_sock = /var/run/mysqld/mysqld.sock
  sql_query_pre = SET NAMES utf8
  sql_query_pre = SET TIME_ZONE = '+0:00'
  sql_query = SELECT SQL_NO_CACHE `products`.`id` * 3 + 1 AS `id` , `products`.`name` AS `name`, `products`.`brand` AS `brand`, `products`.`id` AS `sphinx_internal_id`, 485965105 AS `class_crc`, 0 AS `sphinx_deleted`, IFNULL(`products`.`name`, '') AS `name_sort`, `products`.`id` AS `id`, `products`.`kosher_id` AS `kosher_id`, `products`.`gluten_free_id` AS `gluten_free_id`, `products`.`lactose_free_id` AS `lactose_free_id`, GROUP_CONCAT(DISTINCT IFNULL(`stores`.`id`, '0') SEPARATOR ',') AS `store_ids`, GROUP_CONCAT(DISTINCT IFNULL(`locations`.`id`, '0') SEPARATOR ',') AS `location_ids`, GROUP_CONCAT(DISTINCT IFNULL(`categories`.`id`, '0') SEPARATOR ',') AS `category_ids`, `koshers`.`passover` AS `kosher_passover` FROM `products`    LEFT OUTER JOIN `product_stores` ON (`products`.`id` = `product_stores`.`product_id`)  LEFT OUTER JOIN `stores` ON (`stores`.`id` = `product_stores`.`store_id`)   LEFT OUTER JOIN `product_locations` ON (`products`.`id` = `product_locations`.`product_id`)  LEFT OUTER JOIN `locations` ON (`locations`.`id` = `product_locations`.`location_id`)   LEFT OUTER JOIN `category_products` ON (`products`.`id` = `category_products`.`product_id`)  LEFT OUTER JOIN `categories` ON (`categories`.`id` = `category_products`.`category_id`)   LEFT OUTER JOIN `koshers` ON `koshers`.id = `products`.kosher_id  WHERE `products`.`id` >= $start AND `products`.`id` <= $end GROUP BY `products`.`id`  ORDER BY NULL
  sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `products` 
  sql_attr_uint = sphinx_internal_id
  sql_attr_uint = class_crc
  sql_attr_uint = sphinx_deleted
  sql_attr_uint = id
  sql_attr_uint = kosher_id
  sql_attr_uint = gluten_free_id
  sql_attr_uint = lactose_free_id
  sql_attr_bool = kosher_passover
  sql_attr_str2ordinal = name_sort
  sql_attr_multi = uint store_ids from field
  sql_attr_multi = uint location_ids from field
  sql_attr_multi = uint category_ids from field
  sql_query_info = SELECT * FROM `products` WHERE `id` = (($id - 1) / 3)
}

index product_core
{
  source = product_core_0
  path = [FILTERED]/releases/20101008215652/db/sphinx/staging/product_core
  charset_type = utf-8
}

index product
{
  type = distributed
  local = product_core
}

有问题的行是with[:store_ids] = ...产品可以与多个商店ID相关联,但是如果编号最小的IDwith[:store_ids]的数组中,它似乎只能起作用。 例如,与产品1000相关联的ID为[12,15,41] ,如果with[:store_ids] = [15,41]则返回0结果,但是如果12在数组中则可以工作。

我已停止,启动,重新启动,重新编制索引,重建,为sphinx生成一个新的conf文件,并以各种顺序重复,我没有运气。


In my Product.rb

 define_index do
     indexes :name, :sortable => true
     indexes brand

     has :id, kosher_id, gluten_free_id, lactose_free_id
     has stores(:id),        :as => 'store_ids'
     has locations(:id),     :as => 'location_ids'
     has categories(:id),    :as => 'category_ids'
     has kosher(:passover),  :as => 'kosher_passover'
   end

In my Searching Class

  def self.for_locations_by_query(query, options = {})
     query, categories = @@coder.decode(query).gsub(/(\b\w+\b)/, "+\\0"), @@coder.decode(options.delete(:categories))
     origin, page = @@coder.decode(options.delete(:origin)), @@coder.decode(options.delete(:page))
     per_page, sort_order = @@coder.decode(options.delete(:per_page)), @@coder.decode(options.delete(:sort_order))
     distance, classifications = @@coder.decode(options.delete(:distance)), @@coder.decode(options.delete(:classifications))

     with                        = {}
     with[:store_ids]            = Location.all(:origin => origin, :within => distance).collect(&:store_id).uniq unless origin.blank? or distance.blank?
     with[:category_ids]         = categories.split(',') unless categories.blank?

     without                     = {}
     without[:kosher_id]         = 0 if classifications.split(',').include? 'kosher'
     without[:gluten_free_id]    = 0 if classifications.split(',').include? 'gluten_free'
     without[:lactose_free_id]   = 0 if classifications.split(',').include? 'lactose_free'
     without[:kosher_passover]   = 0 if classifications.split(',').include? 'kosher_passover'

     products  = Product.search(query, :with => with, :without => without, :per_page => 20, :page => 1)
     stores    = products.collect { |p| p.stores }.flatten.uniq
     locations = stores.collect { |s| s.locations.find(:all, :origin => origin, :within => distance) }.flatten.uniq
     locations.sort_by_distance_from(origin)
     locations.each { |l| l.dist = l.distance }

     locations = locations.paginate(:page => page, :per_page => per_page)

     return { :total_entries => locations.total_entries, :size => locations.size, :locations => locations }
    end

*.sphinx.conf file - product model

source product_core_0
{
  type = mysql
  sql_host = [FILTERED]
  sql_user = [FILTERED]
  sql_pass = [FILTERED]
  sql_db = [FILTERED]
  sql_sock = /var/run/mysqld/mysqld.sock
  sql_query_pre = SET NAMES utf8
  sql_query_pre = SET TIME_ZONE = '+0:00'
  sql_query = SELECT SQL_NO_CACHE `products`.`id` * 3 + 1 AS `id` , `products`.`name` AS `name`, `products`.`brand` AS `brand`, `products`.`id` AS `sphinx_internal_id`, 485965105 AS `class_crc`, 0 AS `sphinx_deleted`, IFNULL(`products`.`name`, '') AS `name_sort`, `products`.`id` AS `id`, `products`.`kosher_id` AS `kosher_id`, `products`.`gluten_free_id` AS `gluten_free_id`, `products`.`lactose_free_id` AS `lactose_free_id`, GROUP_CONCAT(DISTINCT IFNULL(`stores`.`id`, '0') SEPARATOR ',') AS `store_ids`, GROUP_CONCAT(DISTINCT IFNULL(`locations`.`id`, '0') SEPARATOR ',') AS `location_ids`, GROUP_CONCAT(DISTINCT IFNULL(`categories`.`id`, '0') SEPARATOR ',') AS `category_ids`, `koshers`.`passover` AS `kosher_passover` FROM `products`    LEFT OUTER JOIN `product_stores` ON (`products`.`id` = `product_stores`.`product_id`)  LEFT OUTER JOIN `stores` ON (`stores`.`id` = `product_stores`.`store_id`)   LEFT OUTER JOIN `product_locations` ON (`products`.`id` = `product_locations`.`product_id`)  LEFT OUTER JOIN `locations` ON (`locations`.`id` = `product_locations`.`location_id`)   LEFT OUTER JOIN `category_products` ON (`products`.`id` = `category_products`.`product_id`)  LEFT OUTER JOIN `categories` ON (`categories`.`id` = `category_products`.`category_id`)   LEFT OUTER JOIN `koshers` ON `koshers`.id = `products`.kosher_id  WHERE `products`.`id` >= $start AND `products`.`id` <= $end GROUP BY `products`.`id`  ORDER BY NULL
  sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `products` 
  sql_attr_uint = sphinx_internal_id
  sql_attr_uint = class_crc
  sql_attr_uint = sphinx_deleted
  sql_attr_uint = id
  sql_attr_uint = kosher_id
  sql_attr_uint = gluten_free_id
  sql_attr_uint = lactose_free_id
  sql_attr_bool = kosher_passover
  sql_attr_str2ordinal = name_sort
  sql_attr_multi = uint store_ids from field
  sql_attr_multi = uint location_ids from field
  sql_attr_multi = uint category_ids from field
  sql_query_info = SELECT * FROM `products` WHERE `id` = (($id - 1) / 3)
}

index product_core
{
  source = product_core_0
  path = [FILTERED]/releases/20101008215652/db/sphinx/staging/product_core
  charset_type = utf-8
}

index product
{
  type = distributed
  local = product_core
}

The problematic line is with[:store_ids] = ... The product can be associated to multiple store ids, however it only seems to work if the lowest numbered ID is in the array for with[:store_ids]. For example, the ids associated with product 1000 are [12,15,41], if with[:store_ids] = [15,41] then 0 results are returned, however if 12 is in the array then it works.

I have stopped, started, restarted, reindexed, rebuilt, generated a new conf file for sphinx, and repeated in various orders and I have had no luck.


原文:https://stackoverflow.com/questions/3935978
更新时间:2022-05-13 13:05

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)