flare 1.4.4 → 1.6.1
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/.gitignore +2 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/flare.rb +11 -2
- data/lib/flare/active_record.rb +2 -0
- data/lib/flare/collection.rb +22 -4
- data/lib/flare/session.rb +19 -7
- data/lib/flare/tasks.rb +5 -0
- metadata +3 -5
- data/flare.gemspec +0 -66
- data/lib/flare/configuration.rb +0 -76
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ begin
|
|
10
10
|
gem.email = "mpdwan@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/michaeldwan/flare"
|
12
12
|
gem.authors = ["Michael Dwan"]
|
13
|
-
gem.add_dependency('rsolr', '0.
|
13
|
+
gem.add_dependency('rsolr', '0.11.0')
|
14
14
|
gem.add_dependency('escape', '>= 0.0.4')
|
15
15
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
16
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.6.1
|
data/lib/flare.rb
CHANGED
@@ -7,7 +7,7 @@ rescue LoadError
|
|
7
7
|
require 'rsolr'
|
8
8
|
end
|
9
9
|
|
10
|
-
%w(
|
10
|
+
%w(collection index_builder session active_record).each do |file|
|
11
11
|
require File.join(File.dirname(__FILE__), 'flare', file)
|
12
12
|
end
|
13
13
|
|
@@ -15,8 +15,17 @@ ActiveRecord::Base.send(:include, Flare::ActiveRecord)
|
|
15
15
|
|
16
16
|
module Flare
|
17
17
|
class << self
|
18
|
+
|
19
|
+
attr_reader :solr_url
|
20
|
+
|
21
|
+
def solr=(value)
|
22
|
+
@session = Flare::Session.new(value)
|
23
|
+
end
|
24
|
+
|
18
25
|
def session
|
19
|
-
@session
|
26
|
+
return @session if @session
|
27
|
+
self.solr = "http://127.0.0.1:8983/solr"
|
28
|
+
@session
|
20
29
|
end
|
21
30
|
|
22
31
|
def indexed_models
|
data/lib/flare/active_record.rb
CHANGED
@@ -29,6 +29,7 @@ module Flare
|
|
29
29
|
module ClassMethods
|
30
30
|
def search_for_ids(*args)
|
31
31
|
options = args.extract_options!
|
32
|
+
options.except!(:include)
|
32
33
|
options[:types] ||= []
|
33
34
|
options[:types] << self
|
34
35
|
Flare.session.search_for_ids(*[args, options].flatten)
|
@@ -43,6 +44,7 @@ module Flare
|
|
43
44
|
|
44
45
|
def search_count(*args)
|
45
46
|
options = args.extract_options!
|
47
|
+
options.except!(:include)
|
46
48
|
options[:types] ||= []
|
47
49
|
options[:types] << self
|
48
50
|
Flare.session.count(*[args, options].flatten)
|
data/lib/flare/collection.rb
CHANGED
@@ -20,11 +20,15 @@ module Flare
|
|
20
20
|
# raise response.inspect
|
21
21
|
collection = self.new(page, per_page, response['response']['numFound'] || 0)
|
22
22
|
collection.response = response
|
23
|
-
collection.replace(instantiate_objects(response))
|
23
|
+
collection.replace(instantiate_objects(response, options))
|
24
24
|
return collection
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
27
|
+
def max_pages=(value)
|
28
|
+
@total_pages = value if value < @total_pages
|
29
|
+
end
|
30
|
+
|
31
|
+
def previous_page
|
28
32
|
current_page > 1 ? (current_page - 1) : nil
|
29
33
|
end
|
30
34
|
|
@@ -37,11 +41,25 @@ module Flare
|
|
37
41
|
end
|
38
42
|
|
39
43
|
private
|
40
|
-
def self.instantiate_objects(response)
|
44
|
+
def self.instantiate_objects(response, options = {})
|
45
|
+
types = Hash.new{|h, k| h[k] = []}
|
46
|
+
results = Hash.new{|h, k| h[k] = {}}
|
41
47
|
response['response']['docs'].map do |doc|
|
42
48
|
type, id = doc['id'].split(':')
|
43
|
-
type
|
49
|
+
types[type] << id
|
50
|
+
end
|
51
|
+
|
52
|
+
types.each do |type, ids|
|
53
|
+
includes = options[:include]
|
54
|
+
type.constantize.find_all_by_id(ids, :include => includes).each do |item|
|
55
|
+
results[type][item.id] = item
|
56
|
+
end
|
44
57
|
end
|
58
|
+
|
59
|
+
response['response']['docs'].map do |doc|
|
60
|
+
type, id = doc['id'].split(':')
|
61
|
+
results[type][id.to_i]
|
62
|
+
end.compact
|
45
63
|
end
|
46
64
|
end
|
47
65
|
end
|
data/lib/flare/session.rb
CHANGED
@@ -3,20 +3,26 @@ module Flare
|
|
3
3
|
RESULT_LIMIT = 1000
|
4
4
|
PER_PAGE = 16
|
5
5
|
|
6
|
-
def
|
7
|
-
@connection
|
6
|
+
def initialize(url)
|
7
|
+
@connection = RSolr.connect(:url => url)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
|
+
attr_reader :connection
|
11
|
+
|
10
12
|
delegate :commit, :optimize, :to => :connection
|
11
13
|
|
12
14
|
def search_for_ids(*args)
|
15
|
+
options = args.extract_options!
|
16
|
+
ar_options = { :include => options.delete(:include) }
|
13
17
|
response = execute(*args)
|
14
18
|
Flare::Collection.ids_from_response(response, response[:request][:page], response[:request][:per_page], response[:request])
|
15
19
|
end
|
16
20
|
|
17
21
|
def search(*args)
|
18
|
-
|
19
|
-
|
22
|
+
options = args.extract_options!
|
23
|
+
ar_options = { :include => options.delete(:include) }
|
24
|
+
response = execute(options)
|
25
|
+
Flare::Collection.create_from_response(response, response[:request][:page], response[:request][:per_page], ar_options)
|
20
26
|
end
|
21
27
|
|
22
28
|
def count(*args)
|
@@ -26,7 +32,8 @@ module Flare
|
|
26
32
|
def index(*objects)
|
27
33
|
objects = ensure_searchable(objects)
|
28
34
|
objects.collect(&:to_solr_doc).each do |doc|
|
29
|
-
connection.update(RSolr::Message::Generator.new.add(doc[:fields], doc[:attributes]))
|
35
|
+
# connection.update(RSolr::Message::Generator.new.add(doc[:fields], doc[:attributes]))
|
36
|
+
connection.update(RSolr::Message::Builder.new.add(doc[:fields], doc[:attributes]))
|
30
37
|
# connection.add(doc[:fields], doc[:attributes])
|
31
38
|
end
|
32
39
|
end
|
@@ -61,7 +68,7 @@ module Flare
|
|
61
68
|
def execute(*args)
|
62
69
|
options = args.extract_options!
|
63
70
|
|
64
|
-
options.assert_valid_keys(:q, :fq, :types, :page, :per_page, :limit, :fl, :sort, :facet, :mlt)
|
71
|
+
options.assert_valid_keys(:q, :fq, :types, :page, :per_page, :limit, :fl, :sort, :facet, :mlt, :mm)
|
65
72
|
|
66
73
|
options.reverse_merge!({
|
67
74
|
:page => 1,
|
@@ -96,6 +103,11 @@ module Flare
|
|
96
103
|
if options[:mlt]
|
97
104
|
query['mlt'] = true
|
98
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]
|
99
111
|
end
|
100
112
|
|
101
113
|
if options[:types]
|
data/lib/flare/tasks.rb
CHANGED
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.
|
4
|
+
version: 1.6.1
|
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-
|
12
|
+
date: 2010-04-15 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.11.0
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: escape
|
@@ -58,11 +58,9 @@ files:
|
|
58
58
|
- README.rdoc
|
59
59
|
- Rakefile
|
60
60
|
- VERSION
|
61
|
-
- flare.gemspec
|
62
61
|
- lib/flare.rb
|
63
62
|
- lib/flare/active_record.rb
|
64
63
|
- lib/flare/collection.rb
|
65
|
-
- lib/flare/configuration.rb
|
66
64
|
- lib/flare/index_builder.rb
|
67
65
|
- lib/flare/session.rb
|
68
66
|
- lib/flare/tasks.rb
|
data/flare.gemspec
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{flare}
|
8
|
-
s.version = "1.4.4"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Michael Dwan"]
|
12
|
-
s.date = %q{2010-02-15}
|
13
|
-
s.description = %q{This needs to get updated}
|
14
|
-
s.email = %q{mpdwan@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"flare.gemspec",
|
27
|
-
"lib/flare.rb",
|
28
|
-
"lib/flare/active_record.rb",
|
29
|
-
"lib/flare/collection.rb",
|
30
|
-
"lib/flare/configuration.rb",
|
31
|
-
"lib/flare/index_builder.rb",
|
32
|
-
"lib/flare/session.rb",
|
33
|
-
"lib/flare/tasks.rb",
|
34
|
-
"test/helper.rb",
|
35
|
-
"test/test_flare.rb"
|
36
|
-
]
|
37
|
-
s.homepage = %q{http://github.com/michaeldwan/flare}
|
38
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
-
s.require_paths = ["lib"]
|
40
|
-
s.rubygems_version = %q{1.3.5}
|
41
|
-
s.summary = %q{This needs to get updated}
|
42
|
-
s.test_files = [
|
43
|
-
"test/helper.rb",
|
44
|
-
"test/test_flare.rb"
|
45
|
-
]
|
46
|
-
|
47
|
-
if s.respond_to? :specification_version then
|
48
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
-
s.specification_version = 3
|
50
|
-
|
51
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
-
s.add_runtime_dependency(%q<rsolr>, ["= 0.12.1"])
|
53
|
-
s.add_runtime_dependency(%q<escape>, [">= 0.0.4"])
|
54
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
55
|
-
else
|
56
|
-
s.add_dependency(%q<rsolr>, ["= 0.12.1"])
|
57
|
-
s.add_dependency(%q<escape>, [">= 0.0.4"])
|
58
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
59
|
-
end
|
60
|
-
else
|
61
|
-
s.add_dependency(%q<rsolr>, ["= 0.12.1"])
|
62
|
-
s.add_dependency(%q<escape>, [">= 0.0.4"])
|
63
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
data/lib/flare/configuration.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Flare
|
4
|
-
class Configuration
|
5
|
-
class << self
|
6
|
-
attr_reader :client, :server
|
7
|
-
|
8
|
-
def server(reload = false)
|
9
|
-
@server = nil if reload
|
10
|
-
@server ||= Server.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def client(reload = false)
|
14
|
-
@client = nil if reload
|
15
|
-
@client = Client.new
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
class Server
|
21
|
-
def initialize
|
22
|
-
@config = YAML::load_file(File.join(Rails.root, 'config', 'solr.yml'))[Rails.env]
|
23
|
-
end
|
24
|
-
|
25
|
-
def port
|
26
|
-
@port ||= (@config['port'] || 8983).to_i
|
27
|
-
end
|
28
|
-
|
29
|
-
def log_dir
|
30
|
-
@log_dir ||= File.expand_path(@config['log_dir'] || 'log')
|
31
|
-
end
|
32
|
-
|
33
|
-
def log_level
|
34
|
-
@log_level ||= @config['log_level'] || 'INFO'
|
35
|
-
end
|
36
|
-
|
37
|
-
def data_dir
|
38
|
-
@data_dir ||= File.expand_path(@config['data_dir'] || File.join('solr', 'data', Rails.env))
|
39
|
-
end
|
40
|
-
|
41
|
-
def solr_home
|
42
|
-
@solr_home ||= File.expand_path(@config['solr_home'] || File.join(File.dirname(__FILE__), '..', '..', 'solr', 'solr'))
|
43
|
-
end
|
44
|
-
|
45
|
-
def pid_dir
|
46
|
-
@pid_dir ||= File.expand_path(@config['pid_dir'] || 'tmp/pids')
|
47
|
-
end
|
48
|
-
|
49
|
-
def jvm_options
|
50
|
-
@jvm_options ||= @config['jvm_options']
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
class Client
|
55
|
-
def initialize
|
56
|
-
@config = YAML::load_file(File.join(Rails.root, 'config', 'flare.yml'))[Rails.env]
|
57
|
-
end
|
58
|
-
|
59
|
-
def port
|
60
|
-
@port ||= (@config['port'] || 8983).to_i
|
61
|
-
end
|
62
|
-
|
63
|
-
def host
|
64
|
-
@host ||= @config['host'] || '127.0.0.1'
|
65
|
-
end
|
66
|
-
|
67
|
-
def path
|
68
|
-
@path ||= @config['path'] || 'solr'
|
69
|
-
end
|
70
|
-
|
71
|
-
def url
|
72
|
-
@url ||= "http://#{host}:#{port}/#{path}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|