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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56abc4100a0dcd75ed558ec0ec631d53088ab5bf
4
- data.tar.gz: 33edaaa054f61e59efa18c8e96f0ecd9cc12630c
3
+ metadata.gz: 0129477dd69209f0276e0207d137556bfe486039
4
+ data.tar.gz: f1c644b3a6659eb823c0993534e3b25dc9ffdf72
5
5
  SHA512:
6
- metadata.gz: d4e3fb0b2571d4fec4f447f1f6df9108b70e6219c7381e9d79e95d559bb063389a4ded5f50db1c320a1564647a83a9050ba6dfb32f3b87adae9866028c7633b8
7
- data.tar.gz: f618f99de2af02e89346f6cde00036e6c56b88292511b434140276d470b6033da2717ebc132b5364e4ba9bdf32afc29ed6811098c532916db6973154b0db0d9e
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, columns, model, normalizer)
8
+ def initialize(query, options, all_columns, model, normalizer)
9
9
  @query = query
10
10
  @options = options || {}
11
- @columns = columns
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, :columns, :model, :normalizer
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
@@ -1,6 +1,7 @@
1
1
  module PgSearch
2
2
  module Features
3
3
  class Trigram < Feature
4
+
4
5
  def conditions
5
6
  if options[:threshold]
6
7
  Arel::Nodes::Grouping.new(
@@ -3,7 +3,7 @@ require 'rails/generators/base'
3
3
  module PgSearch
4
4
  module Migration
5
5
  class Generator < Rails::Generators::Base
6
- hide!
6
+ Rails::Generators.hide_namespace namespace
7
7
 
8
8
  def self.inherited(subclass)
9
9
  super
@@ -1,3 +1,3 @@
1
1
  module PgSearch
2
- VERSION = "0.7.5".freeze
2
+ VERSION = "0.7.6".freeze
3
3
  end
@@ -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.5
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-15 00:00:00.000000000 Z
12
+ date: 2014-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord