flare 1.6.1 → 1.7.0

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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/flare/session.rb +17 -60
  3. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.1
1
+ 1.7.0
@@ -1,6 +1,5 @@
1
1
  module Flare
2
2
  class Session
3
- RESULT_LIMIT = 1000
4
3
  PER_PAGE = 16
5
4
 
6
5
  def initialize(url)
@@ -67,82 +66,40 @@ module Flare
67
66
  private
68
67
  def execute(*args)
69
68
  options = args.extract_options!
70
-
71
- options.assert_valid_keys(:q, :fq, :types, :page, :per_page, :limit, :fl, :sort, :facet, :mlt, :mm)
72
-
69
+
73
70
  options.reverse_merge!({
74
- :page => 1,
75
- :per_page => PER_PAGE,
76
- :limit => RESULT_LIMIT,
77
- :fields => '* score',
71
+ :start => 0,
72
+ :rows => PER_PAGE
78
73
  })
79
-
80
- query = {
81
- :q => Array(options[:q] || (args.blank? ? "*:*" : args)).flatten,
82
- :fq => Array(options[:fq]).flatten,
83
- :fl => options[:fields],
84
- :start => start = (options[:page] -1) * options[:per_page],
85
- :rows => options[:per_page],
86
- :sort => options[:sort]
87
- }
88
-
89
- if options[:facet]
90
- query["facet"] = true
91
- query["facet.field"] = options[:facet][:fields]
92
- query["facet.query"] = options[:facet][:queries]
93
- query["facet.mincount"] = options[:facet][:mincount] || 1
94
- query["facet.limit"] = options[:facet][:limit]
95
-
96
- query["facet.missing"] = @params[:facet][:missing]
97
- query["facet.mincount"] = @params[:facet][:mincount]
98
- query["facet.prefix"] = @params[:facet][:prefix]
99
- query["facet.offset"] = @params[:facet][:offset]
100
- query["facet.offset"] = 'count'
101
- end
102
74
 
103
- if options[:mlt]
104
- query['mlt'] = true
105
- query['mlt.fl'] = Array(options[:mlt][:fields]).flatten.join(',')
106
- query['mlt.count'] = options[:mlt][:count] if options[:mlt][:count]
107
- end
108
-
109
- if options[:mm]
110
- query['mm'] = options[:mm]
111
- end
75
+ options[:q] = Array.wrap(options[:q] || (args.blank? ? "*:*" : args))
76
+ options[:fq] = Array.wrap(options.delete(:fq))
112
77
 
113
78
  if options[:types]
114
- query[:fq] << Array(options[:types]).map {|type| "type:#{type}"}.join(" OR ")
79
+ options[:fq] << Array.wrap(options.delete(:types)).map {|type| "type:#{type}"}.join(" OR ")
115
80
  end
116
81
 
117
82
  Flare.log(<<-SOLR.squish)
118
83
  \e[4;32mSolr Query:\e[0;1m
119
- #{query[:q].join(', ')}
120
- #{"(#{query[:fq].join(' AND ')})," if query[:fq] }
121
- sort: #{query[:sort]}
122
- start: #{query[:start]},
123
- rows: #{query[:rows]}
84
+ #{options[:q].join(', ')}
85
+ #{"(#{options[:fq].join(' AND ')})," if options[:fq] }
86
+ sort: #{options[:sort]}
87
+ start: #{options[:start]},
88
+ rows: #{options[:rows]}
124
89
  SOLR
125
90
 
126
- response = connection.select(query)
127
- response[:request] = query
128
- response[:request][:page] = options[:page]
129
- response[:request][:per_page] = options[:per_page]
91
+ response = connection.select(options)
92
+ response[:request] = options
93
+ response[:request][:page] = options[:start] + 1
94
+ response[:request][:per_page] = options[:rows]
130
95
 
131
96
  response.with_indifferent_access
132
97
  end
133
-
98
+
134
99
  def ensure_searchable(*objects)
135
100
  Array(objects).flatten.select { |object| object.class.searchable? }
136
101
  end
137
-
138
- def prepare_query(query)
139
- query[:page] ||= query[:page] ? query[:page].to_i : 1
140
- query[:per_page] ||= PER_PAGE
141
- query[:limit] ||= RESULT_LIMIT
142
- query[:fields] ||= '* score'
143
- query
144
- end
145
-
102
+
146
103
  # I dont like this... Can we move it to hash if a library like ActiveSupport doesn't already have it?
147
104
  def symbolize_keys(hash)
148
105
  hash.inject({}){|result, (key, value)|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flare
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Dwan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-15 00:00:00 -05:00
12
+ date: 2010-05-20 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency