polysearch 0.1.0 → 0.1.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 +3 -3
- data/README.md +17 -6
- data/app/models/concerns/searchable.rb +1 -1
- data/lib/polysearch/version.rb +1 -1
- 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: 9e36fbf04831569261179657e616072e846db1f69ee69ac177fb573913563a21
|
4
|
+
data.tar.gz: 5c54be09188c3cf6fe2b370770e6e506e712280dfcee3dca05406a37612bb8a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ff0320bf6b4feb3f859faf6717bd27bfb7537f2e00186348dbef096da6a937110f91a904df8ec5929dda5242d3e2c2fb940517dbde24a6081afcabb177408a5
|
7
|
+
data.tar.gz: 5cd2653801702e0d1e37fe7ef8e93ff86193afe0788e8fe62a875bbf53d3a2ff4e29837cf49495d538d8ba9ae7639ceaa708845308535e767078109ba7be0e2d
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
polysearch (0.1.
|
4
|
+
polysearch (0.1.1)
|
5
5
|
rails (>= 6.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -87,10 +87,10 @@ GEM
|
|
87
87
|
mini_portile2 (2.5.1)
|
88
88
|
minitest (5.14.4)
|
89
89
|
nio4r (2.5.7)
|
90
|
-
nokogiri (1.11.
|
90
|
+
nokogiri (1.11.5)
|
91
91
|
mini_portile2 (~> 2.5.0)
|
92
92
|
racc (~> 1.4)
|
93
|
-
nokogiri (1.11.
|
93
|
+
nokogiri (1.11.5-arm64-darwin)
|
94
94
|
racc (~> 1.4)
|
95
95
|
parallel (1.20.1)
|
96
96
|
parser (3.0.1.1)
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
[![Lines of Code](http://img.shields.io/badge/lines_of_code-218-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
|
2
|
+
|
1
3
|
# Polysearch
|
2
4
|
|
3
|
-
|
5
|
+
Simplified polymorphic full text + similarity search based on postgres
|
6
|
+
|
7
|
+
> NOTE: This project is narrower in scope and more opinionated than [pg_search](https://github.com/Casecommons/pg_search).
|
4
8
|
|
5
9
|
## Requirements
|
6
10
|
|
@@ -43,17 +47,24 @@
|
|
43
47
|
after_save_commit :update_polysearch
|
44
48
|
|
45
49
|
def to_tsvectors
|
46
|
-
[
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
+
[
|
51
|
+
make_tsvector(first_name, weight: "A"),
|
52
|
+
make_tsvector(last_name, weight: "A"),
|
53
|
+
make_tsvector(email, weight: "B")
|
54
|
+
]
|
50
55
|
end
|
51
56
|
end
|
52
57
|
```
|
53
58
|
|
54
|
-
|
59
|
+
If you have existing records that need to create/update a polysearch record, you can save them like this.
|
55
60
|
|
61
|
+
```ruby
|
62
|
+
User.find_each(&:update_polysearch)
|
56
63
|
```
|
64
|
+
|
65
|
+
1. Start searching
|
66
|
+
|
67
|
+
```ruby
|
57
68
|
User.create first_name: "Nate", last_name: "Hopkins", email: "nhopkins@mailinator.com"
|
58
69
|
|
59
70
|
User.polysearch("nate")
|
@@ -47,7 +47,7 @@ module Polysearch
|
|
47
47
|
.select_fts_rank(value, :searchable_id, rank_alias: fts_rank_alias)
|
48
48
|
.select_similarity_rank(value, :searchable_id, rank_alias: similarity_rank_alias)
|
49
49
|
.where(searchable_type: name)
|
50
|
-
.fts(value).or(Polysearch::Record.similar(value))
|
50
|
+
.fts(value).or(Polysearch::Record.where(searchable_type: name).similar(value))
|
51
51
|
|
52
52
|
query = <<~SQL
|
53
53
|
SELECT searchables.*, fts.#{fts_rank_alias}, fts.#{similarity_rank_alias} from (#{fts.to_sql}) fts
|
data/lib/polysearch/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|