Using an alias as a filter.

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. There's a few things to note here.

    Firstly, if you're defining fields for this, you need to use :conditions instead of :with - :with is 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:

    ThinkingSphinx.search search_term, :start => true, :with => {:sphinx_internal_id => project_id.to_i}, ...
    

    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.

Reply to this discussion Internal reply only staff will see it

Markdown

Attaching KB article:

» »

Read more…

Attach files

Up to 10MB each.

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions