dm-lucene-adapter 0.1.0-java → 0.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dm-lucene-adapter.rb +17 -3
- data/lib/dm-lucene-adapter_ext.jar +0 -0
- data/lib/dm_lucene_adapter/dm_lucene_adapter.rb +10 -10
- data/spec/dm_lucene_adapter_spec.rb +6 -0
- data/spec/spec_helper.rb +6 -1
- metadata +8 -27
- data/MIT-LICENSE +0 -20
data/lib/dm-lucene-adapter.rb
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
require 'java'
|
2
2
|
begin
|
3
|
-
include_class "de.saumya.lucene.LuceneService"
|
4
|
-
rescue
|
5
3
|
require 'dm-lucene-adapter_ext'
|
6
|
-
|
4
|
+
include_class "de.saumya.lucene.LuceneService"
|
5
|
+
puts "using lucene from classpath"
|
6
|
+
rescue NameError => e
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'org.apache.lucene.lucene-core'
|
10
|
+
puts "using lucene from gem"
|
11
|
+
rescue LoadError => ee
|
12
|
+
LUCENE_VERSION = '3.0.0'
|
13
|
+
|
14
|
+
require "#{File.expand_path('~/')}/.m2/repository/org/apache/lucene/lucene-core/#{LUCENE_VERSION}/lucene-core-#{LUCENE_VERSION}.jar"
|
15
|
+
puts "using lucene from jar"
|
16
|
+
end
|
17
|
+
|
18
|
+
puts "load"
|
19
|
+
include_class "de.saumya.lucene.LuceneService"
|
7
20
|
end
|
21
|
+
|
8
22
|
require 'dm_lucene_adapter/dm_lucene_adapter'
|
Binary file
|
@@ -72,8 +72,7 @@ module DataMapper
|
|
72
72
|
def do_read(offset, limit, query)
|
73
73
|
reader = lucene(query.model).create_reader
|
74
74
|
if(query.conditions.nil?)
|
75
|
-
result = []
|
76
|
-
|
75
|
+
result = []
|
77
76
|
#p query
|
78
77
|
# TODO set limit, offset to default of sorting is non default
|
79
78
|
reader.read_all(offset, limit).each do |resource|
|
@@ -86,9 +85,9 @@ module DataMapper
|
|
86
85
|
result
|
87
86
|
else
|
88
87
|
ops = query.conditions.operands
|
89
|
-
if(ops.size == 1 && ops
|
88
|
+
if(ops.size == 1 && ops.first == :eql && ops.first.subject.name == :id)
|
90
89
|
map = {}
|
91
|
-
reader.read(query.conditions.operands
|
90
|
+
reader.read(query.conditions.operands.first.value).each do |k,v|
|
92
91
|
map[k] = v
|
93
92
|
end
|
94
93
|
[map]
|
@@ -117,11 +116,13 @@ module DataMapper
|
|
117
116
|
ops.each do |comp|
|
118
117
|
case comp.slug
|
119
118
|
when :like
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
comp.value.split(/\s/).each do |value|
|
120
|
+
lquery += "#{comp.subject.name.to_s}:#{value}"
|
121
|
+
unless comp.value =~ /%|_|\?|\*/
|
122
|
+
lquery += "~"
|
123
|
+
end
|
124
|
+
lquery += " #{operator} "
|
123
125
|
end
|
124
|
-
lquery += " #{operator} "
|
125
126
|
when :eql
|
126
127
|
lquery += "#{comp.subject.name.to_s}:\"#{comp.value}\" #{operator} "
|
127
128
|
when :not
|
@@ -150,7 +151,6 @@ module DataMapper
|
|
150
151
|
#
|
151
152
|
# @api semipublic
|
152
153
|
def update(attributes, collection)
|
153
|
-
count = 0
|
154
154
|
service = lucene(collection.model)
|
155
155
|
deleter = service.create_deleter
|
156
156
|
resources = read(collection.query)
|
@@ -167,7 +167,7 @@ module DataMapper
|
|
167
167
|
resource.each { |k,v| map[k.to_s] = v.to_s}
|
168
168
|
indexer.index(map)
|
169
169
|
end
|
170
|
-
|
170
|
+
resources.size
|
171
171
|
ensure
|
172
172
|
indexer.close if indexer
|
173
173
|
deleter.close if deleter
|
@@ -91,6 +91,12 @@ describe DataMapper::Adapters::LuceneAdapter do
|
|
91
91
|
@books.each { |b| b.author.should =~ /sanuka/ }
|
92
92
|
end
|
93
93
|
|
94
|
+
it 'should find 5 with fuzzy query on total' do
|
95
|
+
@books = Book.all(:total.like => "sanaku corner")
|
96
|
+
@books.size.should == @size + @len
|
97
|
+
@books.each { |b| b.author.should =~ /sanuka/ }
|
98
|
+
end
|
99
|
+
|
94
100
|
it 'should find 5 with single char wildcards query' do
|
95
101
|
@books = Book.all(:author.like => "san?k?")
|
96
102
|
@books.size.should == @size + @len
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
gem 'dm-core', ">0.10.0"
|
3
|
+
#gem 'dm-core', ">0.10.0"
|
4
4
|
require 'pathname'
|
5
5
|
$LOAD_PATH << Pathname(__FILE__).dirname.parent.expand_path + 'lib'
|
6
6
|
|
@@ -19,6 +19,11 @@ class Book
|
|
19
19
|
|
20
20
|
property :published, Boolean, :default => true
|
21
21
|
|
22
|
+
property :total, Text
|
23
|
+
|
24
|
+
before :save do
|
25
|
+
attribute_set(:total, "#{id} #{author} #{title} #{published}");
|
26
|
+
end
|
22
27
|
end
|
23
28
|
|
24
29
|
DataMapper.setup(:default, :adapter => :lucene, :path => "tmp")
|
metadata
CHANGED
@@ -1,39 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-lucene-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: java
|
6
|
-
authors:
|
7
|
-
|
6
|
+
authors:
|
7
|
+
- Kristian Meier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-29 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
name: dm-core
|
17
|
-
type: :runtime
|
18
|
-
version_requirement:
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
-
- - "="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.10.1
|
24
|
-
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: rspec
|
27
|
-
type: :development
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ~>
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "1.2"
|
34
|
-
version:
|
14
|
+
dependencies: []
|
15
|
+
|
35
16
|
description: datamapper adapter for search index lucene
|
36
17
|
email:
|
18
|
+
- m.kristian@web.de
|
37
19
|
executables: []
|
38
20
|
|
39
21
|
extensions: []
|
@@ -41,14 +23,13 @@ extensions: []
|
|
41
23
|
extra_rdoc_files: []
|
42
24
|
|
43
25
|
files:
|
44
|
-
- lib/dm-lucene-adapter.rb
|
45
26
|
- lib/dm-lucene-adapter_ext.jar
|
27
|
+
- lib/dm-lucene-adapter.rb
|
46
28
|
- lib/dm_lucene_adapter/dm_lucene_adapter.rb
|
47
29
|
- lib/dm_lucene_adapter/version.rb
|
48
30
|
- spec/dm_lucene_adapter_spec.rb
|
49
31
|
- spec/spec_helper.rb
|
50
32
|
- spec/spec.opts
|
51
|
-
- MIT-LICENSE
|
52
33
|
has_rdoc: true
|
53
34
|
homepage: http://github.com/mkristian/dm-lucene-adapter
|
54
35
|
licenses: []
|
data/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2008 Kristian Meier
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|