typesensual 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -5
- data/lib/tasks/typesensual.rake +1 -1
- data/lib/typesensual/collection.rb +14 -1
- data/lib/typesensual/index.rb +4 -0
- data/lib/typesensual/search/grouped_hit.rb +37 -0
- data/lib/typesensual/search/hit.rb +1 -1
- data/lib/typesensual/search/results.rb +4 -0
- data/lib/typesensual/search.rb +9 -1
- data/lib/typesensual/version.rb +1 -1
- data/lib/typesensual.rb +5 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 432d9ea014861c5f21225215e693d84d87dc2c3056b8b1b74d6e59141b3d153c
|
4
|
+
data.tar.gz: 92b1a1c633e62dab743bbebf4e456a6d9766b842bf3827667a611c1ee9cd416c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3696898ec4467ba051e7178166f97b01c8ff5c3d7f3708d8670239995f642f95f7e5643d08809924259deb50943b53dcdaefc76fff99e99bcfcef7e964faaba
|
7
|
+
data.tar.gz: cd6b6e32bf1f472ff31b6ac33fc86971359f6ae2e31aea265c9af5f688c28fd254f1be9d82edf7fc488a1422c356e524c13d134765470b6e6dfcf33a5b578cb5
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
typesensual (0.
|
4
|
+
typesensual (0.3.1)
|
5
5
|
activesupport (>= 6.1.5)
|
6
6
|
paint (>= 2.0.0)
|
7
7
|
typesense (>= 0.13.0)
|
@@ -9,13 +9,13 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (7.0.
|
12
|
+
activesupport (7.0.7)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
17
|
ast (2.4.2)
|
18
|
-
commonmarker (0.23.
|
18
|
+
commonmarker (0.23.10)
|
19
19
|
concurrent-ruby (1.2.2)
|
20
20
|
diff-lcs (1.5.0)
|
21
21
|
docile (1.4.0)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
27
|
json (2.6.3)
|
28
28
|
minitest (5.19.0)
|
29
|
-
oj (3.
|
29
|
+
oj (3.16.0)
|
30
30
|
paint (2.3.0)
|
31
31
|
parallel (1.23.0)
|
32
32
|
parser (3.2.2.1)
|
@@ -79,7 +79,7 @@ GEM
|
|
79
79
|
simplecov_json_formatter (~> 0.1)
|
80
80
|
simplecov-html (0.12.3)
|
81
81
|
simplecov_json_formatter (0.1.4)
|
82
|
-
typesense (0.
|
82
|
+
typesense (0.15.0)
|
83
83
|
oj (~> 3.11)
|
84
84
|
typhoeus (~> 1.4)
|
85
85
|
typhoeus (1.4.0)
|
data/lib/tasks/typesensual.rake
CHANGED
@@ -5,7 +5,7 @@ require 'typesensual/rake_helper'
|
|
5
5
|
namespace :typesensual do
|
6
6
|
desc 'List typesensual indices and their collections'
|
7
7
|
task list: :environment do
|
8
|
-
Typesensual::RakeHelper.
|
8
|
+
Typesensual::RakeHelper.list
|
9
9
|
end
|
10
10
|
|
11
11
|
desc 'Update the alias for an index'
|
@@ -181,9 +181,22 @@ class Typesensual
|
|
181
181
|
typesense_collection.documents[id.to_s].delete
|
182
182
|
end
|
183
183
|
|
184
|
+
# Remove multiple documents from typesense based on a filter
|
185
|
+
#
|
186
|
+
# @param filter_by [String] the filter to use to remove documents
|
187
|
+
# @return [void]
|
188
|
+
def remove_many!(filter_by:)
|
189
|
+
typesense_collection.documents.delete(filter_by: filter_by)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Search for documents in typesense
|
193
|
+
#
|
194
|
+
# @param query [String] the query to search for
|
195
|
+
# @param query_by [String] the fields to search by
|
196
|
+
# @return [Search] the search object
|
184
197
|
def search(query:, query_by:)
|
185
198
|
Search.new(
|
186
|
-
collection:
|
199
|
+
collection: self,
|
187
200
|
query: query,
|
188
201
|
query_by: query_by
|
189
202
|
)
|
data/lib/typesensual/index.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Typesensual
|
4
|
+
class Search
|
5
|
+
class GroupedHit
|
6
|
+
# {
|
7
|
+
# "group_key": [
|
8
|
+
# "420",
|
9
|
+
# "69"
|
10
|
+
# ],
|
11
|
+
# "hits": {
|
12
|
+
# ...
|
13
|
+
# },
|
14
|
+
# "found": 3
|
15
|
+
# }
|
16
|
+
# @param group [Hash] the Typesense hit hash
|
17
|
+
# * `group_key` [Array<any>] the grouping keys
|
18
|
+
# * `hits` [Hash] the Hits for the group
|
19
|
+
# * `found` [Integer] the number of hits in the group
|
20
|
+
def initialize(group)
|
21
|
+
@group = group
|
22
|
+
end
|
23
|
+
|
24
|
+
def count
|
25
|
+
@group['found']
|
26
|
+
end
|
27
|
+
|
28
|
+
def hits
|
29
|
+
@group['hits'].map { |hit| Hit.new(hit) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def group_key
|
33
|
+
@group['group_key']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -19,7 +19,7 @@ class Typesensual
|
|
19
19
|
# },
|
20
20
|
# "text_match": 130916
|
21
21
|
# }
|
22
|
-
# @param
|
22
|
+
# @param hit [Hash] the Typesense hit hash
|
23
23
|
# * `highlights` [Array<Hash>] the highlights for the hit
|
24
24
|
# * `document` [Hash] the matching document
|
25
25
|
# * `text_match` [Integer] the text matching score
|
data/lib/typesensual/search.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'typesensual/search/hit'
|
4
|
+
require 'typesensual/search/grouped_hit'
|
4
5
|
require 'typesensual/search/results'
|
5
6
|
|
6
7
|
class Typesensual
|
@@ -22,6 +23,7 @@ class Typesensual
|
|
22
23
|
@facet_query = []
|
23
24
|
@include_fields = []
|
24
25
|
@exclude_fields = []
|
26
|
+
@group_by = []
|
25
27
|
@params = {}
|
26
28
|
|
27
29
|
@collection = collection
|
@@ -108,6 +110,11 @@ class Typesensual
|
|
108
110
|
self
|
109
111
|
end
|
110
112
|
|
113
|
+
def group_by(*fields)
|
114
|
+
@group_by += fields.map(&:to_s)
|
115
|
+
self
|
116
|
+
end
|
117
|
+
|
111
118
|
# Set additional parameters to pass to the search
|
112
119
|
# @param values [Hash] the parameters to set
|
113
120
|
def set(values)
|
@@ -128,7 +135,8 @@ class Typesensual
|
|
128
135
|
facet_by: @facet_by&.join(','),
|
129
136
|
facet_query: @facet_query&.join(','),
|
130
137
|
include_fields: @include_fields&.join(','),
|
131
|
-
exclude_fields: @exclude_fields&.join(',')
|
138
|
+
exclude_fields: @exclude_fields&.join(','),
|
139
|
+
group_by: @group_by&.join(',')
|
132
140
|
}.merge(@params).reject { |_, v| v.blank? }
|
133
141
|
end
|
134
142
|
|
data/lib/typesensual/version.rb
CHANGED
data/lib/typesensual.rb
CHANGED
@@ -19,14 +19,16 @@ require 'typesensual/railtie' if defined?(Rails)
|
|
19
19
|
|
20
20
|
class Typesensual
|
21
21
|
class << self
|
22
|
-
attr_accessor :config
|
23
|
-
|
24
22
|
def client
|
25
23
|
config&.client
|
26
24
|
end
|
27
25
|
|
28
26
|
def configure(&block)
|
29
|
-
|
27
|
+
@config = Typesensual::Config.new(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def config
|
31
|
+
@config ||= Typesensual::Config.new
|
30
32
|
end
|
31
33
|
|
32
34
|
# Get the collections that match the alias name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typesensual
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emma Lejeck
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/typesensual/rake_helper.rb
|
81
81
|
- lib/typesensual/schema.rb
|
82
82
|
- lib/typesensual/search.rb
|
83
|
+
- lib/typesensual/search/grouped_hit.rb
|
83
84
|
- lib/typesensual/search/hit.rb
|
84
85
|
- lib/typesensual/search/results.rb
|
85
86
|
- lib/typesensual/state_helpers.rb
|