-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config search to not ignore dots #106
Comments
Probably a bug, feel free to PR. |
@dblock https://github.com/mongoid/mongoid_search/blob/master/lib/mongoid_search/util.rb#L44 |
I've the same issue with dates like 2017-08-10 which are considered "2017", "08", "10" while it's supposed to be a complete date search. @sveredyuk have you fixed this issue on your own ? |
@Loschcode Yeah, I have to monkey-patch this gem) # Mogoid::Search Overwrite
module Mongoid::Search::Util
def self.normalize_keywords(text)
ligatures = Mongoid::Search.ligatures
ignore_list = Mongoid::Search.ignore_list
stem_keywords = Mongoid::Search.stem_keywords
stem_proc = Mongoid::Search.stem_proc
return [] if text.blank?
text = text.to_s.
mb_chars.
normalize(:kd).
downcase.
to_s.
gsub(/[_:;'\"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/, ' '). # strip symbols
gsub(/[#{ligatures.keys.join("")}]/) {|c| ligatures[c]}.
split(' ').
reject { |word| word.size < Mongoid::Search.minimum_word_size }
text = text.reject { |word| ignore_list.include?(word) } unless ignore_list.blank?
text = text.map(&stem_proc) if stem_keywords
text
end
end
module Mongoid::Search
def set_keywords
self._keywords = Mongoid::Search::Util.keywords(self, self.search_fields)
.flatten
.reject{|k| k.nil? || k.empty?}
.push(*self.search_fields)
.flatten.map(&:to_s).uniq.sort
end
end |
@sveredyuk I actually didn't expect any answer so I went forward and made a fork earlier today ; to add a configuration option and slightly change the structure of what you kinda monkey patched on your end. Thanks for your solution though ;) https://github.com/Loschcode/mongoid_search I'll make a pull request, might not suit everyone but it works in production for me. |
Pull request #110 |
my pr is waiting more than half a year - #108 |
I've the feeling we will both wait for a while then, ouch |
We need more maintainers for this repo, @sveredyuk @Loschcode you guys volunteer? @mauriciozaffari is the sole owner of this right now, ping? |
I opened #111 to discuss ownership. |
I have field with ip address like '10.0.10.0' and Mongoid::Search create one keyword only '10'. How to tune search to ignore dots ?
The text was updated successfully, but these errors were encountered: