Searchkick按价格或名称排序会返回错误的结果顺序

时间:2018-04-02 11:14:27

标签: ruby-on-rails elasticsearch spree searchkick

我使用searchkick在我的rails应用程序中搜索和订购产品一切正常,但

---
- hosts: all
  gather_facts: no
  become: yes
  vars_prompt:
    - name: "gituser"
      prompt: "Enter your gitlab ID or username ex: user@XXXX.XXX"
      private: no
    - name: "gitpassword"
      prompt: "Enter your gitlab password"
      private: yes

  tasks:
    - name: Cloning from git 
      git:
        repo: "https://{{ gituser | urlencode }}:{{ gitpassword | urlencode }}@git###.####.###/group/projects.git"
        dest: /usr/share/clonefolder
        clone: yes
        update: yes
        force: yes

以上两种情况都会返回正确的结果但订单不正确

我的价格&名称映射是

search("*", order: { price: {order: :desc}}
// or
search("*", order: { price: :desc})
// name
search("*", order: { name: {order: :desc}}
//or
search("*", order: { name: :desc})

我如何解决这个问题,以便得到正确的结果顺序?!即按价格描述?

1 个答案:

答案 0 :(得分:2)

您可以尝试调试发生了什么:

Model.search("*", order: {price: :desc}, debug: true)

Model.search("*", order: {price: :desc}, explain: true).response

Source

可能是您的搜索索引与数据库不同步。尝试进行完全重新索引(Model.reindex),以查看是否可以解决此问题。