mongodb_meilisearch 1.1.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -0
- data/Gemfile.lock +1 -1
- data/README.md +18 -8
- data/lib/mongodb_meilisearch/version.rb +1 -1
- data/lib/search/client.rb +2 -1
- data/lib/search/instance_methods.rb +9 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff219e5de4c77b4b06515946701f57eee82588691ec7931d963a70011409c79a
|
4
|
+
data.tar.gz: c51b7f234431417abe62fdd5365a106b4d493fe9e49b7802726cdd61a519db48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b21b329983c8ac89de3e8543cccb021e63a7d1411b0cb464885ea3019fe815f7f72de8f408da1bc18d38cc2ebeac929f5491ec643ee3ea5e8a102dde3c582aae
|
7
|
+
data.tar.gz: 4c44d1ae3784917566bd6a1a2bb3993a718fe57d5cf97e7e9af21587a3587fda1d1c77764606ad21dd06b9c8e107eff82e7173d8d019ecd2e18dad46094a19a9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,52 @@
|
|
1
|
+
## [1.2.0] - 2024-06-19
|
2
|
+
|
3
|
+
### Features
|
4
|
+
- The value of `SEARCHABLE_ATTRIBUTES` can now optionally
|
5
|
+
include method names, not just field names.
|
6
|
+
|
7
|
+
This makes for easier incorporation of dynamically generated index values,
|
8
|
+
because it eliminates many cases where you would have had to define
|
9
|
+
a `search_indexable_hash` method. If you already have one, it'll
|
10
|
+
continue to work.
|
11
|
+
|
12
|
+
## [1.1.1] 2023-11-13
|
13
|
+
bug fix
|
14
|
+
|
15
|
+
### Fixes
|
16
|
+
|
17
|
+
Issue #7 - adding the first document from a new model didn't
|
18
|
+
configure the filterable attributes or searchable attributes.
|
19
|
+
The lack of the former would cause basic searches to fail
|
20
|
+
because of our expectation that "object_class" will always
|
21
|
+
be a filterable field unless you've specifically designated
|
22
|
+
your model as unfilterable.
|
23
|
+
|
24
|
+
|
25
|
+
## [1.1.0] - 2023-09-16
|
26
|
+
Sorting & Filtering
|
27
|
+
|
28
|
+
## Additions
|
29
|
+
- adds the ability to specify sortable attributes
|
30
|
+
- these default to match the filterable attributes
|
31
|
+
- filterable attributes still default to match
|
32
|
+
searchable attributes
|
33
|
+
- `set_filterable_attributes`
|
34
|
+
- `set_sortable_attributes`
|
35
|
+
- `set_sortable_attributes!`
|
36
|
+
- `reindex` and `reindex!` now set searchable attributes
|
37
|
+
|
38
|
+
## Fixes
|
39
|
+
- `set_filterable_attributes!` is now synchronous as the name implies
|
40
|
+
- `reindex_core` correctly honors the user's async request when
|
41
|
+
setting filterable attributes (previously it was always async)
|
42
|
+
|
43
|
+
## [1.0.1] - 2023-09-2
|
44
|
+
|
45
|
+
ids from `belongs_to` relations are no longer
|
46
|
+
indexed by default. You can explicitly specify
|
47
|
+
their inclusion if you want.
|
48
|
+
|
49
|
+
|
1
50
|
## [1.0.0] - 2023-07-22
|
2
51
|
|
3
52
|
- Initial release
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -43,7 +43,7 @@ The url below is the default one Meilisearch uses when run locally.
|
|
43
43
|
|
44
44
|
```bash
|
45
45
|
SEARCH_ENABLED=true
|
46
|
-
|
46
|
+
MEILI_MASTER_KEY=<your api key here>
|
47
47
|
MEILISEARCH_URL=http://127.0.0.1:7700
|
48
48
|
|
49
49
|
```
|
@@ -169,16 +169,19 @@ unless you intend to allow users to sort by when a record was created,
|
|
169
169
|
there's no point in recording it's `created_at` in the search index.
|
170
170
|
It'll just waste bandwidth, memory, and disk space.
|
171
171
|
|
172
|
-
Define a `SEARCHABLE_ATTRIBUTES` constant with an array of strings to limit things.
|
173
|
-
|
174
|
-
|
172
|
+
Define a `SEARCHABLE_ATTRIBUTES` constant with an array of strings to limit things.
|
173
|
+
These are the field names, and/or names of methods you wish to have indexed.
|
174
|
+
|
175
|
+
By default these will _also_ be the fields you can filter on.
|
176
|
+
|
177
|
+
Note that Meilisearch requires there to be an `id` field and it must be a string.
|
175
178
|
If you don't define one it will use string version of the `_id` your
|
176
179
|
document's `BSON::ObjectId`.
|
177
180
|
|
178
181
|
```ruby
|
179
182
|
# explicitly define the fields you want to be searchable
|
180
183
|
# this should be an array of symbols
|
181
|
-
SEARCHABLE_ATTRIBUTES = %
|
184
|
+
SEARCHABLE_ATTRIBUTES = %w[title body]
|
182
185
|
# OR explicitly define the fields you DON'T want searchable
|
183
186
|
SEARCHABLE_ATTRIBUTES = searchable_attributes - [:created_at]
|
184
187
|
```
|
@@ -194,9 +197,16 @@ exclude any fields that are `Mongoid::Fields::ForeignKey` objects.
|
|
194
197
|
|
195
198
|
#### Getting Extra Specific
|
196
199
|
If your searchable data needs to by dynamically generated instead of
|
197
|
-
just taken directly from the `Mongoid::Document`'s attributes
|
198
|
-
define a `search_indexable_hash` method on your class.
|
199
|
-
|
200
|
+
just taken directly from the `Mongoid::Document`'s attributes or
|
201
|
+
existing methods you can define a `search_indexable_hash` method on your class.
|
202
|
+
|
203
|
+
Before you do, please note that as of v1.1 your `SEARCHABLE_ATTRIBUTES`
|
204
|
+
constant can contain fields and method names in its array of values. Making
|
205
|
+
a method for each thing dynamically generated thing you want in the search
|
206
|
+
and then including it in SEARCHABLE_ATTRIBUTES is going to be
|
207
|
+
the easiest way of accomplishing this.
|
208
|
+
|
209
|
+
Your `search_indexable_hash` must return a hash, and that hash must include the following keys:
|
200
210
|
- `"id"` - a string that uniquely identifies the record
|
201
211
|
- `"object_class"` the name of the class that this record corresponds to.
|
202
212
|
|
data/lib/search/client.rb
CHANGED
@@ -8,7 +8,8 @@ module Search
|
|
8
8
|
def initialize
|
9
9
|
if ENV.fetch("SEARCH_ENABLED", "true") == "true"
|
10
10
|
url = ENV.fetch("MEILISEARCH_URL")
|
11
|
-
|
11
|
+
# MEILISEARCH_API_KEY is for mongodb_meilisearch v1.2.1 & earlier
|
12
|
+
api_key = ENV.fetch("MEILI_MASTER_KEY") || ENV.fetch("MEILISEARCH_API_KEY")
|
12
13
|
timeout = ENV.fetch("MEILISEARCH_TIMEOUT", 10).to_i
|
13
14
|
max_retries = ENV.fetch("MEILISEARCH_MAX_RETRIES", 2).to_i
|
14
15
|
if url.present? && api_key.present?
|
@@ -44,6 +44,10 @@ module Search
|
|
44
44
|
search_index.delete_document!(send(primary_search_key).to_s)
|
45
45
|
end
|
46
46
|
|
47
|
+
def searchable_attributes
|
48
|
+
self.class.searchable_attributes
|
49
|
+
end
|
50
|
+
|
47
51
|
# returns a hash of all the attributes
|
48
52
|
# if searchable_attributes method is defined
|
49
53
|
# it is assumed to return a list of symbols
|
@@ -57,9 +61,10 @@ module Search
|
|
57
61
|
# in returned results
|
58
62
|
def search_indexable_hash
|
59
63
|
klass = self.class
|
60
|
-
|
61
|
-
|
62
|
-
|
64
|
+
# the to_s & to_sym is just safety in case someone
|
65
|
+
# defined searchable_attributes as an array of strings
|
66
|
+
hash = {}
|
67
|
+
searchable_attributes.each { |a| hash[a.to_s] = send(a.to_sym) }
|
63
68
|
|
64
69
|
# Meilisearch doesn't like a primary key of _id
|
65
70
|
# but Mongoid ids are _id
|
@@ -69,7 +74,7 @@ module Search
|
|
69
74
|
id = hash.delete("_id").to_s
|
70
75
|
new_id = (!klass.has_class_prefixed_search_ids?) ? id : "#{self.class.name}_#{id}"
|
71
76
|
hash["id"] = new_id
|
72
|
-
elsif hash.has_key?("id") && !hash[id].is_a?(String)
|
77
|
+
elsif hash.has_key?("id") && !hash["id"].is_a?(String)
|
73
78
|
# this is mostly in case it's a BSON::ObjectId
|
74
79
|
hash["id"] = hash["id"].to_s
|
75
80
|
elsif !hash.has_key?("id")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongodb_meilisearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- masukomi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|