noodall-core 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/noodall/search.rb +16 -6
- data/noodall-core.gemspec +2 -2
- data/spec/node_spec.rb +32 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.7
|
data/lib/noodall/search.rb
CHANGED
@@ -24,6 +24,10 @@ module Noodall
|
|
24
24
|
def language(lang = 'en')
|
25
25
|
@language ||= lang
|
26
26
|
end
|
27
|
+
|
28
|
+
def stemmer
|
29
|
+
@stemmer ||= Lingua::Stemmer.new(:language => language)
|
30
|
+
end
|
27
31
|
|
28
32
|
def search(query, options = {})
|
29
33
|
if options[:per_page] || options[:per_page]
|
@@ -39,7 +43,11 @@ module Noodall
|
|
39
43
|
# Extract words from the query and clean up
|
40
44
|
words = query.downcase.split(/\W/) - STOPWORDS
|
41
45
|
words.reject!{|w| w.length < 3}
|
42
|
-
|
46
|
+
|
47
|
+
# add stemmed words to the array of words
|
48
|
+
words = stem(words) | words
|
49
|
+
|
50
|
+
criteria.merge!( :_keywords => { :$in => words } )
|
43
51
|
|
44
52
|
# The Search result
|
45
53
|
search_result = collection.map_reduce(search_map(words), search_reduce, {:query => criteria, :finalize => search_finalize})
|
@@ -63,6 +71,10 @@ module Noodall
|
|
63
71
|
docs.map! { |hash| load(hash['value']) }
|
64
72
|
end
|
65
73
|
end
|
74
|
+
|
75
|
+
def stem(words)
|
76
|
+
words.map { |word| stemmer.stem(word) }
|
77
|
+
end
|
66
78
|
|
67
79
|
def search_map(words)
|
68
80
|
#convert words into Regex OR
|
@@ -90,22 +102,20 @@ module Noodall
|
|
90
102
|
module InstanceMethods
|
91
103
|
protected
|
92
104
|
def _update_keywords
|
93
|
-
s = Lingua::Stemmer.new(:language => self.class.language)
|
94
|
-
|
95
105
|
self._keywords = []
|
96
106
|
|
97
107
|
self.class.searchable_keys.each do |search_key|
|
98
|
-
self._keywords += keywords_for_value(
|
108
|
+
self._keywords += keywords_for_value(send(search_key)).compact
|
99
109
|
end
|
100
110
|
end
|
101
111
|
|
102
112
|
private
|
103
|
-
def keywords_for_value(
|
113
|
+
def keywords_for_value(val)
|
104
114
|
if val.kind_of?(String)
|
105
115
|
words = val.downcase.split(/\W/) - STOPWORDS
|
106
116
|
words.reject!{|w| w.length < 3}
|
107
117
|
words.map do |word|
|
108
|
-
stem = stemmer.stem(word)
|
118
|
+
stem = self.class.stemmer.stem(word)
|
109
119
|
if stem != word
|
110
120
|
[stem, word]
|
111
121
|
else
|
data/noodall-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{noodall-core}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Steve England"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-17}
|
13
13
|
s.description = %q{Core data objects for Noodall}
|
14
14
|
s.email = %q{steve@wearebeef.co.uk}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/node_spec.rb
CHANGED
@@ -329,6 +329,38 @@ describe Noodall::Node do
|
|
329
329
|
|
330
330
|
results.should have(0).things
|
331
331
|
end
|
332
|
+
|
333
|
+
describe "creating keywords" do
|
334
|
+
|
335
|
+
it "should create keywords" do
|
336
|
+
page = Factory(:page, :title => "I like to teach")
|
337
|
+
page._keywords.should include("teach")
|
338
|
+
|
339
|
+
page = Factory(:page, :title => "I am going to be teaching")
|
340
|
+
page._keywords.should include("teach")
|
341
|
+
|
342
|
+
page = Factory(:page, :title => "The way he teaches is terrible")
|
343
|
+
page._keywords.should include("teach")
|
344
|
+
end
|
345
|
+
|
346
|
+
end
|
347
|
+
|
348
|
+
describe "stemmed searching" do
|
349
|
+
|
350
|
+
before(:each) do
|
351
|
+
Factory(:page, :title => "I like to teach")
|
352
|
+
Factory(:page, :title => "I like teaching")
|
353
|
+
Factory(:page, :title => "The way he teaches is terrible")
|
354
|
+
Factory(:page, :title => "I like the moon")
|
355
|
+
Factory(:page, :title => "I like cheese")
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should return stemmed matches" do
|
359
|
+
results = Page.search("teaching")
|
360
|
+
results.should have(3).things
|
361
|
+
end
|
362
|
+
|
363
|
+
end
|
332
364
|
|
333
365
|
it "should return related" do
|
334
366
|
Factory(:page, :title => "My Page 1", :tag_list => 'one,two,three')
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noodall-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 7
|
10
|
+
version: 0.3.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Steve England
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-17 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|