mongoid_search 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6551ebbcf9e4da8d5ef2bd51036aa3580e7c4023043d228ce88cb8069c8bba31
4
- data.tar.gz: a1b040501713dbb5d7f874dadeb2a05cc5a0af3f80dc89b4b8b387afa02abb1f
3
+ metadata.gz: 057244f829816a389f10496ce6c9377899f345d1ff85f5859a272e967598d7e6
4
+ data.tar.gz: c84d8de65fdbf2396e6835b9e4ea1d8539b5085477630461b6048ecb15e63444
5
5
  SHA512:
6
- metadata.gz: e24c0139031664d6616db5ba52338850d0cb4b2fbb9e82920a8db4e0cfb87b1cc0dabb9ba4bf17e78699143682f2055bdd5ac9acc9ed9d475decb73d76b06129
7
- data.tar.gz: f4a234e8c235fa037362715e405e9dc45ea85d18e5de54274b8525e3f5cb9173d6d230696ff7b2031e0f4bcd58bfeaa75a9456a69f00d47088f50bb15f211019
6
+ metadata.gz: 1320708342eecd41bc9b59fd97e8a328e63a8519565977bb8ab1999f58f9c9d267ce9361e1fee579fb0d5c6d551d98e258e73082116ea95744dc483c4b82751c
7
+ data.tar.gz: 79ca0c460deaf226ce087ad8eaa807ef44fe4f56e558eaec0ec92d1af973abc4cf5393309e0a751203372516e3083dd3869ab914f3c6ca19a55794d1c88fa04e
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  Mongoid Search is a simple full text search implementation for Mongoid ORM. It supports Mongoid 6, 7, and 8 and performs well for small data sets. If your searchable model is big (i.e. 1.000.000+ records), [mongoid_fulltext](https://github.com/mongoid/mongoid_fulltext), ElasticSearch, Solr or Sphinx may suit you better.
4
4
 
5
- [![Test](https://github.com/mongoid/mongoid_search/actions/workflows/test.yml/badge.svg)](https://github.com/mongoid/mongoid_search/actions/workflows/test.yml)
5
+ [![Test](https://github.com/mongoid/mongoid_search/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mongoid/mongoid_search/actions/workflows/test.yml?query=branch%3Amaster) [![Coverage Status](https://coveralls.io/repos/github/mongoid/mongoid_search/badge.svg?branch=master)](https://coveralls.io/github/mongoid/mongoid_search?branch=master)
6
+
7
+ CI collects SimpleCov coverage on Ruby 3.4 with Mongoid 9 and MongoDB 8.0 and submits one report to Coveralls using GitHub's workflow token. To generate a local report, run `COVERAGE=true MONGOID_VERSION=9 bundle install` followed by `COVERAGE=true MONGOID_VERSION=9 bundle exec rspec`. Reports are written to `coverage/`.
6
8
 
7
9
  ## Installation
8
10
 
@@ -14,7 +16,7 @@ gem 'mongoid_search'
14
16
 
15
17
  Then:
16
18
 
17
- ```
19
+ ```sh
18
20
  bundle install
19
21
  ```
20
22
 
@@ -24,6 +26,7 @@ bundle install
24
26
  class Product
25
27
  include Mongoid::Document
26
28
  include Mongoid::Search
29
+
27
30
  field :brand
28
31
  field :name
29
32
  field :unit
@@ -38,6 +41,7 @@ end
38
41
 
39
42
  class Tag
40
43
  include Mongoid::Document
44
+
41
45
  field :name
42
46
 
43
47
  belongs_to :product
@@ -45,6 +49,7 @@ end
45
49
 
46
50
  class Category
47
51
  include Mongoid::Document
52
+
48
53
  field :name
49
54
 
50
55
  has_many :products
@@ -54,7 +59,8 @@ end
54
59
  Now when you save a product, you get a `_keywords` field automatically:
55
60
 
56
61
  ```ruby
57
- p = Product.new brand: 'Apple', name: 'iPhone', unit: 'kilogram', info: { summary: 'Info-summary', description: 'Info-description' }
62
+ p = Product.new brand: 'Apple', name: 'iPhone', unit: 'kilogram',
63
+ info: { summary: 'Info-summary', description: 'Info-description' }
58
64
  p.tags << Tag.new(name: 'Amazing')
59
65
  p.tags << Tag.new(name: 'Awesome')
60
66
  p.tags << Tag.new(name: 'Superb')
@@ -69,30 +75,31 @@ p._unit_keywords
69
75
  Now you can run search, which will look in the `_keywords` field and return all matching results:
70
76
 
71
77
  ```ruby
72
- Product.full_text_search("apple iphone").size
78
+ Product.full_text_search('apple iphone').size
73
79
  # => 1
74
80
  ```
75
81
 
76
82
  You can also search in "virtual" fields by defining them as methods. This can be useful when you have a method with dynamic fields (i.e. variable schema).
83
+
77
84
  ```ruby
78
85
  class ModelWithDynamicFields
79
-
80
- ...
81
-
86
+ # ...
87
+
82
88
  search_in :search_data
83
89
 
84
90
  def search_data
85
91
  # concatenate all String fields' values
86
- self.attributes.select{|k,v| v.is_a?(String) }.values.join(' ')
92
+ attributes.select { |k, v| v.is_a?(String) }.values.join(' ')
87
93
  end
88
94
  end
89
95
  ```
96
+
90
97
  Mongoid_search will run the method before save and use it's output to populate the `_keywords` field.
91
98
 
92
99
  Of course, some models could have more than one index. For instance, two different searches with different fields, so you could even specify from which index should be searched:
93
100
 
94
101
  ```ruby
95
- Product.full_text_search("kilogram", index: :_unit_keywords).size
102
+ Product.full_text_search('kilogram', index: :_unit_keywords).size
96
103
  # => 1
97
104
  ```
98
105
 
@@ -111,13 +118,13 @@ category.products.where(:price.lt => 499).full_text_search('iphone').asc(:price)
111
118
 
112
119
  To index or reindex all existing records, run this rake task
113
120
 
114
- ```
115
- $ rake mongoid_search:index
121
+ ```sh
122
+ rake mongoid_search:index
116
123
  ```
117
124
 
118
125
  ## Options
119
126
 
120
- ### match
127
+ ### Match
121
128
 
122
129
  * `:any` - match any occurrence
123
130
  * `:all` - match all occurrences
@@ -132,7 +139,7 @@ Product.full_text_search('apple motorola', match: :all).size
132
139
  # => 0
133
140
  ```
134
141
 
135
- ### allow\_empty\_search
142
+ ### Allow Empty Search
136
143
 
137
144
  * `true` - will return `Model.all`
138
145
  * `false` - will return `[]`
@@ -144,7 +151,7 @@ Product.full_text_search('', allow_empty_search: true).size
144
151
  # => 1
145
152
  ```
146
153
 
147
- ### relevant_search
154
+ ### Relevant Search
148
155
 
149
156
  * `true` - adds relevance information to the results
150
157
  * `false` - no relevance information
@@ -158,7 +165,11 @@ Product.full_text_search('amazing apple', relevant_search: true)
158
165
 
159
166
  Please note that relevant_search will return an Array and not a Criteria object. The search method should always be called in the end of the method chain.
160
167
 
161
- ### index
168
+ Results are ordered by decreasing numeric relevance (the number of matching indexed keywords). This option uses MongoDB map-reduce, which is deprecated upstream and requires server-side JavaScript.
169
+
170
+ Upgrading from an earlier release? See [UPGRADING](UPGRADING.md) for the relevance ordering change in 0.6.0.
171
+
172
+ ### Index
162
173
 
163
174
  Default is `_keywords`.
164
175
 
@@ -209,18 +220,18 @@ Mongoid::Search.setup do |config|
209
220
  ## Regex to search
210
221
 
211
222
  ## Match partial words on both sides (slower)
212
- config.regex = Proc.new { |query| /#{query}/ }
223
+ config.regex = proc { |query| /#{query}/ }
213
224
 
214
225
  ## Match partial words on the beginning or in the end (slightly faster)
215
226
  # config.regex = Proc.new { |query| /^#{query}/ }
216
227
  # config.regex = Proc.new { |query| /#{query}$/ }
217
228
 
218
229
  # Ligatures to be replaced
219
- # http://en.wikipedia.org/wiki/Typographic_ligature
220
- config.ligatures = { "œ"=>"oe", "æ"=>"ae" }
230
+ # https://en.wikipedia.org/wiki/Ligature_(writing)
231
+ config.ligatures = { 'œ' => 'oe', 'æ' => 'ae' }
221
232
 
222
233
  # Strip symbols regex to be replaced. These symbols will be replaced by space
223
- config.strip_symbols = /[._:;'\"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/
234
+ config.strip_symbols = %r{[._:;'"`,?|+={}()!@#%^&*<>~$\-\\/\[\]]}
224
235
 
225
236
  # Strip accents regex to be replaced. These sybols will be removed after strip_symbols replacing
226
237
  config.strip_accents = /[^\s\p{Alnum}]/
data/Rakefile CHANGED
@@ -9,7 +9,27 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
9
9
  spec.pattern = 'spec/**/*_spec.rb'
10
10
  end
11
11
 
12
- require 'rubocop/rake_task'
13
- RuboCop::RakeTask.new(:rubocop)
12
+ lint = RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
13
+ Gem.loaded_specs.key?('rubocop')
14
+ if lint
15
+ require 'rubocop/rake_task'
16
+ RuboCop::RakeTask.new(:rubocop)
14
17
 
15
- task default: %i[rubocop spec]
18
+ desc 'Lint Ruby, Markdown, YAML, and spelling'
19
+ task lint: :rubocop
20
+ end
21
+
22
+ task default: lint ? %i[rubocop spec] : %i[spec]
23
+ require 'bundler/gem_tasks'
24
+
25
+ if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
26
+ Gem.loaded_specs.key?('ruby-gem-release')
27
+ require_relative 'script/release'
28
+ MongoidSearchRelease.workflow.install_tasks
29
+
30
+ %w[release release:rubygem_push release:source_control_push].each do |name|
31
+ Rake::Task[name].clear
32
+ desc 'Disabled; releases run through GitHub Actions, see RELEASING.md'
33
+ task(name) { abort "#{name} is disabled; releases run through GitHub Actions, see RELEASING.md" }
34
+ end
35
+ end
@@ -94,7 +94,7 @@ module Mongoid::Search
94
94
  end
95
95
 
96
96
  def search_relevant(query, options)
97
- results_with_relevance(query, options).sort_by { |o| o['value'] }.map do |r|
97
+ results_with_relevance(query, options).sort_by { |o| -o['value'] }.map do |r|
98
98
  new(r['_id'].merge(relevance: r['value'])) do |o|
99
99
  # Need to match the actual object
100
100
  o.instance_variable_set('@new_record', false)
@@ -124,7 +124,7 @@ module Mongoid::Search
124
124
 
125
125
  reduce = %{
126
126
  function(key, values) {
127
- return(values);
127
+ return Array.sum(values);
128
128
  }
129
129
  }
130
130
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mongoid
4
+ module Search
5
+ VERSION = '0.6.0'
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauricio Zaffari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-02-02 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast-stemmer
@@ -54,6 +54,7 @@ files:
54
54
  - lib/mongoid_search/railtie.rb
55
55
  - lib/mongoid_search/tasks/mongoid_search.rake
56
56
  - lib/mongoid_search/util.rb
57
+ - lib/mongoid_search/version.rb
57
58
  homepage: https://github.com/mongoid/mongoid_search
58
59
  licenses:
59
60
  - MIT
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  - !ruby/object:Gem::Version
75
76
  version: 1.3.6
76
77
  requirements: []
77
- rubygems_version: 3.4.19
78
+ rubygems_version: 3.5.22
78
79
  signing_key:
79
80
  specification_version: 4
80
81
  summary: Search implementation for Mongoid ORM