polysearch 0.2.1 → 0.2.3

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: 7d46cc2a6e4a3d8bb8100e611d57722c9576f7b4104770903f821fb8432ac921
4
- data.tar.gz: 960aff262721eb4e0acc75773aa75169406bde6ce2fda77896dddd8ff96d5ce5
3
+ metadata.gz: e527bae221d08edf537ee05002258f8cdf982c09f0748eccfee8f170fb83629e
4
+ data.tar.gz: 3f4d4d07575755d6a89e2d20be671128a861305cc5f41b7437a7d4c88a0a7bb2
5
5
  SHA512:
6
- metadata.gz: 78cc5ea29490948ac03a67e226b5d5b6c12335b74a4ac68f329358903d92b64501ef57dba654aac737518c48a347ccf4aac4dfe86b7aa03e4b21e8d4b5c158e5
7
- data.tar.gz: 2fe8f4139749f14b96b528a3b3aee6609f66f50325ad648c631832fb48715a1e5fe016c8733963c1a521758a7abc67e45f0e0cad6d18be25522ff620200e2994
6
+ metadata.gz: '09093059f97e4f6af87403c21e8eb3b834ba82acfaebfa9708992f7028304d59bfc32cad6a7c38b482d7045a535f6e7c1cbc379416e594ec2fcef65b9a17d445'
7
+ data.tar.gz: 03f1cf68155d2cf68431e032459363c43252c7bfe359e93a43db3f2cb3ef4827f784ea16ee7539ed34999ad30936a82f735c2eb57857773eb23c6d319ffa581e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polysearch (0.2.1)
4
+ polysearch (0.2.3)
5
5
  rails (>= 6.0)
6
6
 
7
7
  GEM
@@ -60,14 +60,30 @@ module Polysearch
60
60
  end
61
61
 
62
62
  def update_polysearch
63
+ return unless persisted?
63
64
  tsvectors = to_tsvectors.compact.uniq
64
65
  return if tsvectors.blank?
66
+
65
67
  tsvectors.pop while tsvectors.size > 500
66
68
  tsvectors.concat similarity_words_tsvectors
67
69
  tsvector = tsvectors.join(" || ")
68
- fts = Polysearch::Record.where(searchable: self).first_or_create
69
- fts.update_value tsvector
70
- fts.update_columns words: similarity_words.join(" ")
70
+
71
+ attributes = {
72
+ searchable_type: self.class.name,
73
+ searchable_id: id,
74
+ words: similarity_words.join(" "),
75
+ created_at: Time.current,
76
+ updated_at: Time.current
77
+ }
78
+
79
+ result = Polysearch::Record.upsert(
80
+ attributes,
81
+ unique_by: [:searchable_type, :searchable_id],
82
+ returning: :id
83
+ )
84
+
85
+ record = Polysearch::Record.find_by(id: result.first["id"])
86
+ record.update_value tsvector
71
87
  end
72
88
 
73
89
  # Polysearch::Searchable#to_tsvectors is abstract... a noop by default
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Polysearch
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polysearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-24 00:00:00.000000000 Z
11
+ date: 2021-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails