noodall-core 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.5
data/lib/noodall/node.rb CHANGED
@@ -33,8 +33,6 @@ module Noodall
33
33
 
34
34
  acts_as_tree :order => "position", :search_class => Noodall::Node
35
35
 
36
- searchable_keys :title, :description, :keywords, :body
37
-
38
36
  validates_true_for :template,
39
37
  :message => "cannot be changed as sub content is not allowed in this template",
40
38
  :logic => lambda { children.reject{|c| self._type.constantize.template_classes.include?(c.class)}.empty? }
@@ -1,30 +1,30 @@
1
1
  module Noodall
2
2
  module Search
3
3
  STOPWORDS = ["about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also", "although", "always", "among", "amongst", "amoungst", "amount", "and", "another", "any", "anyhow", "anyone", "anything", "anyway", "anywhere", "are", "around", "back", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom", "but", "call", "can", "cannot", "cant", "con", "could", "couldnt", "cry", "describe", "detail", "done", "down", "due", "during", "each", "eight", "either", "eleven", "else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "had", "has", "hasnt", "have", "hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself", "his", "how", "however", "hundred", "inc", "indeed", "interest", "into", "its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "nobody", "none", "noone", "nor", "not", "nothing", "now", "nowhere", "off", "often", "once", "one", "only", "onto", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own", "part", "per", "perhaps", "please", "put", "rather", "same", "see", "seem", "seemed", "seeming", "seems", "serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "some", "somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take", "ten", "than", "that", "the", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter", "thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this", "those", "though", "three", "through", "throughout", "thru", "thus", "together", "too", "top", "toward", "towards", "twelve", "twenty", "two", "under", "until", "upon", "very", "via", "was", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter", "whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who", "whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you", "your", "yours", "yourself", "yourselves"]
4
-
4
+
5
5
  def self.configure(model)
6
6
  require 'lingua/stemmer'
7
-
7
+
8
8
  model.class_eval do
9
9
  key :_keywords, Array, :index => true
10
10
  attr_accessor :relevance
11
-
11
+
12
12
  before_save :_update_keywords
13
13
  end
14
14
  end
15
-
15
+
16
16
  module ClassMethods
17
17
  def searchable_keys(*keys)
18
- @@searchable_keys ||= Set.new
19
- @@searchable_keys += keys
20
-
21
- @@searchable_keys
18
+ @searchable_keys ||= Set.new
19
+ @searchable_keys += keys
20
+
21
+ @searchable_keys
22
22
  end
23
-
23
+
24
24
  def language(lang = 'en')
25
25
  @language ||= lang
26
26
  end
27
-
27
+
28
28
  def search(query, options = {})
29
29
  if options[:per_page] || options[:per_page]
30
30
  per_page = options.delete(:per_page)
@@ -40,10 +40,10 @@ module Noodall
40
40
  words = query.downcase.split(/\W/) - STOPWORDS
41
41
  words.reject!{|w| w.length < 3}
42
42
  criteria.merge!( :_keywords => { :$all => words } )
43
-
43
+
44
44
  # The Search result
45
45
  search_result = collection.map_reduce(search_map(words), search_reduce, {:query => criteria, :finalize => search_finalize})
46
-
46
+
47
47
  # Add value to sort options because model is stored in the value key
48
48
  options[:sort].map! do |s,v|
49
49
  ["value.#{s}",v]
@@ -57,13 +57,13 @@ module Noodall
57
57
  results = search_query.all
58
58
  end
59
59
  # clean up tmp collection
60
- search_result.drop
60
+ search_result.drop
61
61
  #return results mappped to objects
62
62
  results.tap do |docs|
63
63
  docs.map! { |hash| load(hash['value']) }
64
64
  end
65
65
  end
66
-
66
+
67
67
  def search_map(words)
68
68
  #convert words into Regex OR
69
69
  q = words.map do |k|
@@ -77,28 +77,28 @@ module Noodall
77
77
  "emit(this._id, this);" +
78
78
  "}"
79
79
  end
80
-
80
+
81
81
  def search_reduce
82
82
  "function( key , values ){return { model: values[0]};}"
83
83
  end
84
-
84
+
85
85
  def search_finalize
86
86
  "function( key , values ){return values.model;}"
87
87
  end
88
88
  end
89
-
89
+
90
90
  module InstanceMethods
91
91
  protected
92
92
  def _update_keywords
93
93
  s = Lingua::Stemmer.new(:language => self.class.language)
94
-
94
+
95
95
  self._keywords = []
96
-
96
+
97
97
  self.class.searchable_keys.each do |search_key|
98
98
  self._keywords += keywords_for_value(s, send(search_key)).compact
99
99
  end
100
100
  end
101
-
101
+
102
102
  private
103
103
  def keywords_for_value(stemmer, val)
104
104
  if val.kind_of?(String)
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.4"
8
+ s.version = "0.3.5"
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-11-29}
12
+ s.date = %q{2010-12-09}
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 = [
@@ -1,6 +1,7 @@
1
1
  # Dummy node class for the tests
2
2
  class Page < Noodall::Node
3
3
  #sub_templates PageA, PageB, ArticlesList, LandingPage, EventsList
4
+ searchable_keys :title, :description, :keywords, :body
4
5
  root_template!
5
6
 
6
7
  main_slots 1
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
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-11-29 00:00:00 +00:00
18
+ date: 2010-12-09 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency