Skip to content
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

Closed
sveredyuk opened this issue Dec 19, 2016 · 10 comments · Fixed by #108
Closed

Config search to not ignore dots #106

sveredyuk opened this issue Dec 19, 2016 · 10 comments · Fixed by #108
Labels

Comments

@sveredyuk
Copy link
Collaborator

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 ?

@dblock
Copy link
Contributor

dblock commented Dec 19, 2016

Probably a bug, feel free to PR.

@dblock dblock added the Bug label Dec 19, 2016
@sveredyuk
Copy link
Collaborator Author

@dblock https://github.com/mongoid/mongoid_search/blob/master/lib/mongoid_search/util.rb#L44
Seems strip just ignored some symbols, what about to make this configurable ?

@Loschcode
Copy link
Collaborator

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 ?

@sveredyuk
Copy link
Collaborator Author

@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

@Loschcode
Copy link
Collaborator

@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.

@Loschcode
Copy link
Collaborator

Pull request #110

@sveredyuk
Copy link
Collaborator Author

my pr is waiting more than half a year - #108

@Loschcode
Copy link
Collaborator

I've the feeling we will both wait for a while then, ouch

@dblock
Copy link
Contributor

dblock commented Oct 10, 2017

We need more maintainers for this repo, @sveredyuk @Loschcode you guys volunteer?

@mauriciozaffari is the sole owner of this right now, ping?

@dblock
Copy link
Contributor

dblock commented Oct 10, 2017

I opened #111 to discuss ownership.

@rtrv rtrv closed this as completed in #108 Oct 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants