I have a Project model (the parent model) that I need to include in a search with a bunch of children models.
In the project_index I create an alias....
indexes :id, :as => :project_id
and my search
ThinkingSphinx.search("#{ search_term }", :star => true,
:with => { :project_id => project_id },
:classes => [ActionItem, Attachment, Comment, Feature, Bundle,
BundleEvent, Defect, Need, Requirement, Scenario, UseCase,
BusinessObjective, Project, Constraint, ChangeRequest,
TestScenario, Verification, ItServiceImpact, DataEntityImpact,
ProjectStakeholder, ProcessImpact, ProjectRuleBook, ProjectImpact],
:order => 'updated_at DESC', :page => page || 1, :per_page
=> 10).populate
The search doesn't include the project (parent) in the search though. Any idea on what I can do?
#1 Posted by Pat Allan Support staff on 29 Apr, 2014 02:55 AM
There's a few things to note here.
Firstly, if you're defining fields for this, you need to use
:conditionsinstead of:with-:withis for attributes. But, attributes are the better fit for integer matches...However, the primary key actually exists as an internal (from Thinking Sphinx's perspective) attribute, so you don't need to add anything at all to your index:
Such a search will return everything with that primary key though - whether or not they're a project. If you only want projects, then best to only have Project in the :classes option.