stellr 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ == 0.1.2 / 2008-08-21
2
+
3
+ * Add json serialization support to search results
4
+
1
5
  == 0.1.1 / 2008-08-06
2
6
 
3
7
  * Add support for bulk indexing of multiple records
@@ -18,7 +18,7 @@ require 'stellr/search'
18
18
  $SAFE = 1
19
19
 
20
20
  module Stellr
21
- VERSION = '0.1.1'
21
+ VERSION = '0.1.2'
22
22
 
23
23
  def self.start_server( config )
24
24
  if config.script
@@ -28,7 +28,7 @@ module Stellr
28
28
 
29
29
  if options[:page]
30
30
  results.current_page = options.delete(:page).to_i
31
- options[:limit] = results.per_page = options.delete(:per_page) || 10
31
+ options[:limit] = results.per_page = (options.delete(:per_page).to_i rescue nil) || 10
32
32
  options[:offset] = (p = results.current_page - 1) <= 0 ? 0 : p * results.per_page
33
33
  end
34
34
 
@@ -1,2 +1,3 @@
1
+ require 'json'
1
2
  require 'stellr/search/search_result'
2
3
  require 'stellr/search/search_results'
@@ -16,6 +16,14 @@ module Stellr
16
16
  @field_data[name]
17
17
  end
18
18
  alias [] field
19
+
20
+ def to_json
21
+ {
22
+ :doc_id => @doc_id,
23
+ :score => @score,
24
+ :data => @field_data
25
+ }.to_json
26
+ end
19
27
  end
20
28
  end
21
29
  end
@@ -9,6 +9,15 @@ module Stellr
9
9
  def initialize
10
10
  @results = []
11
11
  end
12
+
13
+ def to_json
14
+ {
15
+ :results => @results,
16
+ :total_hits => total_hits,
17
+ :current_page => current_page,
18
+ :per_page => per_page
19
+ }.to_json
20
+ end
12
21
 
13
22
  def method_missing(symbol, *args, &block)
14
23
  @results.send(symbol, *args, &block)
@@ -68,8 +68,7 @@ module Stellr
68
68
  #
69
69
  #
70
70
  def register( name, options = {} )
71
- raise "invalid collection name >#{name}<, may only contain a-zA-Z0-9_-" unless name =~ /^([a-zA-Z0-9_-]+)$/
72
- name.untaint
71
+ untaint_collection_name name
73
72
  @collections.synchronize do
74
73
  collection = (@collections[name] ||= create_collection( name, options ))
75
74
  save_collection_config name, options unless options.nil? or options.empty?
@@ -138,13 +137,25 @@ module Stellr
138
137
 
139
138
  def load_collection_config( name )
140
139
  path = collection_config_path name
141
- conf = YAML.load( File.read(path) ) if File.readable?(path) rescue nil
140
+ @logger.debug "trying to load collection config from #{path}"
141
+ conf = begin
142
+ YAML.load( File.read(path) ) if File.readable?(path)
143
+ rescue
144
+ @logger.error "error loading config: #{$!}\n#{$!.backtrace.join "\n"}"
145
+ nil
146
+ end
142
147
  @logger.info "loaded collection config from #{path}" unless conf.nil?
143
148
  return conf
144
149
  end
145
150
 
146
151
  def collection_config_path( name )
147
- File.join @config.conf_dir, "#{name}.yml"
152
+ untaint_collection_name name
153
+ File.join @config.conf_dir, "#{name.untaint}.yml"
154
+ end
155
+
156
+ def untaint_collection_name(name)
157
+ raise "invalid collection name >#{name}<, may only contain a-zA-Z0-9_-" unless name =~ /^([a-zA-Z0-9_-]+)$/
158
+ name.untaint
148
159
  end
149
160
 
150
161
  # called by shutdown
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Krause
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-08-13 00:00:00 +02:00
13
+ date: 2008-08-21 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency