typesensual 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ea8c4aeb857be069ae139f07adf94182acb7cf65e4fc3d21efdaca0522227a8
4
- data.tar.gz: de66e132cc8b81b58201fc517847e4b5c0bf3644abb1c79eafa56bc696fbb7ce
3
+ metadata.gz: 16c9d2bb0a45de749680a833abf874d3f42da4190ea66b88e5d1f19a8f2d902c
4
+ data.tar.gz: d4f9dc200a97e182929b8cdc6fbb48edc1da69e6444137e2f7f670197742fa2a
5
5
  SHA512:
6
- metadata.gz: a29f224543a07478a3fc61e23edd3c9d3bb52995740c266f43400dd33dcf96b7e6d0a9ee54f59e7d6500c1ce3a33be1d0cd4ef590e5f716a6ade44bc22eb6c66
7
- data.tar.gz: e05a23f4d02ecc1242ba7b2ffdae7aca2a2f8c537a838186532e18b87a97b22c76385fe05a7b6c917d291f02461487abb378ab2f649c99cf0cd2c7587d0f6f7c
6
+ metadata.gz: 7d3130f6ac4d1b5d2722c4a6020fab73dc6ce1b91b7095e0f91de2d50723a60c5edb5434f651f874182c868a22e4015b12aa0eed097270562bc2bd291640a2af
7
+ data.tar.gz: c1fc489fab6f2c1fc29f57a0662883115b37b1790a02eab0db6193be53fbf4174de8e464b937f42b54ee2c3098d57abc8dc529f5d081728cb63861c75b302242
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- typesensual (0.2.0)
4
+ typesensual (0.3.0)
5
5
  activesupport (>= 6.1.5)
6
6
  paint (>= 2.0.0)
7
7
  typesense (>= 0.13.0)
@@ -9,7 +9,7 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (7.0.6)
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)
@@ -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.15.1)
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.14.1)
82
+ typesense (0.15.0)
83
83
  oj (~> 3.11)
84
84
  typhoeus (~> 1.4)
85
85
  typhoeus (1.4.0)
@@ -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.list_collections
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: typesense_collection,
199
+ collection: self,
187
200
  query: query,
188
201
  query_by: query_by
189
202
  )
@@ -21,6 +21,10 @@ class Typesensual
21
21
  class Index
22
22
  include StateHelpers
23
23
 
24
+ class << self
25
+ delegate :search, to: :collection
26
+ end
27
+
24
28
  def self.inherited(subclass)
25
29
  super
26
30
  # Copy the schema from the parent class to the subclass
@@ -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 collection [Hash] the Typesense hit hash
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
@@ -11,6 +11,10 @@ class Typesensual
11
11
  @results['hits'].map { |hit| Hit.new(hit) }
12
12
  end
13
13
 
14
+ def grouped_hits
15
+ @results['grouped_hits'].map { |hit| GroupedHit.new(hit) }
16
+ end
17
+
14
18
  def count
15
19
  @results['found']
16
20
  end
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Typesensual
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
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.2.0
4
+ version: 0.3.0
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-06 00:00:00.000000000 Z
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