-
-
Save jpemberthy/8257e7c4e512aa8a45df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's say I have the following user. | |
user = User.create(:company_name => "The cheappo restaurant") | |
# And the following User finder that works with `starting_with`. | |
def self.find_all_by_indexed_company_name(term) | |
Sunspot.search(self) do |q| | |
q.text_fields { with(:company_name).starting_with(term) } | |
end.results | |
end | |
# Now let's try some queries | |
User.find_all_by_indexed_company_name("the") | |
=> user | |
User.find_all_by_indexed_company_name("the ch") | |
=> user | |
# Now if I search for "estaurant" | |
User.find_all_by_indexed_company_name("estaurant") | |
=> [] | |
# This is why I say `starting_with` partially works for me, | |
# I would like to have an indexed search using something like `LIKE`: | |
User.find(:all, :conditions => ["company_name LIKE ?", "%estaurant%"]) | |
=> user | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment