pg_search 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +33 -0
- data/lib/pg_search/configuration/column.rb +2 -1
- data/lib/pg_search/features/feature.rb +13 -3
- data/lib/pg_search/features/trigram.rb +1 -0
- data/lib/pg_search/migration/generator.rb +1 -1
- data/lib/pg_search/version.rb +1 -1
- data/spec/lib/pg_search/features/trigram_spec.rb +21 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0129477dd69209f0276e0207d137556bfe486039
|
4
|
+
data.tar.gz: f1c644b3a6659eb823c0993534e3b25dc9ffdf72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38795ff477f256ba5acdb5ce1c368d8830294cabc04bd3ca1b84554f26094e39f14eca31574d6de0821803c987a1040946913b008a06de0ad4d376b7b2cfebfe
|
7
|
+
data.tar.gz: e7ce0c0536b72f1857cd638cb55eb3a2a1087262a4a973a26057a18e45d6ea15df0818637f4c8bd9e4d9757895feeb3d0fb255893c0c01d0e09aa6c9e066a0bd
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# pg_search changelog
|
2
2
|
|
3
|
+
## 0.7.6
|
4
|
+
|
5
|
+
* Fix migration generator in Rails 3. (Andrew Marshall and Nora Lin)
|
6
|
+
* Add :only option for limiting search fields per feature. (Jonathan Greenberg)
|
7
|
+
|
3
8
|
## 0.7.5
|
4
9
|
|
5
10
|
* Add option to make feature available only for sorting. (Brent Wheeldon)
|
data/README.md
CHANGED
@@ -790,6 +790,39 @@ Vegetable.roughly_spelled_like("collyflower") # => [cauliflower]
|
|
790
790
|
Vegetable.strictly_spelled_like("collyflower") # => []
|
791
791
|
```
|
792
792
|
|
793
|
+
### Limiting Fields When Combining Features
|
794
|
+
|
795
|
+
Sometimes when doing queries combining different features you
|
796
|
+
might want to searching against only some of the fields with certain features.
|
797
|
+
For example perhaps you want to only do a trigram search against the shorter fields
|
798
|
+
so that you don't need to reduce the threshold excessively. You can specify
|
799
|
+
which fields using the 'only' option:
|
800
|
+
|
801
|
+
```ruby
|
802
|
+
class Image < ActiveRecord::Base
|
803
|
+
include PgSearch
|
804
|
+
|
805
|
+
pg_search_scope :combined_search,
|
806
|
+
:against => [:file_name, :short_description, :long_description]
|
807
|
+
:using => {
|
808
|
+
:tsearch => { :dictionary => 'english' },
|
809
|
+
:trigram => {
|
810
|
+
:only => [:file_name, :short_description]
|
811
|
+
}
|
812
|
+
}
|
813
|
+
|
814
|
+
end
|
815
|
+
```
|
816
|
+
|
817
|
+
Now you can succesfully retrieve an Image with a file_name: 'image_foo.jpg'
|
818
|
+
and long_description: 'This description is so long that it would make a trigram search
|
819
|
+
fail any reasonable threshold limit' with:
|
820
|
+
|
821
|
+
```ruby
|
822
|
+
Image.combined_search('reasonable') # found with tsearch
|
823
|
+
Image.combined_search('foo') # found with trigram
|
824
|
+
```
|
825
|
+
|
793
826
|
### Ignoring accent marks (PostgreSQL 9.0 and newer only)
|
794
827
|
|
795
828
|
Most of the time you will want to ignore accent marks when searching. This
|
@@ -3,9 +3,10 @@ require 'digest'
|
|
3
3
|
module PgSearch
|
4
4
|
class Configuration
|
5
5
|
class Column
|
6
|
-
attr_reader :weight
|
6
|
+
attr_reader :weight, :name
|
7
7
|
|
8
8
|
def initialize(column_name, weight, model)
|
9
|
+
@name = column_name.to_s
|
9
10
|
@column_name = column_name.to_s
|
10
11
|
@weight = weight
|
11
12
|
@model = model
|
@@ -5,22 +5,32 @@ module PgSearch
|
|
5
5
|
class Feature
|
6
6
|
delegate :connection, :quoted_table_name, :to => :'@model'
|
7
7
|
|
8
|
-
def initialize(query, options,
|
8
|
+
def initialize(query, options, all_columns, model, normalizer)
|
9
9
|
@query = query
|
10
10
|
@options = options || {}
|
11
|
-
@
|
11
|
+
@all_columns = all_columns
|
12
12
|
@model = model
|
13
13
|
@normalizer = normalizer
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
attr_reader :query, :options, :
|
18
|
+
attr_reader :query, :options, :all_columns, :model, :normalizer
|
19
19
|
|
20
20
|
def document
|
21
21
|
columns.map { |column| column.to_sql }.join(" || ' ' || ")
|
22
22
|
end
|
23
23
|
|
24
|
+
def columns
|
25
|
+
if options[:only]
|
26
|
+
all_columns.select do |column|
|
27
|
+
Array.wrap(options[:only]).map(&:to_s).include? column.name
|
28
|
+
end
|
29
|
+
else
|
30
|
+
all_columns
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
def normalize(expression)
|
25
35
|
normalizer.add_normalization(expression)
|
26
36
|
end
|
data/lib/pg_search/version.rb
CHANGED
@@ -50,6 +50,27 @@ describe PgSearch::Features::Trigram do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
+
context 'only certain columns are selected' do
|
54
|
+
context 'one column' do
|
55
|
+
let(:options) { { only: :name } }
|
56
|
+
|
57
|
+
it 'only searches against the select column' do
|
58
|
+
options = { only: :name }
|
59
|
+
coalesced_column = "coalesce(#{Model.quoted_table_name}.\"name\"::text, '')"
|
60
|
+
expect(feature.conditions.to_sql).to eq("((#{coalesced_column}) % '#{query}')")
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
context 'multiple columns' do
|
65
|
+
let(:options) { { only: [:name, :content] } }
|
66
|
+
|
67
|
+
it 'concatenates when multiples columns are selected' do
|
68
|
+
options = { only: [:name, :content] }
|
69
|
+
expect(feature.conditions.to_sql).to eq("((#{coalesced_columns}) % '#{query}')")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
53
74
|
end
|
54
75
|
|
55
76
|
describe '#rank' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Hutchins
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|