pg_search_scope 0.1.6 → 0.1.7

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.
data/README.md CHANGED
@@ -38,6 +38,8 @@ You can set additional search options:
38
38
 
39
39
  :rank_function - Ranking function. Valid values are 'ts_rank' and 'ts_rank_cd'
40
40
 
41
+ :rank_columns - If you want to sort table by rank only by specific fields - input column names hear
42
+
41
43
  If you use `:language` option, you need to use the same option for `add_fulltext_index`
42
44
 
43
45
  Examples:
@@ -33,6 +33,7 @@ module PgSearchScope
33
33
  #
34
34
  # * <tt>:language</tt> - Search language, e.g. 'simple' (without magic), 'english'
35
35
  # * <tt>:rank_function</tt> - Ranking function. Valid values are 'ts_rank' and 'ts_rank_cd'
36
+ # * <tt>:rank_columns</tt> - If you want to sort table by rank only by specific fields - input column names hear
36
37
  #
37
38
  # == Usage
38
39
  #
@@ -70,8 +71,13 @@ module PgSearchScope
70
71
 
71
72
  tsvector = "to_tsvector('#{options[:language]}', #{document})"
72
73
  tsquery = "to_tsquery('#{options[:language]}', '#{terms.join(" #{OPERATORS[options[:operator]]} ")}')"
74
+ rank_tsvector = tsvector
75
+ if options[:rank_columns].present?
76
+ rank_document = options[:rank_columns].map { |n| n = "#{prefix}.#{n}" unless n['.']; "coalesce(#{n}, '')" }.join(" || ' ' || ")
77
+ rank_tsvector = "to_tsvector('#{options[:language]}', #{rank_document})"
78
+ end
73
79
 
74
- rank = "#{scope_options[:rank_function]}(#{tsvector}, #{tsquery}, #{options[:normalization]})"
80
+ rank = "#{scope_options[:rank_function]}(#{rank_tsvector}, #{tsquery}, #{options[:normalization]})"
75
81
 
76
82
  search_scope = scoped
77
83
 
@@ -1,3 +1,3 @@
1
1
  module PgSearchScope
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_search_scope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ''
15
15
  email: