moonstone 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -27,7 +27,7 @@ spec = Gem::Specification.new { |s|
27
27
  s.name = 'moonstone'
28
28
  s.summary = "Moonstone Agile Search Framework"
29
29
  deps.each &s.method(:add_dependency)
30
- s.version = '0.6.0'
30
+ s.version = '0.6.1'
31
31
  }
32
32
 
33
33
  Rake::GemPackageTask.new(spec) { |pkg|
@@ -2,7 +2,8 @@ module Moonstone
2
2
  class Engine
3
3
  include Lucene::Index
4
4
  include Lucene::Search
5
-
5
+ include Lucene::Document
6
+
6
7
  attr_reader :store, :similarity
7
8
 
8
9
  # :store should be a String or some kind of Lucene::Store::Directory
@@ -105,6 +106,13 @@ module Moonstone
105
106
  delete_documents([term])
106
107
  end
107
108
 
109
+ def optimize
110
+ IndexWriter.open(@store, analyzer) do |writer|
111
+ writer.optimize
112
+ end
113
+ refresh_searcher
114
+ end
115
+
108
116
  # Takes any kind of input object parsable by your #create_query method. Quack.
109
117
  # Options patterns (see javadoc for org.apache.lucene.search.Searcher):
110
118
  # Returns a TopDocs object
@@ -143,13 +151,19 @@ module Moonstone
143
151
  # Returns an instance of the Analyzer class defined within
144
152
  # this class's namespace.
145
153
  def analyzer
146
- @analyzer ||= self.class::Analyzer.new
154
+ @analyzer ||= (defined?(self.class::Analyzer) ? self.class::Analyzer.new : Lucene::Analysis::StandardAnalyzer.new )
155
+ end
156
+
157
+ # Analyze and index all fields.
158
+ # Override this method for custom behavior.
159
+ def doc_from(record)
160
+ Doc.create(record)
147
161
  end
148
162
 
149
163
  # Opens an IndexWriter for the duration of the block.
150
164
  # engine.writer { |w| w.add_document(doc) }
151
165
  def writer
152
- IndexWriter.open(@store, self.class::Analyzer.new) do |writer|
166
+ IndexWriter.open(@store, analyzer) do |writer|
153
167
  writer.set_similarity(@similarity.new) if @similarity
154
168
  yield writer
155
169
  end
@@ -0,0 +1,39 @@
1
+ module Moonstone
2
+ module Racker
3
+ module LocalClient
4
+
5
+ def search(topic, location, options={})
6
+ raise "Unable to use supplied location: #{location}" unless loc = geo(location)
7
+ query = {:input => topic, :lat => loc['latitude'].to_s, :lon => loc['longitude'].to_s}
8
+ r = HTTParty.get("#{uri}/search.json", :query => query)
9
+ hash = {}
10
+ r.each { |k,v| hash[k] = v }
11
+ hash['location'] = loc
12
+ hash
13
+ rescue Errno::ECONNREFUSED
14
+ {}
15
+ end
16
+
17
+ def geo(location)
18
+ lat = location['lat'] || location['latitude'] || location['LAT'] ||
19
+ location[:lat] || location[:latitude]
20
+ lon = location['lon'] || location['long'] || location['LON'] ||
21
+ location['longitude'] || location[:lon] ||
22
+ location[:long] || location[:longitude]
23
+ {'latitude' => lat, "longitude" => lon} if lat && lon
24
+ end
25
+
26
+ def index_info
27
+ HTTParty.get("#{uri}/index_info.json")
28
+ rescue Errno::ECONNREFUSED
29
+ {}
30
+ end
31
+
32
+ def details(id)
33
+ HTTParty.get("#{uri}/document.json", :query => {:id => id})
34
+ rescue Errno::ECONNREFUSED
35
+ {}
36
+ end
37
+ end
38
+ end
39
+ end
@@ -5,7 +5,7 @@ module Moonstone
5
5
  include Moonstone::Racker
6
6
 
7
7
  def json_GET_search(request)
8
- args = request.params.values_at('input', 'lat', 'lon')
8
+ args = request.params.values_at('topic', 'lat', 'lon')
9
9
  options = search_options(request)
10
10
  args << options
11
11
  t = Time.now
@@ -20,7 +20,7 @@ module Moonstone
20
20
  def json_POST_search(request)
21
21
  options = search_options(request)
22
22
  data = request.env['rack.input'].read
23
- JSON.parse(data).map do |input, lat, lon|
23
+ JSON.parse(data).map do |topic, lat, lon|
24
24
  t = Time.now
25
25
  results = search(input, lat, lon, options).to_hash
26
26
  results[:time] = Time.now - t
metadata CHANGED
@@ -1,91 +1,89 @@
1
1
  --- !ruby/object:Gem::Specification
2
+ name: moonstone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew King
8
+ - Jason Rush
9
+ - Jay Donnell
10
+ - Dan Yoder
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+
15
+ date: 2009-11-27 00:00:00 -07:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: rspec
20
+ type: :runtime
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: "0"
27
+ version:
28
+ description:
29
+ email: self@automatthew.com
30
+ executables: []
31
+
2
32
  extensions: []
3
33
 
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - lib/moonstone.rb
38
+ - lib/jar/lucene-core-2.4.0.jar
39
+ - lib/jar/lucene-spellchecker-2.4-dev.jar
40
+ - lib/lucene/analysis.rb
41
+ - lib/lucene/document.rb
42
+ - lib/lucene/function.rb
43
+ - lib/lucene/index.rb
44
+ - lib/lucene/query_parser.rb
45
+ - lib/lucene/search.rb
46
+ - lib/lucene/store.rb
47
+ - lib/moonstone/analyzer.rb
48
+ - lib/moonstone/engine.rb
49
+ - lib/moonstone/filter.rb
50
+ - lib/moonstone/index_inspection.rb
51
+ - lib/moonstone/multi_analyzer.rb
52
+ - lib/moonstone/queued_filter.rb
53
+ - lib/moonstone/racker.rb
54
+ - lib/moonstone/tokenizer.rb
55
+ - lib/moonstone/filters/synonymer.rb
56
+ - lib/moonstone/racker/basic_search.rb
57
+ - lib/moonstone/racker/client.rb
58
+ - lib/moonstone/racker/local_search.rb
59
+ - Rakefile
60
+ has_rdoc: true
4
61
  homepage:
5
- executables: []
62
+ licenses: []
6
63
 
7
- version: !ruby/object:Gem::Version
8
- version: 0.6.0
9
64
  post_install_message:
10
- date: 2009-06-16 07:00:00 +00:00
11
- files:
12
- - lib/jar
13
- - lib/lucene
14
- - lib/moonstone
15
- - lib/moonstone.rb
16
- - lib/jar/lucene-core-2.4.0.jar
17
- - lib/jar/lucene-spellchecker-2.4-dev.jar
18
- - lib/lucene/analysis.rb
19
- - lib/lucene/document.rb
20
- - lib/lucene/function.rb
21
- - lib/lucene/index.rb
22
- - lib/lucene/query_parser.rb
23
- - lib/lucene/search.rb
24
- - lib/lucene/store.rb
25
- - lib/moonstone/analyzer.rb
26
- - lib/moonstone/engine.rb
27
- - lib/moonstone/filter.rb
28
- - lib/moonstone/filters
29
- - lib/moonstone/index_inspection.rb
30
- - lib/moonstone/multi_analyzer.rb
31
- - lib/moonstone/queued_filter.rb
32
- - lib/moonstone/racker
33
- - lib/moonstone/racker.rb
34
- - lib/moonstone/tokenizer.rb
35
- - lib/moonstone/filters/synonymer.rb
36
- - lib/moonstone/racker/basic_search.rb
37
- - lib/moonstone/racker/local_search.rb
38
- - Rakefile
39
- rubygems_version: 1.3.1
40
65
  rdoc_options: []
41
66
 
42
- signing_key:
43
- cert_chain: []
44
-
45
- name: moonstone
46
- has_rdoc: true
47
- platform: ruby
48
- summary: Moonstone Agile Search Framework
49
- default_executable:
50
- bindir: bin
51
- required_rubygems_version: !ruby/object:Gem::Requirement
52
- version:
53
- requirements:
54
- - - '>='
55
- - !ruby/object:Gem::Version
56
- version: "0"
67
+ require_paths:
68
+ - lib
57
69
  required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
58
74
  version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
76
  requirements:
60
- - - '>='
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- require_paths:
64
- - lib
65
- specification_version: 2
66
- test_files: []
67
-
68
- dependencies:
69
- - !ruby/object:Gem::Dependency
70
- type: :runtime
71
- name: rspec
72
- version_requirement:
73
- version_requirements: !ruby/object:Gem::Requirement
74
- version:
75
- requirements:
76
- - - '>='
77
+ - - ">="
77
78
  - !ruby/object:Gem::Version
78
79
  version: "0"
79
- description:
80
- email: self@automatthew.com
81
- authors:
82
- - Matthew King
83
- - Jason Rush
84
- - Jay Donnell
85
- - Dan Yoder
86
- extra_rdoc_files: []
87
-
80
+ version:
88
81
  requirements: []
89
82
 
90
83
  rubyforge_project:
91
- autorequire:
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Moonstone Agile Search Framework
88
+ test_files: []
89
+