typesensual 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +293 -0
- data/.ruby-version +1 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +111 -0
- data/LICENSE.txt +21 -0
- data/README.md +160 -0
- data/Rakefile +6 -0
- data/lib/tasks/typesensual.rake +24 -0
- data/lib/typesensual/callbacks.rb +22 -0
- data/lib/typesensual/collection.rb +202 -0
- data/lib/typesensual/config.rb +26 -0
- data/lib/typesensual/field.rb +52 -0
- data/lib/typesensual/index.rb +161 -0
- data/lib/typesensual/railtie.rb +9 -0
- data/lib/typesensual/rake_helper.rb +103 -0
- data/lib/typesensual/schema.rb +49 -0
- data/lib/typesensual/search/hit.rb +43 -0
- data/lib/typesensual/search/results.rb +51 -0
- data/lib/typesensual/search.rb +137 -0
- data/lib/typesensual/state_helpers.rb +14 -0
- data/lib/typesensual/version.rb +5 -0
- data/lib/typesensual.rb +41 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9231d4598d045c7089f290474867722966f4c4e720cc34a8de0ef960b5ac650a
|
4
|
+
data.tar.gz: 6b9400c0f282f3df2b3bec0f310f453b3383ddd05846894a1390176db60b206e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ebec05f05e05762734582d0b5080844a567002313aff70b4009642da0aeb20874fbe7a12e9b523dcc2f702bf0b98c24342f3f23dcf751582b42399f21542114
|
7
|
+
data.tar.gz: 709890ec4af5c9da8b680910c865d4900d0eae090cd9cc471bfb50c0860e486854cbcb01ee934aac1bfa124da6722771b2154d2a80b7a911416876ff9598257e
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,293 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
- rubocop-performance
|
4
|
+
AllCops:
|
5
|
+
NewCops: enable
|
6
|
+
DisplayCopNames: false
|
7
|
+
DisplayStyleGuide: true
|
8
|
+
StyleGuideCopsOnly: false
|
9
|
+
TargetRubyVersion: 2.7
|
10
|
+
Layout/ArgumentAlignment:
|
11
|
+
EnforcedStyle: with_fixed_indentation
|
12
|
+
Style/BlockDelimiters:
|
13
|
+
EnforcedStyle: braces_for_chaining
|
14
|
+
Style/CollectionMethods:
|
15
|
+
PreferredMethods:
|
16
|
+
collect: map
|
17
|
+
collect!: map!
|
18
|
+
inject: reduce
|
19
|
+
detect: find
|
20
|
+
find_all: select
|
21
|
+
Style/CommentAnnotation:
|
22
|
+
Enabled: true
|
23
|
+
Keywords:
|
24
|
+
- TODO
|
25
|
+
- FIXME
|
26
|
+
- OPTIMIZE
|
27
|
+
- HACK
|
28
|
+
- REVIEW
|
29
|
+
- DEPRECATED
|
30
|
+
Layout/DotPosition:
|
31
|
+
EnforcedStyle: leading
|
32
|
+
Layout/EmptyLineAfterGuardClause:
|
33
|
+
Enabled: false
|
34
|
+
Style/FormatString:
|
35
|
+
Enabled: true
|
36
|
+
EnforcedStyle: format
|
37
|
+
Style/FrozenStringLiteralComment:
|
38
|
+
SafeAutoCorrect: true
|
39
|
+
Enabled: true
|
40
|
+
Style/GlobalVars:
|
41
|
+
Enabled: false
|
42
|
+
Style/GuardClause:
|
43
|
+
Enabled: true
|
44
|
+
MinBodyLength: 3
|
45
|
+
Style/IfUnlessModifier:
|
46
|
+
Enabled: true
|
47
|
+
Layout/FirstArrayElementIndentation:
|
48
|
+
EnforcedStyle: consistent
|
49
|
+
Layout/FirstHashElementIndentation:
|
50
|
+
EnforcedStyle: consistent
|
51
|
+
Style/LambdaCall:
|
52
|
+
Enabled: true
|
53
|
+
Style/Next:
|
54
|
+
Enabled: true
|
55
|
+
MinBodyLength: 3
|
56
|
+
Style/NumericLiterals:
|
57
|
+
Enabled: true
|
58
|
+
MinDigits: 5
|
59
|
+
Style/PercentLiteralDelimiters:
|
60
|
+
Enabled: true
|
61
|
+
PreferredDelimiters:
|
62
|
+
'%': '[]'
|
63
|
+
'%i': '[]'
|
64
|
+
'%q': '[]'
|
65
|
+
'%Q': '[]'
|
66
|
+
'%r': '{}'
|
67
|
+
'%s': '()'
|
68
|
+
'%w': '[]'
|
69
|
+
'%W': '[]'
|
70
|
+
'%x': '[]'
|
71
|
+
Style/RaiseArgs:
|
72
|
+
Enabled: true
|
73
|
+
EnforcedStyle: exploded
|
74
|
+
Style/SingleLineMethods:
|
75
|
+
Enabled: true
|
76
|
+
AllowIfMethodIsEmpty: true
|
77
|
+
Style/StringLiterals:
|
78
|
+
EnforcedStyle: single_quotes
|
79
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
80
|
+
Enabled: true
|
81
|
+
EnforcedStyle: space
|
82
|
+
Layout/SpaceBeforeBlockBraces:
|
83
|
+
Enabled: true
|
84
|
+
EnforcedStyle: space
|
85
|
+
Layout/SpaceInsideBlockBraces:
|
86
|
+
Enabled: true
|
87
|
+
EnforcedStyle: space
|
88
|
+
EnforcedStyleForEmptyBraces: no_space
|
89
|
+
SpaceBeforeBlockParameters: true
|
90
|
+
Layout/SpaceInsideHashLiteralBraces:
|
91
|
+
Enabled: true
|
92
|
+
EnforcedStyle: space
|
93
|
+
EnforcedStyleForEmptyBraces: no_space
|
94
|
+
Style/SymbolProc:
|
95
|
+
Enabled: true
|
96
|
+
Layout/TrailingEmptyLines:
|
97
|
+
Enabled: true
|
98
|
+
EnforcedStyle: final_newline
|
99
|
+
Style/TrailingCommaInArguments:
|
100
|
+
Enabled: true
|
101
|
+
EnforcedStyleForMultiline: no_comma
|
102
|
+
Style/TrailingCommaInArrayLiteral:
|
103
|
+
Enabled: true
|
104
|
+
EnforcedStyleForMultiline: no_comma
|
105
|
+
Style/TrailingCommaInHashLiteral:
|
106
|
+
Enabled: true
|
107
|
+
EnforcedStyleForMultiline: no_comma
|
108
|
+
Style/TrivialAccessors:
|
109
|
+
Enabled: true
|
110
|
+
AllowDSLWriters: true
|
111
|
+
Naming/VariableName:
|
112
|
+
Enabled: true
|
113
|
+
EnforcedStyle: snake_case
|
114
|
+
Style/WordArray:
|
115
|
+
Enabled: true
|
116
|
+
MinSize: 2
|
117
|
+
Metrics/AbcSize:
|
118
|
+
Enabled: false
|
119
|
+
Metrics/BlockNesting:
|
120
|
+
Enabled: true
|
121
|
+
Max: 5
|
122
|
+
Metrics/BlockLength:
|
123
|
+
Enabled: false
|
124
|
+
Metrics/ClassLength:
|
125
|
+
Enabled: true
|
126
|
+
CountComments: false
|
127
|
+
Max: 500
|
128
|
+
Metrics/ModuleLength:
|
129
|
+
Enabled: true
|
130
|
+
CountComments: false
|
131
|
+
Max: 500
|
132
|
+
Metrics/CyclomaticComplexity:
|
133
|
+
Enabled: false
|
134
|
+
Layout/LineLength:
|
135
|
+
Enabled: true
|
136
|
+
Max: 100
|
137
|
+
AllowURI: true
|
138
|
+
IgnoreCopDirectives: true
|
139
|
+
Exclude:
|
140
|
+
- config/routes.rb
|
141
|
+
Metrics/MethodLength:
|
142
|
+
Enabled: true
|
143
|
+
CountComments: false
|
144
|
+
Max: 100
|
145
|
+
Metrics/ParameterLists:
|
146
|
+
Enabled: true
|
147
|
+
Max: 5
|
148
|
+
CountKeywordArgs: false
|
149
|
+
Metrics/PerceivedComplexity:
|
150
|
+
Enabled: false
|
151
|
+
Lint/AssignmentInCondition:
|
152
|
+
Enabled: true
|
153
|
+
AllowSafeAssignment: true
|
154
|
+
Style/InlineComment:
|
155
|
+
Enabled: false
|
156
|
+
Style/MethodCalledOnDoEndBlock:
|
157
|
+
Enabled: true
|
158
|
+
Style/SymbolArray:
|
159
|
+
Enabled: true
|
160
|
+
Naming/AccessorMethodName:
|
161
|
+
Enabled: true
|
162
|
+
Style/Alias:
|
163
|
+
Enabled: true
|
164
|
+
EnforcedStyle: prefer_alias_method
|
165
|
+
Style/ArrayJoin:
|
166
|
+
Enabled: true
|
167
|
+
Style/AsciiComments:
|
168
|
+
Enabled: false
|
169
|
+
Naming/AsciiIdentifiers:
|
170
|
+
Enabled: true
|
171
|
+
Style/Attr:
|
172
|
+
Enabled: true
|
173
|
+
Style/BlockComments:
|
174
|
+
Enabled: true
|
175
|
+
Style/ColonMethodCall:
|
176
|
+
Enabled: true
|
177
|
+
Style/Documentation:
|
178
|
+
Enabled: false
|
179
|
+
Style/EmptyLiteral:
|
180
|
+
Enabled: true
|
181
|
+
Style/EvenOdd:
|
182
|
+
Enabled: true
|
183
|
+
Lint/FlipFlop:
|
184
|
+
Enabled: true
|
185
|
+
Style/IfWithSemicolon:
|
186
|
+
Enabled: true
|
187
|
+
Style/Lambda:
|
188
|
+
EnforcedStyle: literal
|
189
|
+
# HACK: Until Rubocop is released with EnforcedStyle
|
190
|
+
Enabled: true
|
191
|
+
Layout/LeadingCommentSpace:
|
192
|
+
Enabled: true
|
193
|
+
Style/MultilineBlockChain:
|
194
|
+
Enabled: true
|
195
|
+
Style/MultilineTernaryOperator:
|
196
|
+
Enabled: true
|
197
|
+
Style/NegatedIf:
|
198
|
+
Enabled: true
|
199
|
+
Style/NestedTernaryOperator:
|
200
|
+
Enabled: true
|
201
|
+
Style/NilComparison:
|
202
|
+
Enabled: true
|
203
|
+
Style/Not:
|
204
|
+
Enabled: true
|
205
|
+
Style/OneLineConditional:
|
206
|
+
Enabled: true
|
207
|
+
Style/PerlBackrefs:
|
208
|
+
Enabled: true
|
209
|
+
Style/RedundantBegin:
|
210
|
+
Enabled: true
|
211
|
+
Style/RedundantSelf:
|
212
|
+
Enabled: true
|
213
|
+
Style/RescueModifier:
|
214
|
+
Enabled: true
|
215
|
+
Style/SelfAssignment:
|
216
|
+
Enabled: true
|
217
|
+
Style/ClassAndModuleChildren:
|
218
|
+
Enabled: true
|
219
|
+
Exclude:
|
220
|
+
- app/graphql/**/*
|
221
|
+
Style/HashEachMethods:
|
222
|
+
Enabled: true
|
223
|
+
Style/HashTransformKeys:
|
224
|
+
Enabled: true
|
225
|
+
Style/HashTransformValues:
|
226
|
+
Enabled: true
|
227
|
+
Layout/SpaceBeforeFirstArg:
|
228
|
+
Enabled: true
|
229
|
+
Layout/SpaceAfterColon:
|
230
|
+
Enabled: true
|
231
|
+
Layout/SpaceAfterComma:
|
232
|
+
Enabled: true
|
233
|
+
Layout/SpaceAroundKeyword:
|
234
|
+
Enabled: true
|
235
|
+
Layout/SpaceAfterMethodName:
|
236
|
+
Enabled: true
|
237
|
+
Layout/SpaceAfterNot:
|
238
|
+
Enabled: true
|
239
|
+
Layout/SpaceAfterSemicolon:
|
240
|
+
Enabled: true
|
241
|
+
Layout/SpaceBeforeComma:
|
242
|
+
Enabled: true
|
243
|
+
Layout/SpaceBeforeComment:
|
244
|
+
Enabled: true
|
245
|
+
Layout/SpaceBeforeSemicolon:
|
246
|
+
Enabled: true
|
247
|
+
Layout/SpaceAroundOperators:
|
248
|
+
Enabled: true
|
249
|
+
Layout/SpaceInsideParens:
|
250
|
+
Enabled: true
|
251
|
+
Layout/SpaceInsideRangeLiteral:
|
252
|
+
Enabled: true
|
253
|
+
Style/SpecialGlobalVars:
|
254
|
+
Enabled: true
|
255
|
+
Layout/TrailingWhitespace:
|
256
|
+
Enabled: true
|
257
|
+
Style/UnlessElse:
|
258
|
+
Enabled: true
|
259
|
+
Style/VariableInterpolation:
|
260
|
+
Enabled: true
|
261
|
+
Style/WhenThen:
|
262
|
+
Enabled: true
|
263
|
+
Lint/Debugger:
|
264
|
+
Enabled: true
|
265
|
+
Lint/DeprecatedClassMethods:
|
266
|
+
Enabled: true
|
267
|
+
Security/Eval:
|
268
|
+
Enabled: true
|
269
|
+
Lint/SuppressedException:
|
270
|
+
Enabled: true
|
271
|
+
Lint/LiteralInInterpolation:
|
272
|
+
Enabled: true
|
273
|
+
Lint/Loop:
|
274
|
+
Enabled: true
|
275
|
+
Lint/ParenthesesAsGroupedExpression:
|
276
|
+
Enabled: true
|
277
|
+
Lint/RequireParentheses:
|
278
|
+
Enabled: false
|
279
|
+
Lint/UnderscorePrefixedVariableName:
|
280
|
+
Enabled: true
|
281
|
+
Lint/UselessSetterCall:
|
282
|
+
Enabled: true
|
283
|
+
RSpec/ExampleLength:
|
284
|
+
Max: 20
|
285
|
+
RSpec/ImplicitSubject:
|
286
|
+
EnforcedStyle: single_statement_only
|
287
|
+
Enabled: true
|
288
|
+
RSpec/NamedSubject:
|
289
|
+
Enabled: false
|
290
|
+
RSpec/NestedGroups:
|
291
|
+
Max: 4
|
292
|
+
RSpec/Focus:
|
293
|
+
AutoCorrect: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.4
|
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in typesensual.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'rake'
|
9
|
+
gem 'rspec'
|
10
|
+
gem 'rubocop'
|
11
|
+
gem 'rubocop-performance'
|
12
|
+
gem 'rubocop-rspec'
|
13
|
+
gem 'simplecov'
|
14
|
+
|
15
|
+
# Documentation
|
16
|
+
gem 'commonmarker'
|
17
|
+
gem 'rack'
|
18
|
+
gem 'webrick'
|
19
|
+
gem 'yard'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
typesensual (0.1.0)
|
5
|
+
activesupport (>= 6.1.5)
|
6
|
+
paint (>= 2.0.0)
|
7
|
+
typesense (>= 0.13.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (7.0.5)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
ast (2.4.2)
|
18
|
+
commonmarker (0.23.9)
|
19
|
+
concurrent-ruby (1.2.2)
|
20
|
+
diff-lcs (1.5.0)
|
21
|
+
docile (1.4.0)
|
22
|
+
ethon (0.16.0)
|
23
|
+
ffi (>= 1.15.0)
|
24
|
+
ffi (1.15.5)
|
25
|
+
i18n (1.13.0)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
json (2.6.3)
|
28
|
+
minitest (5.18.0)
|
29
|
+
oj (3.14.3)
|
30
|
+
paint (2.3.0)
|
31
|
+
parallel (1.23.0)
|
32
|
+
parser (3.2.2.1)
|
33
|
+
ast (~> 2.4.1)
|
34
|
+
rack (2.2.7)
|
35
|
+
rainbow (3.1.1)
|
36
|
+
rake (13.0.6)
|
37
|
+
regexp_parser (2.8.0)
|
38
|
+
rexml (3.2.5)
|
39
|
+
rspec (3.12.0)
|
40
|
+
rspec-core (~> 3.12.0)
|
41
|
+
rspec-expectations (~> 3.12.0)
|
42
|
+
rspec-mocks (~> 3.12.0)
|
43
|
+
rspec-core (3.12.2)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-expectations (3.12.3)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-mocks (3.12.5)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.12.0)
|
51
|
+
rspec-support (3.12.0)
|
52
|
+
rubocop (1.51.0)
|
53
|
+
json (~> 2.3)
|
54
|
+
parallel (~> 1.10)
|
55
|
+
parser (>= 3.2.0.0)
|
56
|
+
rainbow (>= 2.2.2, < 4.0)
|
57
|
+
regexp_parser (>= 1.8, < 3.0)
|
58
|
+
rexml (>= 3.2.5, < 4.0)
|
59
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
60
|
+
ruby-progressbar (~> 1.7)
|
61
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
62
|
+
rubocop-ast (1.28.1)
|
63
|
+
parser (>= 3.2.1.0)
|
64
|
+
rubocop-capybara (2.18.0)
|
65
|
+
rubocop (~> 1.41)
|
66
|
+
rubocop-factory_bot (2.23.1)
|
67
|
+
rubocop (~> 1.33)
|
68
|
+
rubocop-performance (1.18.0)
|
69
|
+
rubocop (>= 1.7.0, < 2.0)
|
70
|
+
rubocop-ast (>= 0.4.0)
|
71
|
+
rubocop-rspec (2.22.0)
|
72
|
+
rubocop (~> 1.33)
|
73
|
+
rubocop-capybara (~> 2.17)
|
74
|
+
rubocop-factory_bot (~> 2.22)
|
75
|
+
ruby-progressbar (1.13.0)
|
76
|
+
simplecov (0.22.0)
|
77
|
+
docile (~> 1.1)
|
78
|
+
simplecov-html (~> 0.11)
|
79
|
+
simplecov_json_formatter (~> 0.1)
|
80
|
+
simplecov-html (0.12.3)
|
81
|
+
simplecov_json_formatter (0.1.4)
|
82
|
+
typesense (0.14.1)
|
83
|
+
oj (~> 3.11)
|
84
|
+
typhoeus (~> 1.4)
|
85
|
+
typhoeus (1.4.0)
|
86
|
+
ethon (>= 0.9.0)
|
87
|
+
tzinfo (2.0.6)
|
88
|
+
concurrent-ruby (~> 1.0)
|
89
|
+
unicode-display_width (2.4.2)
|
90
|
+
webrick (1.7.0)
|
91
|
+
yard (0.9.34)
|
92
|
+
|
93
|
+
PLATFORMS
|
94
|
+
x86_64-darwin-19
|
95
|
+
x86_64-darwin-22
|
96
|
+
|
97
|
+
DEPENDENCIES
|
98
|
+
commonmarker
|
99
|
+
rack
|
100
|
+
rake
|
101
|
+
rspec
|
102
|
+
rubocop
|
103
|
+
rubocop-performance
|
104
|
+
rubocop-rspec
|
105
|
+
simplecov
|
106
|
+
typesensual!
|
107
|
+
webrick
|
108
|
+
yard
|
109
|
+
|
110
|
+
BUNDLED WITH
|
111
|
+
2.3.13
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Emma Lejeck
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
# Typesensual
|
2
|
+
|
3
|
+
Typesensual is a small wrapper around the [Typesense Ruby client][typesense-gem] which provides a
|
4
|
+
more familiar, rubyish interface for interacting with [Typesense][typesense-website]. Similar to
|
5
|
+
[Chewy][chewy-gem], it provides a DSL for defining your schema, manages the life-cycle of your
|
6
|
+
collections, and provides a simple interface for indexing, searching, and deleting documents.
|
7
|
+
|
8
|
+
Unlike Chewy, it does *not* handle loading, denormalizing, or formatting your data for search
|
9
|
+
purposes. It can be combined with an ORM such as ActiveRecord or Sequel, or even used with plain SQL
|
10
|
+
queries, but that integration is left to you. This is a concious decision, since loading and
|
11
|
+
transforming data is often a complex and application-specific task that is best left to the
|
12
|
+
application developer, since you know best.
|
13
|
+
|
14
|
+
[typesense-gem]: https://github.com/typesense/typesense-ruby
|
15
|
+
[typesense-website]: https://typesense.org/
|
16
|
+
[chewy-gem]: https://github.com/toptal/chewy
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'typesensual'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install typesensual
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
### Configuring the client
|
37
|
+
|
38
|
+
The first step is to configure the client. This is done by calling `Typesensual.configure` and
|
39
|
+
passing a block to configure your parameters:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
# config/initializers/typesensual.rb
|
43
|
+
Typesensual.configure do |config|
|
44
|
+
# The nodes in your cluster to connect to
|
45
|
+
config.nodes = [{ host: 'localhost', port: 8108, protocol: 'http' }]
|
46
|
+
# The API key to use for authentication
|
47
|
+
config.api_key = 'xyz'
|
48
|
+
# The environment you are running in (in Rails, this is set automatically)
|
49
|
+
config.env = 'test'
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
### Creating your first index
|
54
|
+
|
55
|
+
Once the client is configured, you can create your first index. This is done by creating a subclass
|
56
|
+
of `Typesensual::Index` and defining your schema and how to load the data. For example, the
|
57
|
+
following index might be used to index movies from an ActiveRecord model:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# app/indices/movie_index.rb
|
61
|
+
class MoviesIndex < Typesensual::Index
|
62
|
+
# The schema of the collection
|
63
|
+
schema do
|
64
|
+
enable_nested_fields
|
65
|
+
|
66
|
+
field 'title', type: 'string'
|
67
|
+
field 'release_date\..*', type: 'int32', facet: true
|
68
|
+
field 'average_rating', type: 'float', facet: true
|
69
|
+
field 'user_count', type: 'int32'
|
70
|
+
field 'genres', type: 'string[]', facet: true
|
71
|
+
end
|
72
|
+
|
73
|
+
def index_one(id)
|
74
|
+
movie = Movie.find(id).includes(:genres)
|
75
|
+
|
76
|
+
{
|
77
|
+
id: movie.id,
|
78
|
+
title: movie.title,
|
79
|
+
release_date: {
|
80
|
+
year: movie.release_date.year,
|
81
|
+
month: movie.release_date.month,
|
82
|
+
day: movie.release_date.day
|
83
|
+
},
|
84
|
+
average_rating: movie.average_rating,
|
85
|
+
user_count: movie.user_count,
|
86
|
+
genres: movie.genres.map(&:name)
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
def index_many(ids)
|
91
|
+
Movies.where(id: ids).includes(:genres).find_each do |movie|
|
92
|
+
yield {
|
93
|
+
id: movie.id,
|
94
|
+
title: movie.title,
|
95
|
+
release_date: {
|
96
|
+
year: movie.release_date.year,
|
97
|
+
month: movie.release_date.month,
|
98
|
+
day: movie.release_date.day
|
99
|
+
},
|
100
|
+
average_rating: movie.average_rating,
|
101
|
+
user_count: movie.user_count,
|
102
|
+
genres: movie.genres.map(&:name)
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
### Loading data into your index
|
110
|
+
|
111
|
+
Once you have defined your index, you can load data into it and update the alias to point to the
|
112
|
+
indexed data. Typesensual provides rake tasks for this purpose if you use ActiveRecord:
|
113
|
+
|
114
|
+
```console
|
115
|
+
$ bundle exec rake typesensual:load[MoviesIndex,Movie]
|
116
|
+
==> Indexing Movie into MoviesIndex (Version 1690076097)
|
117
|
+
|
118
|
+
$ bundle exec rake typesensual:update_alias[MoviesIndex,1690076097]
|
119
|
+
==> Alias for MoviesIndex
|
120
|
+
Old: None (N/A)
|
121
|
+
New: 1690076097 (2023-05-07 18:01:37)
|
122
|
+
```
|
123
|
+
|
124
|
+
Otherwise you can do similar to the following:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
collection = MoviesIndex.create!
|
128
|
+
collection.index_many(Movie.ids, collection: collection)
|
129
|
+
MoviesIndex.update_alias(collection)
|
130
|
+
```
|
131
|
+
|
132
|
+
### Searching your index
|
133
|
+
|
134
|
+
Now that you have data in your index, you can search it! Typesensual provides a simple interface for
|
135
|
+
this purpose, including pagination support:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
query = MoviesIndex.search(query: 'Your Name', query_by: 'title')
|
139
|
+
query.per(10).page(2).load
|
140
|
+
```
|
141
|
+
|
142
|
+
The full interface for this is documented in the `Search`, `Results`, and `Hit` classes.
|
143
|
+
|
144
|
+
## Development
|
145
|
+
|
146
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
147
|
+
|
148
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
149
|
+
|
150
|
+
## Contributing
|
151
|
+
|
152
|
+
Bug reports, feature requests, and pull requests are welcome on [our GitHub][github].
|
153
|
+
|
154
|
+
[github]: https://github.com/hummingbird-me/typesensual
|
155
|
+
|
156
|
+
## License
|
157
|
+
|
158
|
+
The gem is available as open source under the terms of the [MIT License][mit-license].
|
159
|
+
|
160
|
+
[mit-license]: https://opensource.org/licenses/MIT
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :typesensual do
|
4
|
+
desc 'List typesensual indices and their collections'
|
5
|
+
task list: :environment do
|
6
|
+
Typesensual::RakeHelper.list_collections
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'Update the alias for an index'
|
10
|
+
task :update_alias, %i[index version] => :environment do |_, args|
|
11
|
+
Typesensual::RakeHelper.update_alias(
|
12
|
+
index: args[:index],
|
13
|
+
version: args[:version]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Index all records from a model into an index'
|
18
|
+
task :index, %i[index model] => :environment do |_, args|
|
19
|
+
Typesensual::RakeHelper.index(
|
20
|
+
index: args[:index],
|
21
|
+
model: args[:model]
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Typesensual
|
4
|
+
class Callbacks
|
5
|
+
def initialize(index, should_update: ->(_record) { true })
|
6
|
+
@index = index
|
7
|
+
@should_update = should_update
|
8
|
+
end
|
9
|
+
|
10
|
+
def after_create_commit(record)
|
11
|
+
@index.index_one(record.id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def after_update_commit(record)
|
15
|
+
@should_update.call(record) && @index.index_one(record.id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def after_destroy_commit(record)
|
19
|
+
@index.remove_one(record.id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|