couchrest_model_search 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Dorren Chen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ = couchrest_model_search
2
+
3
+ This add search method calls to couchrest_model gem. Assuming you are using couchdb-lucene.
4
+
5
+ == Install
6
+ gem install couchrest_model_search
7
+
8
+ == Usage
9
+ class Article < CouchRest::Model::Base
10
+ end
11
+
12
+ # save design doc to couchdb if you have existing one.
13
+ # by default, couchrest_model only update view_by functions.
14
+ Article.update_search_doc
15
+
16
+ @articles = Article..search 'by_content', "apple" # search by keyword apple
17
+
18
+ # you can also custom the search function.
19
+ class CustomArticle < CouchRest::Model::Base
20
+ def self.fulltext
21
+ { "by_content" => {"index" => %(function(doc) {})}
22
+ }
23
+ end
24
+ end
25
+
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "couchrest_model_search"
8
+ gem.summary = %Q{Add search function to CouchRest Model}
9
+ gem.description = %Q{Add search function to CouchRest Model, assuming you're using couchdb-lucene}
10
+ gem.email = "dorrenchen@gmail.com"
11
+ gem.homepage = "http://github.com/dorren/couchrest_model_search"
12
+ gem.authors = ["Dorren Chen"]
13
+ gem.add_development_dependency "active_support", ">=3.0.0"
14
+ gem.add_development_dependency "couchrest_model", ">=1.0.0.beta7"
15
+ gem.add_development_dependency "rspec", ">= 2.0.0"
16
+ gem.add_development_dependency "cucumber", ">= 0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ # require 'spec/rake/rspectask'
25
+ # Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ # spec.libs << 'lib' << 'spec'
27
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ # end
29
+ #
30
+ # Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ # spec.libs << 'lib' << 'spec'
32
+ # spec.pattern = 'spec/**/*_spec.rb'
33
+ # spec.rcov = true
34
+ # end
35
+ #
36
+ # task :spec => :check_dependencies
37
+
38
+ begin
39
+ require 'cucumber/rake/task'
40
+ Cucumber::Rake::Task.new(:features)
41
+
42
+ task :features => :check_dependencies
43
+ rescue LoadError
44
+ task :features do
45
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
46
+ end
47
+ end
48
+
49
+ task :default => :spec
50
+
51
+ require 'rake/rdoctask'
52
+ Rake::RDocTask.new do |rdoc|
53
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
54
+
55
+ rdoc.rdoc_dir = 'rdoc'
56
+ rdoc.title = "couchrest_model_search #{version}"
57
+ rdoc.rdoc_files.include('README*')
58
+ rdoc.rdoc_files.include('lib/**/*.rb')
59
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{couchrest_model_search}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dorren Chen"]
12
+ s.date = %q{2010-10-13}
13
+ s.description = %q{Add search function to CouchRest Model, assuming you're using couchdb-lucene}
14
+ s.email = %q{dorrenchen@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rspec",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "couchrest_model_search.gemspec",
28
+ "features/couchrest_model_search.feature",
29
+ "features/step_definitions/couchrest_model_search_steps.rb",
30
+ "features/support/env.rb",
31
+ "lib/couchrest_model_search.rb",
32
+ "spec/couchrest_model_search_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/dorren/couchrest_model_search}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Add search function to CouchRest Model}
40
+ s.test_files = [
41
+ "spec/couchrest_model_search_spec.rb",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<active_support>, [">= 3.0.0"])
51
+ s.add_development_dependency(%q<couchrest_model>, [">= 1.0.0.beta7"])
52
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0"])
53
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<active_support>, [">= 3.0.0"])
56
+ s.add_dependency(%q<couchrest_model>, [">= 1.0.0.beta7"])
57
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
58
+ s.add_dependency(%q<cucumber>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<active_support>, [">= 3.0.0"])
62
+ s.add_dependency(%q<couchrest_model>, [">= 1.0.0.beta7"])
63
+ s.add_dependency(%q<rspec>, [">= 2.0.0"])
64
+ s.add_dependency(%q<cucumber>, [">= 0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'couchrest_model_search'
3
+
4
+ require 'spec/expectations'
@@ -0,0 +1,72 @@
1
+ require 'couchrest_model'
2
+
3
+ module CouchRest
4
+ module Model
5
+ module DesignDoc
6
+ module ClassMethods
7
+ # the default search function
8
+ def fulltext
9
+ { "by_content" => {
10
+ "index" => %(
11
+ function(doc) {
12
+ var ret = new Document();
13
+ function idx(obj) {
14
+ for (var key in obj){
15
+ switch (typeof obj[key]) {
16
+ case 'object':
17
+ idx(obj[key]);
18
+ break;
19
+ case 'function':
20
+ break;
21
+ default:
22
+ ret.add(obj[key]);
23
+ break;
24
+ }
25
+ }
26
+ };
27
+
28
+ if (doc['couchrest-type'] == '#{self.to_s}') {
29
+ idx(doc);
30
+
31
+ if (doc._attachments) {
32
+ for (var i in doc._attachments) {
33
+ ret.attachment('attachment', i);
34
+ }
35
+ }
36
+ }
37
+ return ret;
38
+ }
39
+ )
40
+ }
41
+ }
42
+ end
43
+
44
+ alias_method :orig_default_design_doc, :default_design_doc
45
+ def default_design_doc
46
+ orig_default_design_doc.merge "fulltext" => fulltext
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ class CouchRest::Database
54
+ def search(klass, view_fn, query, options={})
55
+ CouchRest.get CouchRest.paramify_url("#{@root}/_fti/_design/#{klass}/#{view_fn}", options.merge(:q => query))
56
+ end
57
+ end
58
+
59
+ class CouchRest::Model::Base
60
+ def self.search(view_fn, query, options={})
61
+ options[:include_docs] = true
62
+ ret = self.database.search(self.to_s, view_fn, query, options)
63
+ ret['rows'].map {|r| self.new(r['doc'])}
64
+ end
65
+
66
+ def self.update_search_doc
67
+ dbdoc = database.get '_design/#{self.to_s}'
68
+ dbdoc.update design_doc
69
+ dbdoc.save
70
+ end
71
+ end
72
+
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CouchrestModelSearch" do
4
+ class Article < CouchRest::Model::Base
5
+ end
6
+
7
+ it "should overwrite default_design_doc" do
8
+ Article.design_doc["fulltext"].should_not be_nil
9
+ end
10
+ end
11
+
12
+ describe "CouchrestModelSearch" do
13
+ class CustomArticle < CouchRest::Model::Base
14
+ def self.fulltext
15
+ { "by_content" => {"index" => %(function(doc) {})}}
16
+ end
17
+ end
18
+
19
+ it "should allow class to overwrite fulltext function" do
20
+ CustomArticle.design_doc["fulltext"].should == CustomArticle.fulltext
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'couchrest_model_search'
4
+ require 'rspec'
5
+ require 'rspec/autorun'
6
+
7
+ RSpec.configure do |config|
8
+ # == Mock Framework
9
+ #
10
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
11
+ #
12
+ # config.mock_with :mocha
13
+ # config.mock_with :flexmock
14
+ # config.mock_with :rr
15
+ config.mock_with :rspec
16
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: couchrest_model_search
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Dorren Chen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-13 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: active_support
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: couchrest_model
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 299253591
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ - beta7
51
+ version: 1.0.0.beta7
52
+ type: :development
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 15
63
+ segments:
64
+ - 2
65
+ - 0
66
+ - 0
67
+ version: 2.0.0
68
+ type: :development
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: cucumber
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ type: :development
83
+ version_requirements: *id004
84
+ description: Add search function to CouchRest Model, assuming you're using couchdb-lucene
85
+ email: dorrenchen@gmail.com
86
+ executables: []
87
+
88
+ extensions: []
89
+
90
+ extra_rdoc_files:
91
+ - LICENSE
92
+ - README.rdoc
93
+ files:
94
+ - .document
95
+ - .gitignore
96
+ - .rspec
97
+ - LICENSE
98
+ - README.rdoc
99
+ - Rakefile
100
+ - VERSION
101
+ - couchrest_model_search.gemspec
102
+ - features/couchrest_model_search.feature
103
+ - features/step_definitions/couchrest_model_search_steps.rb
104
+ - features/support/env.rb
105
+ - lib/couchrest_model_search.rb
106
+ - spec/couchrest_model_search_spec.rb
107
+ - spec/spec_helper.rb
108
+ has_rdoc: true
109
+ homepage: http://github.com/dorren/couchrest_model_search
110
+ licenses: []
111
+
112
+ post_install_message:
113
+ rdoc_options:
114
+ - --charset=UTF-8
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.3.7
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Add search function to CouchRest Model
142
+ test_files:
143
+ - spec/couchrest_model_search_spec.rb
144
+ - spec/spec_helper.rb