Answered on Stack Overflow, but copied here:

What you're facing is a scenario that only occurs when you have the inheritance 
column (which is named type by default) in your model (whether or not you're 
using it for STI - Thinking Sphinx can't figure that out).

To allow for querying across certain subclasses of the STI hierarchy, Thinking 
Sphinx adds a field called sphinx_internal_class_name which is used to limit 
search results to certain models. In your case, it would contain 
'PracticeTestResult' - hence, ti and p return all objects.

The workaround, as you've found, is to limit your queries to specific fields.

It's also worth noting that in earlier versions of TS v3.0.x, this internal 
field was always present. Given it's only useful when STI is in play, it now 
doesn't get added unless necessary.


Cheers

— 
Pat

On 22 May 2014, at 6:27 am, Prakash Murthy <[email protected]> wrote:

> Hi 
> 
> I have a model practice_test_result for which I have defined the index as 
> follows:
> 
> ThinkingSphinx::Index.define :practice_test_result, with: :active_record, 
> delta: true do
>   indexes [student.first_name, student.last_name], :as => :student_name
> 
>   set_property :min_infix_len => 1
> end
> Searching for test results returns unexpected results in some cases listed 
> below:
> 
> > PracticeTestResult.search('x').map{|x| x.student.name }                     
> >                         
>  => []
> This is as per expectation, as none of the student names have 'x' in it.
> 
> > PracticeTestResult.search('p').map{|x| x.student.name } 
>  => ["Jane Doe", "Jane Doe", "David Doe", "Timothy Doe", "Jane Doe"]
> This is not expected, as none of the student names have 'p' in it.
> 
> > PracticeTestResult.search('ti').map{|x| x.student.name }
>  => ["Jane Doe", "Jane Doe", "David Doe", "Timothy Doe", "Jane Doe"]
> Again not as per expectation; should have only one value Timothy Doe returned.
> 
> > PracticeTestResult.search('tim').map{|x| x.student.name }
>  => ["Timothy Doe"]
> Works as expected.
> 
> Any suggestion on how to debug this? Could this be because min_infix_len is 
> set too low at 1?
> 
> Sphinx version : Sphinx 2.1.7-release (rel21-r4638)
> 
> Thinking-Sphinx version : 3.1.1
> 
> Database : MySql
> 
> Rails version: 3.2.13
> 
> Posted the same question on Stack Overflow as well: 
> http://stackoverflow.com/questions/23792862/thinking-sphinx-returning-results-that-dont-fit-the-criteria
> 
> 
> 
> Thanks,
> 
> Prakash
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to