cheap_skate 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cheap_skate/application.rb +1 -1
- data/lib/cheap_skate/index.rb +9 -6
- data/lib/cheap_skate/models.rb +5 -4
- data/lib/cheap_skate/schema.rb +5 -1
- metadata +3 -3
data/lib/cheap_skate/index.rb
CHANGED
@@ -54,7 +54,7 @@ module CheapSkate
|
|
54
54
|
writer.field_infos.add_field(field, opts)
|
55
55
|
end
|
56
56
|
|
57
|
-
def
|
57
|
+
def do_search(query, opts={})
|
58
58
|
results = ResultSet.new
|
59
59
|
results.offset = opts[:offset]
|
60
60
|
results.limit = opts[:limit]
|
@@ -73,9 +73,14 @@ module CheapSkate
|
|
73
73
|
opts[:filter_proc] = query.filter_proc
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
searcher = Ferret::Search::Searcher.new(self.reader)
|
77
|
+
hits = searcher.search(query.query, opts)
|
78
|
+
results.total = hits.total_hits
|
79
|
+
results.max_score = hits.max_score
|
80
|
+
hits.hits.each do |hit|
|
81
|
+
doc = @schema.typed_document(self[hit.doc])
|
82
|
+
doc[:score] = hit.score
|
83
|
+
results << doc
|
79
84
|
end
|
80
85
|
if query.respond_to?(:facet_fields)
|
81
86
|
facets = {}
|
@@ -95,7 +100,6 @@ module CheapSkate
|
|
95
100
|
end
|
96
101
|
|
97
102
|
def get_facets_from_index_terms(query)
|
98
|
-
puts query.facet_fields.inspect
|
99
103
|
query.facet_fields.keys.each do |field|
|
100
104
|
field_terms = reader.terms(field)
|
101
105
|
next unless field_terms
|
@@ -160,7 +164,6 @@ module CheapSkate
|
|
160
164
|
end
|
161
165
|
end
|
162
166
|
unless bool.to_s.empty?
|
163
|
-
puts "We did something here."
|
164
167
|
return Ferret::Search::QueryFilter.new(bool)
|
165
168
|
end
|
166
169
|
nil
|
data/lib/cheap_skate/models.rb
CHANGED
@@ -26,7 +26,7 @@ module CheapSkate
|
|
26
26
|
end
|
27
27
|
|
28
28
|
class ResultSet
|
29
|
-
attr_accessor :total, :docs, :query, :limit, :offset, :facets, :query_time, :nl_format
|
29
|
+
attr_accessor :total, :docs, :query, :limit, :offset, :facets, :query_time, :nl_format, :max_score
|
30
30
|
def <<(obj)
|
31
31
|
@docs ||=[]
|
32
32
|
@docs << obj
|
@@ -34,7 +34,8 @@ module CheapSkate
|
|
34
34
|
|
35
35
|
def to_hash()
|
36
36
|
response = {"responseHeader"=>{"status"=>0, "QTime"=>self.query_time, "params"=>{"q"=>self.query, "version"=>"2.2", "rows"=>self.limit}}}
|
37
|
-
response["response"] = {"numFound"=>self.total, "start"=>self.offset, "docs"=>[]}
|
37
|
+
response["response"] = {"numFound"=>self.total, "start"=>self.offset, "rows"=>docs.length, "docs"=>[]}
|
38
|
+
response["response"]["maxScore"] = self.max_score if self.max_score
|
38
39
|
if self.docs
|
39
40
|
self.docs.each do |doc|
|
40
41
|
response["response"]["docs"] << doc
|
@@ -121,8 +122,8 @@ module CheapSkate
|
|
121
122
|
map_arr = {}
|
122
123
|
@facet_fields.each_pair do |k,v|
|
123
124
|
map_arr[k] ||= {}
|
124
|
-
v.
|
125
|
-
map_arr[k][
|
125
|
+
v.each do |val_pair|
|
126
|
+
map_arr[k][val_pair[0]] = val_pair[1]
|
126
127
|
end
|
127
128
|
end
|
128
129
|
map_arr
|
data/lib/cheap_skate/schema.rb
CHANGED
@@ -154,7 +154,11 @@ module CheapSkate
|
|
154
154
|
lazy_doc.fields.each do |field|
|
155
155
|
[*lazy_doc[field]].each do |fld|
|
156
156
|
if doc[field]
|
157
|
-
|
157
|
+
if multi_valued?(field)
|
158
|
+
doc[field] = [*doc[field]]
|
159
|
+
else
|
160
|
+
doc[field] << "\n"
|
161
|
+
end
|
158
162
|
doc[field] << type_field(field, fld)
|
159
163
|
elsif multi_valued?(field)
|
160
164
|
doc[field] = [type_field(field, fld)]
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ross Singer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-02 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|