Giter Club home page Giter Club logo

Comments (3)

ellnix avatar ellnix commented on June 2, 2024 2

Now, i can search by Question.search() and it will query both models right?

I have to apologize, I thought you could but it turns out that is not what the gem does. Please use this as a temporary fix (replace QUERY_HERE with the search query):

Question.index.search(QUERY_HERE)['hits'].map do |result|
  klass, id = result['ms_id'].split('_')
  case klass
  when 'question'
    Question.find(id)
  when 'answer'
    Answer.find(id)
  end
end

I have to make some proposals to make the straightforward Question.search work.

from meilisearch-rails.

ellnix avatar ellnix commented on June 2, 2024

Please only call meilisearch once in models and append the block to that one call:

class Answer < ApplicationRecord
  include MeiliSearch::Rails
  belongs_to :question

  meilisearch index_uid: "Discussion", primary_key: :ms_id do
    attribute :title
    attribute :body
  end

  def ms_id
    "answer_#{primary_key}"
  end
end
class Question < ApplicationRecord
  include MeiliSearch::Rails
  has_many :answers
  
  meilisearch index_uid: "Discussion", primary_key: :ms_id do
    attribute :title
    attribute :body
  end

   def ms_id
    "question_#{primary_key}"
  end
end

I believe the second call to meilisearch was overwriting the first. Please let me know if this fixes it 😄.

from meilisearch-rails.

botbotbotbotboot avatar botbotbotbotboot commented on June 2, 2024
class Question < ApplicationRecord
  include MeiliSearch::Rails
  has_many :answers

  meilisearch index_uid: "Discussion", primary_key: :ms_id do
    attribute :title
    attribute :body
  end

   def ms_id
    "question_#{id}"
  end
end

Ok this worked!. Thank you.

Now, i can search by Question.search() and it will query both models right?

from meilisearch-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.