xapian_db 0.5.0 → 0.5.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/CHANGELOG.md +10 -0
- data/README.rdoc +12 -6
- data/lib/xapian_db/adapters/base_adapter.rb +26 -0
- data/lib/xapian_db/document_blueprint.rb +7 -0
- metadata +23 -8
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
##0.5.1 (December 22th, 2010)
|
2
|
+
|
3
|
+
Features:
|
4
|
+
|
5
|
+
- simple facet support for indexed classes. Any attribute can be used in a facet search
|
6
|
+
|
7
|
+
Fixes:
|
8
|
+
|
9
|
+
- attribute names that match a Xapian::Document method are not allowed
|
10
|
+
|
1
11
|
##0.5.0 (December 19th, 2010)
|
2
12
|
|
3
13
|
Features:
|
data/README.rdoc
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
== What's in the box?
|
4
4
|
|
5
|
-
XapianDb is a ruby gem that combines features of nosql databases and fulltext indexing into one piece. The result: Rich documents and very fast queries.
|
6
|
-
It is based on {Xapian}[http://xapian.org/], an efficient and powerful indexing library.
|
7
|
-
The gem is in very early development and not production ready yet.
|
5
|
+
XapianDb is a ruby gem that combines features of nosql databases and fulltext indexing into one piece. The result: Rich documents and very fast queries. It is based on {Xapian}[http://xapian.org/], an efficient and powerful indexing library.
|
8
6
|
|
9
7
|
XapianDb is inspired by {xapian-fu}[https://github.com/johnl/xapian-fu] and {xapit}[https://github.com/ryanb/xapit].
|
10
8
|
Thank you John and Ryan for your great work. It helped me learning to understand the xapian library and I borrowed an idea
|
@@ -133,7 +131,7 @@ Use blocks for complex evaluations of attributes or indexed values:
|
|
133
131
|
end
|
134
132
|
end
|
135
133
|
|
136
|
-
place these configurations either into the
|
134
|
+
place these configurations either into the corresponding class or - I prefer to have the index configurations outside
|
137
135
|
the models - into the file config/xapian_blueprints.rb.
|
138
136
|
|
139
137
|
=== Update the index
|
@@ -209,7 +207,7 @@ Use a search result with will_paginate in a view:
|
|
209
207
|
|
210
208
|
=== Facets
|
211
209
|
|
212
|
-
If you want to implement a simple drilldown for your searches, you can use a facets query:
|
210
|
+
If you want to implement a simple drilldown for your searches, you can use a global facets query:
|
213
211
|
|
214
212
|
search_expression = "Foo"
|
215
213
|
facets = XapianDb.facets(search_expression)
|
@@ -220,7 +218,15 @@ If you want to implement a simple drilldown for your searches, you can use a fac
|
|
220
218
|
# doc = klass.search search_expression
|
221
219
|
end
|
222
220
|
|
223
|
-
|
221
|
+
A global facet search always groups the results by the class of the indexed objects. There is a class level facet query syntax available, too:
|
222
|
+
|
223
|
+
search_expression = "Foo"
|
224
|
+
facets = Person.facets(:name, search_expression)
|
225
|
+
facets.each do |name, count|
|
226
|
+
puts "#{name}: #{count} hits"
|
227
|
+
end
|
228
|
+
|
229
|
+
At the class level, any attribute can be used for a facet query.
|
224
230
|
|
225
231
|
== Production setup
|
226
232
|
|
@@ -46,6 +46,32 @@ module XapianDb
|
|
46
46
|
result
|
47
47
|
end
|
48
48
|
|
49
|
+
# Add a method to search atribute facets of this class
|
50
|
+
define_singleton_method(:facets) do |attr_name, expression|
|
51
|
+
|
52
|
+
# return an empty hash if no search expression is given
|
53
|
+
return {} if expression.nil? || expression.strip.empty?
|
54
|
+
|
55
|
+
class_scope = "indexed_class:#{klass.name.downcase}"
|
56
|
+
blueprint = XapianDb::DocumentBlueprint.blueprint_for klass
|
57
|
+
value_index = blueprint.value_index_for attr_name.to_sym
|
58
|
+
|
59
|
+
query_parser = QueryParser.new(XapianDb.database)
|
60
|
+
query = query_parser.parse("#{class_scope} and (#{expression})")
|
61
|
+
enquiry = Xapian::Enquire.new(XapianDb.database.reader)
|
62
|
+
enquiry.query = query
|
63
|
+
enquiry.collapse_key = value_index
|
64
|
+
facets = {}
|
65
|
+
enquiry.mset(0, XapianDb.database.size).matches.each do |match|
|
66
|
+
facet_value = YAML::load match.document.values[value_index].value
|
67
|
+
# We must add 1 to the collapse_count since collapse_count means
|
68
|
+
# "how many other matches are there?"
|
69
|
+
facets[facet_value] = match.collapse_count + 1
|
70
|
+
end
|
71
|
+
facets
|
72
|
+
|
73
|
+
end
|
74
|
+
|
49
75
|
end
|
50
76
|
end
|
51
77
|
end
|
@@ -182,6 +182,7 @@ module XapianDb
|
|
182
182
|
# end
|
183
183
|
# @todo Make sure the name does not collide with a method name of Xapian::Document
|
184
184
|
def attribute(name, options={}, &block)
|
185
|
+
raise ArgumentError.new("You cannot use #{name} as an attribute name since it is a reserved method name of Xapian::Document") if reserved_method_name?(name)
|
185
186
|
opts = {:index => true}.merge(options)
|
186
187
|
if block_given?
|
187
188
|
@attributes_hash[name] = block
|
@@ -197,6 +198,7 @@ module XapianDb
|
|
197
198
|
# @todo Make sure the name does not collide with a method name of Xapian::Document
|
198
199
|
def attributes(*attributes)
|
199
200
|
attributes.each do |attr|
|
201
|
+
raise ArgumentError.new("You cannot use #{attr} as an attribute name since it is a reserved method name of Xapian::Document") if reserved_method_name?(attr)
|
200
202
|
@attributes_hash[attr] = nil
|
201
203
|
self.index attr
|
202
204
|
end
|
@@ -258,6 +260,11 @@ module XapianDb
|
|
258
260
|
end
|
259
261
|
end
|
260
262
|
|
263
|
+
# Check if the attribute name does not collide with a method name of Xapian::Document
|
264
|
+
def reserved_method_name?(attr_name)
|
265
|
+
@reserved_method_names ||= Xapian::Document.instance_methods
|
266
|
+
@reserved_method_names.include?(attr_name.to_sym)
|
267
|
+
end
|
261
268
|
end
|
262
269
|
|
263
270
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 1
|
9
|
+
version: 0.5.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Gernot Kogler
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-22 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,9 +27,9 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 2
|
30
|
+
- 3
|
30
31
|
- 1
|
31
|
-
|
32
|
-
version: 2.1.0
|
32
|
+
version: 2.3.1
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -43,11 +43,26 @@ dependencies:
|
|
43
43
|
segments:
|
44
44
|
- 0
|
45
45
|
- 3
|
46
|
-
-
|
47
|
-
version: 0.3.
|
46
|
+
- 7
|
47
|
+
version: 0.3.7
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
|
-
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: beanstalk-client
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 1
|
60
|
+
- 1
|
61
|
+
- 0
|
62
|
+
version: 1.1.0
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
description: XapianDb is a ruby gem that combines features of nosql databases and fulltext indexing. It is based on Xapian, an efficient and powerful indexing library
|
51
66
|
email: gernot.kogler (at) garaio (dot) com
|
52
67
|
executables: []
|
53
68
|
|