/
mongoid_search.rb
58 lines (43 loc) · 1.53 KB
/
mongoid_search.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# encoding: utf-8
require 'mongoid_search/railtie' if defined?(Rails)
require 'mongoid_search/mongoid_search'
module Mongoid::Search
## Default matching type. Match :any or :all searched keywords
mattr_accessor :match
@@match = :any
## If true, an empty search will return all objects
mattr_accessor :allow_empty_search
@@allow_empty_search = false
## If true, will search with relevance information
mattr_accessor :relevant_search
@@relevant_search = false
## Stem keywords
mattr_accessor :stem_keywords
@@stem_keywords = false
## Words to ignore
mattr_accessor :ignore_list
@@ignore_list = []
## An array of words
# @@ignore_list = %w{ a an to from as }
## Or from a file
# @@ignore_list = YAML.load(File.open(File.dirname(__FILE__) + '/config/ignorelist.yml'))["ignorelist"]
## Search using regex (slower)
mattr_accessor :regex_search
@@regex_search = true
## Regex to search
mattr_accessor :regex
## Match partial words on both sides (slower)
@@regex = Proc.new { |query| /#{query}/ }
## Match partial words on the beginning or in the end (slightly faster)
# @@regex = Proc.new { |query| /ˆ#{query}/ }
# @@regex = Proc.new { |query| /#{query}$/ }
# Ligatures to be replaced
# http://en.wikipedia.org/wiki/Typographic_ligature
mattr_accessor :ligatures
@@ligatures = { "œ"=>"oe", "æ"=>"ae" }
# Minimum word size. Words smaller than it won't be indexed
mattr_accessor :minimum_word_size
@@minimum_word_size = 2
end
require 'mongoid_search/util'
require 'mongoid_search/log'