quest_search 0.0.1 → 0.0.2
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.
- metadata +2 -6
- data/lib/quest/quest_on.rb +0 -79
- data/lib/quest/version.rb +0 -3
- data/lib/quest.rb +0 -5
- data/quest.gemspec +0 -24
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quest_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -23,10 +23,6 @@ files:
|
|
23
23
|
- Gemfile
|
24
24
|
- README
|
25
25
|
- Rakefile
|
26
|
-
- lib/quest.rb
|
27
|
-
- lib/quest/quest_on.rb
|
28
|
-
- lib/quest/version.rb
|
29
|
-
- quest.gemspec
|
30
26
|
homepage: http://github.com/fredriksundstrom/quest
|
31
27
|
licenses: []
|
32
28
|
post_install_message:
|
@@ -46,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
42
|
- !ruby/object:Gem::Version
|
47
43
|
version: '0'
|
48
44
|
requirements: []
|
49
|
-
rubyforge_project:
|
45
|
+
rubyforge_project: quest_search
|
50
46
|
rubygems_version: 1.8.11
|
51
47
|
signing_key:
|
52
48
|
specification_version: 3
|
data/lib/quest/quest_on.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
module Quest
|
2
|
-
module QuestOn
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
module ClassMethods
|
6
|
-
def quest_on(*fields)
|
7
|
-
if fields.size.zero?
|
8
|
-
raise "No arguments given, please specify which fields should be indexed and searched."
|
9
|
-
end
|
10
|
-
|
11
|
-
options = fields.extract_options!
|
12
|
-
|
13
|
-
@order = options[:order] || "id desc"
|
14
|
-
@limit = options[:limit] || 1000
|
15
|
-
|
16
|
-
cattr_accessor :quest_fields
|
17
|
-
|
18
|
-
self.quest_fields = fields
|
19
|
-
end
|
20
|
-
|
21
|
-
def quest_for(query, page_no = 1, page_size = nil)
|
22
|
-
words = query.to_s.split " "
|
23
|
-
conditions = words.map do |w|
|
24
|
-
self.quest_fields.map do |f|
|
25
|
-
replace_bind_variables("#{f} like ?", ["%#{w}%"])
|
26
|
-
end.join " OR "
|
27
|
-
end.join " OR "
|
28
|
-
|
29
|
-
self.where(conditions).order(@order).limit(@limit).sort do |a, b|
|
30
|
-
b.points_for(query) <=> a.points_for(query)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def points_for(query)
|
36
|
-
query = query.to_s.downcase
|
37
|
-
@quest_relevance ||= {}
|
38
|
-
return @quest_relevance[query] if @quest_relevance[query]
|
39
|
-
words = query.split " "
|
40
|
-
|
41
|
-
self.search_word_matches = []
|
42
|
-
self.search_word_matches_count = 0
|
43
|
-
self.search_word_total_matches_count = 0
|
44
|
-
|
45
|
-
points = words.map do |w|
|
46
|
-
matches = 0
|
47
|
-
|
48
|
-
points = self.quest_fields.map do |field|
|
49
|
-
content = self.send(field).to_s.downcase
|
50
|
-
|
51
|
-
matches = content.scan(w).size
|
52
|
-
|
53
|
-
# one point for partial word matches
|
54
|
-
(content.scan(w).size +
|
55
|
-
# one point for partial query matches
|
56
|
-
content.scan(query).size +
|
57
|
-
# two points for exact word match
|
58
|
-
(content == w ? 2 : 0) +
|
59
|
-
# two points for exact query match
|
60
|
-
(content == query ? 2 : 0))
|
61
|
-
end.sum
|
62
|
-
|
63
|
-
if matches != 0
|
64
|
-
self.search_word_matches.push [ 'word' => w, 'count' => matches ]
|
65
|
-
self.search_word_matches_count += 1
|
66
|
-
self.search_word_total_matches_count += matches
|
67
|
-
end
|
68
|
-
|
69
|
-
points
|
70
|
-
end.sum
|
71
|
-
|
72
|
-
self.relevance = points
|
73
|
-
|
74
|
-
@quest_relevance[query] = points
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
ActiveRecord::Base.send :include, Quest::QuestOn
|
data/lib/quest/version.rb
DELETED
data/lib/quest.rb
DELETED
data/quest.gemspec
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "quest/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "quest_search"
|
7
|
-
s.version = Quest::VERSION
|
8
|
-
s.authors = ["Fredrik Sundström"]
|
9
|
-
s.email = ["fredrik.sundstrom@gmail.com"]
|
10
|
-
s.homepage = "http://github.com/fredriksundstrom/quest"
|
11
|
-
s.summary = "Extremely naive full text search implementation for ActiveRecord based on naive-search by Tomas Jogin (http://github.com/tjogin/naive-search). Orders results by relevance and gives you detailed info on the search results."
|
12
|
-
s.description = "Quest is a gem that lets you search your model in a simple and intuitive way."
|
13
|
-
|
14
|
-
s.rubyforge_project = "quest"
|
15
|
-
|
16
|
-
s.files = `git ls-files`.split("\n")
|
17
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
-
s.require_paths = ["lib"]
|
20
|
-
|
21
|
-
# specify any dependencies here; for example:
|
22
|
-
# s.add_development_dependency "rspec"
|
23
|
-
# s.add_runtime_dependency "rest-client"
|
24
|
-
end
|