diviner 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4a7ccb4a2983496e7e16134161d598586071d10
4
- data.tar.gz: c154e3b39bf3b6314503fef01ab47da3bddb3dc9
3
+ metadata.gz: 6b394c94e959d168855fbdd58a40e2785acff6e5
4
+ data.tar.gz: c188f6c5c2d71aa2e33cfda62f04953b9437290c
5
5
  SHA512:
6
- metadata.gz: f56c6cf85a44dc21215430dbd244a88aa4b6bca73b11cb653d0797c6cb4f717ad9190df3446f3078bc67d9d6cd85e1754d770f8ea4d2fdeb6713c9019db0f656
7
- data.tar.gz: 803e067181fd6bf181f327eb948191f7b1378dd39839a248085b32a713a4681383e0dde53cef6326a3447cba47ad12fd0d0f929fa3ca25c798d42e4b003fed78
6
+ metadata.gz: 8386e140b2cc549e5ba8c443d233abfb44a0ee90dfd2058f178fef00eef8341aaa1c3b811673ffb4d697b72e0cc9e2c3bee4b372ee26e7e521e9866c2f70045a
7
+ data.tar.gz: f3a1c90770ca1c9dff3b11616306d37a71adb1d573d1cb7fa66ee0f3dcc1b2082aea78988d7031cd5104c054a4c442dfba926fb72e124f6e1bccc97a3973c20b
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: diviner 0.1.2 ruby lib
5
+ # stub: diviner 0.1.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "diviner"
9
- s.version = "0.1.2"
9
+ s.version = "0.1.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Ferhat Ziba"]
14
- s.date = "2016-06-13"
14
+ s.date = "2016-06-14"
15
15
  s.description = "It matches from a list of categories the right category to a Product."
16
16
  s.email = "fero.ziba@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -62,6 +62,10 @@ module Deviner
62
62
  end
63
63
  end
64
64
 
65
+ result = result.reject{ |x| x[:value] != highest_value}
66
+ puts "ACHTUNG"
67
+ puts result
68
+
65
69
  return selected_category
66
70
 
67
71
  end
@@ -81,24 +85,30 @@ module Deviner
81
85
  query = prepare_query(query)
82
86
  return cache[query] if cache[query] != nil
83
87
  search = Picky::Search.new @index
84
- result = search.search(query)
88
+ subqueries = query.split(" ")
89
+ total = 0
90
+ for subquery in subqueries
91
+ result = search.search(query)
92
+ total+=result.total
93
+ end
85
94
  if options[:has_parent]
86
95
  parent = category.send(options[:parent_method])
87
96
  else
88
97
  parent = nil
89
98
  end
90
- cache[query] = result.total + score(parent)
99
+ cache[query] = total + score(parent)
91
100
  end
92
101
 
93
102
  def prepare_query query
94
- query.gsub(",", " OR ").
95
- gsub("&", " OR ").
103
+ query.gsub(",", " ").
104
+ gsub("&", " ").
96
105
  gsub("ü", "ue").
97
106
  gsub("ö", "oe").
98
107
  gsub("ä", "ae").
99
108
  gsub("Ü", "Ue").
100
109
  gsub("Ö", "Oe").
101
- gsub("Ä", "Ae")
110
+ gsub("Ä", "Ae").
111
+ gsub(" ", " ")
102
112
  end
103
113
 
104
114
  end
@@ -67,15 +67,14 @@ taxonomies.each_line do |line|
67
67
  stack.pop
68
68
  end
69
69
 
70
+ stack = [] if names.length == 1
71
+
70
72
  parent = stack.last
71
73
  category = TestCategory.new(names.last,parent)
72
74
  stack.push(category)
73
75
  @categories << category
74
76
  end
75
77
 
76
-
77
- puts @categories
78
-
79
78
  class MyTestCategory
80
79
 
81
80
  def self.categories=(categories)
@@ -21,4 +21,18 @@ class TestDiviner < Test::Unit::TestCase
21
21
  matcher.model(model, keys)
22
22
  assert_equal "Massageöle", matcher.match(MyTestCategory.categories).name
23
23
  end
24
+
25
+ should "find more complex testcase" do
26
+ Product = Struct.new :id, :name, :description, :categories
27
+ keys = [:name, :description, :categories]
28
+ weights = {categories: 3, name: 2, description: 1}
29
+ model = Product.new(1, "HiPP Gemüserisotto mit zarter Bio-Pute, 250 g",
30
+ "HiPP Gemüserisotto mit zarter Bio-Pute enthält schonend dampfgegarte Zutaten mit kindgerechter Würzung und Omega-3 Fettsäuren aus Bio-Rapsöl. Die Mahlzeit ist geeignet für eine sichere und ausgewogene Ernährung Ihres Babys ab dem12. Monat. mit Stückchenfürs Kauenlernen salzreduziert glutenfrei ohne Zusatz von Aromen, Konservierungsstoffen, Farbstoffen, Verdickungsmitteln",
31
+ "Baby & Kind Babynahrung Kindernahrung Beikost")
32
+ matcher = Deviner::Match.new(weights)
33
+ matcher.model(model, keys)
34
+ assert_equal "Babynahrung", matcher.match(MyTestCategory.categories).name
35
+ end
36
+
37
+
24
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diviner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ferhat Ziba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-stemmer