pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 470 forks source link

No results found when multiple :classes are specified #553

Closed groe closed 11 years ago

groe commented 11 years ago

In thinking-sphinx 2, the following performed an application-wide search, limited to certain classes:

ThinkingSphinx.search term, :classes => [Article, Comment]

However, in thinking-sphinx 3 there seems to be a problem when multiple classes are specified. Everything works fine when I do not pass the :classes option at all, when I pass :classes => [Article] or :classes => [Comment], but when passing :classes => [Article, Comment] suddenly no results at all are found.

The query log (query term "sampleterm") shows this:

# :classes => [Article]
[article_core] sampleterm @sphinx_internal_class_name (Article)
# :classes => [Comment]
[comment_core] sampleterm @sphinx_internal_class_name (Comment)
# :classes => [Article, Comment]
[article_core`, `comment_core] sampleterm @sphinx_internal_class_name (Article|Comment)

(The same issue occurs with ThinkingSphinx#facets.)

Any ideas on how to resolve that? Am I doing something wrong?

pat commented 11 years ago

I'm not sure what's happening here - I just added a test for this scenario (see e3d99301b2072aa4724bacef7bdcc317ba47e3cf), and it's working fine on my machine. What version of Sphinx are you using?

groe commented 11 years ago

I am using Sphinx 2.0.8-id64-release (r3831).

Well, that's strange. I will try to come up with a minimal setup to reproduce the issue (with my class/index config).

Btw, Is there any comfortable way to run a extended query directly on sphinx (bypassing thinking-sphinx) in order to isolate the issue? The command-line tool search seems to work only when no query at is passed (i.e. listing all records) - the sphinx forums say it's broken.

pat commented 11 years ago

I usually connect via the mysql CLI tool: mysql --host 127.0.0.1 --port 9306 (the host option is usually required, otherwise it defaults to connecting via a Unix socket instead, ignoring the port option).

pat commented 11 years ago

Also: just updated to 2.0.8 on my machine (was using 2.0.6), but there's no difference - test still passes. Even a simple test app would be great, if you have the time.

groe commented 11 years ago

Thanks for your hint on the mysql client - I did not know sphinx is compatible to that, nice!

I have built a test app to reproduce the issue and noticed that it is related to my thinking-sphinx config. Without a config file config/thinking_sphinx.yml everything works as expected. When I add my config file with ngram-settings to the mix, the problem occurs.

Steps to reproduce the issue with the test app:

git clone https://github.com/groe/ts553.git
mysql -u root -p < db_setup.sql # create mysql DB and grant privileges
rake db:schema:load
rake db:seed
rake ts:rebuild
rake ts553:test

The result is:

All articles: 5
All books: 5
All articles & books: 0

Now remove the config file config/thinking_sphinx.yml or remove/comment both of the ngram-settings. After that (and doing a rake ts:rebuild), everything works as expected:

All articles: 5
All books: 5
All articles & books: 10

These ngram-settings have been working with thinking-sphinx 2. Are they still supported in version 3?

Let me know if I can provide you with any further information. Your help is highly appreciated!

pat commented 11 years ago

I'm not super familiar with ngram settings, but I don't think you need non-CJK characters covered by ngramchars? If I keep both settings, but remove `0..9, A..Z->a..z, , a..z` from the list, the test passes.

pat commented 11 years ago

Also: really appreciate the test app :)

groe commented 11 years ago

That's strange. This has been working previously without any problems.

In fact the application I am working on deals with wylie transliterations as well as CJK texts. I will check if it makes sense to exclude the non-CJK characters for wylie.

Anyway, non-CJK characters in ngram_chars should work, right? So this might be a problem with sphinx itself?

Thanks a lot for your help, pat!

pat commented 11 years ago

I'm not sure if it should work, or even if non-CJK-ish characters should go in the ngram_chars setting. Perhaps worth asking on the Sphinx forum? Better chance of someone familiar with that there :)

steveyken commented 11 years ago

This discussion just saved me a lot of time! Thanks to you both + :100: