简体   繁体   中英

Rails thinking_sphinx fuzzy search problem

I'm trying to set up thinking_sphinx for an auto-suggestion search field. On each keypress I do a sphinx search on my database of the current text value in the field. I set min_infix_len to 3, I don't want suggestions to start appearing until at least 3 characters are typed. The problem comes with multiple-word queries. Despite setting :match_mode => :phrase, each new word I type is apparently treated as a separate keyword in the sphinx search, having to abide to the min_infix_len of 3.

So if I'm typing "Lorem Ipsum", I get auto-suggestions for "Lor", "Lore", and "Lorem". Then I get no results for "Lorem I" and "Lorem Ip". Then once I hit "Lorem Ips" I get results again.

What's the deal? If this isn't what :match_mode => :phrase is for, then what is it for?

You could extend the String class by this method which converts a string of one or more words to a star-searchable string

def to_star_search
  "*#{self.strip.gsub(/ +/, '* *')}*"
end

I'm pretty certain min_infix_len is only has an impact when indexing data in Sphinx. It doesn't apply at all when searching. So: min_infix_len applies for each word, not for phrases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM