如何编辑狂欢搜索查询

时间:2015-09-12 08:05:31

标签: ruby-on-rails e-commerce spree

我想编辑狂欢搜索查询,因为它没有返回优化结果。例如,如果我搜索产品名称“产品”,它会搜索名称为“the”或名称为“product”或描述“the”或“product”的所有产品,其结果是产品名称正确“产品”显示在某些位于中间但不在顶部的位置。这是查询

SELECT  DISTINCT "spree_products"."id", spree_products_taxons.position AS alias_0 FROM "spree_products" INNER JOIN "spree_variants" ON "spree_variants"."product_id" = "spree_products"."id" AND "spree_variants"."is_master" = 't' AND "spree_variants"."deleted_at" IS NULL INNER JOIN "spree_prices" ON "spree_prices"."variant_id" = "spree_variants"."id" AND "spree_prices"."deleted_at" IS NULL LEFT OUTER JOIN "spree_products_taxons" ON "spree_products_taxons"."product_id" = "spree_products"."id" WHERE "spree_products"."deleted_at" IS NULL AND ("spree_products".deleted_at IS NULL or "spree_products".deleted_at >= '2015-09-12 17:02:36.804128') AND ("spree_products".available_on <= '2015-09-12 17:02:36.804764') AND "spree_products_taxons"."taxon_id" IN (1, 2, 3, 6, 7, 8, 4, 9, 10, 11, 12, 13, 14, 15) AND (("spree_products"."name" ILIKE '%the%' OR "spree_products"."name" ILIKE '%product%') OR ("spree_products"."description" ILIKE '%the%' OR "spree_products"."description" ILIKE '%product%')) AND (spree_prices.amount IS NOT NULL) AND "spree_prices"."currency" = 'PKR'  ORDER BY spree_products_taxons.position ASC, asc LIMIT 1 OFFSET 0

我需要对此进行优化,以便最相关的产品显示在顶部,我无法找到定义此查询的确切文件或类。

1 个答案:

答案 0 :(得分:0)

Spree使用ransack来创建这些查询。你不会发现它们是直接编码的。代码可能看起来像Spree::Product.ransack(name_cont: "query")