Reputation: 2103
I'm using ThinkingSphinx for a simple searching which goes through Book model. my book_indexes.rb looks like this:
ThinkingSphinx::Index.define :book, with: :active_record do
indexes title
indexes author
indexes publishing_date
indexes isbn
end
and controller action looks like this
def index
@books = Book.search(params[:search])
end
so far everything works as it is supposed, when i type "bible" it returns Book titled "Bible". But is it possible to get search result which are not based eg on a whole title? In more simple words i would like to get "bible" whenever i search for "bib" or "b".
EDIT
my thinking_sphinx.yml is now:
development:
enable_star: true
min_infix_len: 1
min_prefix_len: 1
and controller action:
@books = Book.search("*#{params[:search]}*")
but it still works just the same, only without any query, just after loading the page, @books is nil
Upvotes: 0
Views: 48
Reputation: 1717
You're looking for the min_infix_len property. You can set your thinking_sphinx.yml
configuration settings like this:
development:
#.... truncated ....
enable_star: true # Allow wildcard searching
min_infix_len: 3 # Indexes on values starting at 3 letters like "bib"
Upvotes: 1
Reputation: 8954
Thinking Sphinx allows you to use wildcards so when you search like this instead:
@books = Book.search("*#{params[:search]}*")
It will also work when you dont use the whole word!
Upvotes: 0