komainu 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -9,11 +9,11 @@ module Komainu
|
|
9
9
|
|
10
10
|
def search query
|
11
11
|
results = SearchResults.new
|
12
|
-
@data_to_search.each do |
|
13
|
-
if text_includes_string(text, query)
|
14
|
-
results.items <<
|
15
|
-
elsif text_includes_words_from_string(text, query)
|
16
|
-
results.items <<
|
12
|
+
@data_to_search.each do |searchable|
|
13
|
+
if text_includes_string(searchable.text, query)
|
14
|
+
results.items << searchable
|
15
|
+
elsif text_includes_words_from_string(searchable.text, query)
|
16
|
+
results.items << searchable
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -24,7 +24,7 @@ module Komainu
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def calculate_suggestion(query)
|
27
|
-
words = split_into_words(@data_to_search.
|
27
|
+
words = split_into_words(@data_to_search.map { |searchable| searchable.text }.join(" "))
|
28
28
|
levenshtein = Levenshtein.new(words)
|
29
29
|
suggestion = split_into_words(query).map do |word|
|
30
30
|
matches = levenshtein.search(word, 2)
|
data/lib/komainu/version.rb
CHANGED
@@ -6,10 +6,13 @@ module Komainu
|
|
6
6
|
subject { SearchesText.new(data_to_search) }
|
7
7
|
|
8
8
|
let :data_to_search do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
item1 = OpenStruct.new
|
10
|
+
item1.name = :item1
|
11
|
+
item1.text = "This is some text"
|
12
|
+
item2 = OpenStruct.new
|
13
|
+
item2.name = :item2
|
14
|
+
item2.text = "Batman has no parents"
|
15
|
+
[item1, item2]
|
13
16
|
end
|
14
17
|
|
15
18
|
it "finds exact matches" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: komainu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-11-22 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
16
|
-
requirement: &
|
16
|
+
requirement: &70219264697540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70219264697540
|
25
25
|
description: ''
|
26
26
|
email:
|
27
27
|
- andrew.vos@gmail.com
|
@@ -35,7 +35,6 @@ files:
|
|
35
35
|
- komainu.gemspec
|
36
36
|
- lib/komainu.rb
|
37
37
|
- lib/komainu/levenshtein.rb
|
38
|
-
- lib/komainu/search_result.rb
|
39
38
|
- lib/komainu/search_results.rb
|
40
39
|
- lib/komainu/searches_text.rb
|
41
40
|
- lib/komainu/trie_node.rb
|