-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support embedded documents #9
Comments
abhishiv - did you ever figure this out? Im having the same dilema.. |
+1 and ready to help out |
I've tried this and it worked to search for documents with embedded certain field values. Say you have company with embedded departments, and you want to search for companies with certain department names. searchable do Your regular index...text :company_departments def company_departments Hope that helps. |
@basharabdullah, while that works, It hardly scales. I will create a lot of duplication if your embedded documents have many fields. And needs quite some cruft in cases where embedded documents are optional (a user may have 0 to n jobs). |
@berkes could you elaborate that, to be honest, I've been doing it like @basharabdullah for a while now, but with considerably few documents and only a handful of users. (this particular application does not need to scale, it's just used internally, but nevertheless i'm interested in a 'good'/scaling solution. |
I took @basharabdullah's concept and made it a little more DRY: My users can have zero or one drupal_profiles. Profiles should only be indexed (and searchable) once they are available and authorized. They contain many fields, two of which are illustrated below: a string and a list of items (Array). searchable do
text :drupal_username do
drupal_profile_value(:drupal_username) do |field|
field.to_s
end
end
text :drupal_projects do
drupal_profile_value(:projects) do |field|
field.values.join(", ")
end
end
end
# ....
private
def drupal_profile_value(field)
if (self.drupal_profile) && self.drupal_profile.authorized?)
if self.drupal_profile.fields.include?(field.to_s)
value = yield self.drupal_profile[field]
end
end
value
end I am no Rails expert, so this could probably be refactored and cleaned even further, but the idea is that I call drupal_profile_value, and pass it a block that allows me to modify, change or return the value of the embedded field. IMHO this still is not as ideal as a clean DSL that supports embedded documents, say text "drupal_profile.drupal_username"
text "drupal_profile.drupal_projects" do
drupal_profile.drupal_projects.values.join(", ")
end EDIT: @cice: with scaling I meant scaling towards more fields, more types of embedded documents and so on. I have a model with 7 types of embedded documents, that have a total of 160 fields. This means that I have to define ~160 methods in the parent model to index all the fields. Fields that are defined elsewhere. |
@berkes right you are, but it's the best solution I found. Thanks for providing more solid solution. |
I am having an hard time figuring out how to make this gem work with embedded documents. Any pointers?
Thanks a ton & great work!
The text was updated successfully, but these errors were encountered: