Comments (3)
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.
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.
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)
- Index not created since 0.11.0 - 404 Not Found HOT 8
- Upgrading to 0.11.0 produces "The request was not processed in the expected time." repeatedly. HOT 1
- Split and decouple models in integration_spec.rb to their separate files
- Improve test robustness and confidence with end-to-end system tests
- Improve spec style clarity
- Add unit tests for individual methods
- Support and test Sequel properly
- Document multi_search interface in README HOT 1
- Using attribute option with custom primary key will break fetching
- Polymorphic shared indexes HOT 3
- Index-first search HOT 1
- Rename root module to `Meilisearch` instead of `MeiliSearch`
- Refactor `meilisearch.rb`
- Global `ms_without_auto_index` in `Meilisearch`
- MeiliSearch::Rails::MSCleanUpJob 404 error when deleting records HOT 3
- Update Gem dependencies HOT 6
- Error: MeiliSearch::TimeoutError: The request was not processed in the expected time. HOT 29
- Race condition in proximity precision test
- Undefined method `after_destroy_commit' when using with Mongoid HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meilisearch-rails.