I have a rails app with thinking_sphinx successfully working for indexing/searching. I was, however, wondering if there was a way to get partial work matches to search. Meaning if I have a report with title "Best Report" and I searched "Best" it would return that report.
Asked
Active
Viewed 501 times
2 Answers
2
i suggest you to try the Wildcard search with Thinking Sphinx.
There are basically three settings that rule the wildcard search world: * enable_star * min_prefix_len * min_infix_len
- min_prefix_len => Minimum word prefix length to index
- min_infix_len => Infix indexing allows to implement wildcard searching by 'start*','*end', and 'middle' wildcards
Note: *enabled_star is required plus one of the other two for settings for enabling either prefix or infix search (can't have both, at least on the same index)*
For Example :
Model :
class Comment < ActiveRecord::Base
#define the indexes for your searchable attributes
define_index do
indexes :comment
enable_star: true
min_infix_len: 3
has created_at,updated_at
end
end
Controller :
class CommentsController < ApplicationController
def search
@result = ThinkingSphinx.search "*#{params[:id]}*" ,:classes => [Comment,....]
end
end
Then Rebuild the thinking_sphinx :
- rake ts:stop
- rake ts:index
- rake ts:start
(or)
- rake ts:rebuild
the above example will result following instances :
Comment.search "Best*"
Comment.search "Best Rep* "
Comment.search "Rep " .. etc
If any queries feel free, please ask me .......

Balachandar1887229
- 456
- 4
- 7
1
I'm not sure, but it working this way by default, however you can look into match modes here http://freelancing-god.github.com/ts/en/searching.html

Mikhail Nikalyukin
- 11,867
- 1
- 46
- 70