Search sold edition,rake sunspot:solr:run. NewsBulletin.solr_search,NewsBulletin.solr_reindex. Not working

This commit is contained in:
Matthew K. Fu JuYuan committed 2012-06-20 14:50:51 +08:00
1 parent 8dd1ab32c1
commit cb17fe0825
46 files changed
+2597 -263

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
README.rdoc
lib/**/*.rb
bin/*
features/**/*.feature
LICENSE
+20
View File
@@ -0,0 +1,20 @@
Copyright (c) 2009 jugyo
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+53
View File
@@ -0,0 +1,53 @@
sunspot_mongoid
====
A Sunspot wrapper for Mongoid.
Install
----
gem install sunspot_mongoid
Examples
----
class Post
include Mongoid::Document
field :title
include Sunspot::Mongoid
searchable do
text :title
end
end
For Rails3
----
### as gem:
add a gem to Gemfile as following,
gem 'sunspot_mongoid'
### as plugin:
add gems to Gemfile as following,
gem 'sunspot'
gem 'sunspot_rails'
and install sunspot_mongoid as rails plugin,
rails plugin install git://github.com/jugyo/sunspot_mongoid.git
Links
----
* [sunspot](http://github.com/outoftime/sunspot)
* [sunspot_rails](http://github.com/outoftime/sunspot/tree/master/sunspot_rails/)
Copyright
----
Copyright (c) 2010 jugyo. See LICENSE for details.
+57
View File
@@ -0,0 +1,57 @@
require 'rubygems'
require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "sunspot_mongoid"
gem.summary = %Q{A Sunspot wrapper for Mongoid.}
gem.description = %Q{A Sunspot wrapper for Mongoid that is like sunspot_rails.}
gem.email = "jugyo.org@gmail.com"
gem.homepage = "http://github.com/jugyo/sunspot_mongoid"
gem.authors = ["jugyo"]
gem.add_runtime_dependency "mongoid", ">= 0"
gem.add_runtime_dependency "sunspot", ">= 1.1.0"
gem.add_runtime_dependency "sunspot_rails", ">= 1.1.0"
gem.add_development_dependency "shoulda", ">= 0"
gem.add_development_dependency "rr", ">= 0"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
end
task :test => :check_dependencies
task :default => :test
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "sunspot_mongoid #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
+1
View File
@@ -0,0 +1 @@
0.4.1
+36
View File
@@ -0,0 +1,36 @@
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'sunspot_mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('sunspot-mongoid-test')
end
# model
class Post
include Mongoid::Document
field :title
include Sunspot::Mongoid
searchable do
text :title
end
end
# remove old indexes
Post.destroy_all
# indexing
Post.create(:title => 'foo')
Post.create(:title => 'foo bar')
Post.create(:title => 'bar baz')
# commit
Sunspot.commit
# search
search = Post.search do
keywords 'foo'
end
search.each_hit_with_result do |hit, post|
p post
end
+1
View File
@@ -0,0 +1 @@
require 'sunspot_mongoid'
+49
View File
@@ -0,0 +1,49 @@
require 'sunspot'
require 'mongoid'
require 'sunspot/rails'
# == Examples:
#
# class Post
# include Mongoid::Document
# field :title
#
# include Sunspot::Mongoid
# searchable do
# text :title
# end
# end
#
module Sunspot
module Mongoid
def self.included(base)
base.class_eval do
extend Sunspot::Rails::Searchable::ActsAsMethods
Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
end
end
class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
def id
@instance.id
end
end
class DataAccessor < Sunspot::Adapters::DataAccessor
def load(id)
criteria(id).first
end
def load_all(ids)
criteria(ids)
end
private
def criteria(id)
@clazz.criteria.id(id)
end
end
end
end
+1
View File
@@ -0,0 +1 @@
require 'sunspot/mongoid'
+67
View File
@@ -0,0 +1,67 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{sunspot_mongoid}
s.version = "0.4.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["jugyo"]
s.date = %q{2011-03-04}
s.description = %q{A Sunspot wrapper for Mongoid that is like sunspot_rails.}
s.email = %q{jugyo.org@gmail.com}
s.extra_rdoc_files = [
"LICENSE",
"README.md"
]
s.files = [
".document",
"LICENSE",
"README.md",
"Rakefile",
"VERSION",
"examples/example.rb",
"init.rb",
"lib/sunspot/mongoid.rb",
"lib/sunspot_mongoid.rb",
"sunspot_mongoid.gemspec",
"test/helper.rb",
"test/test_sunspot_mongoid.rb"
]
s.homepage = %q{http://github.com/jugyo/sunspot_mongoid}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.6.0}
s.summary = %q{A Sunspot wrapper for Mongoid.}
s.test_files = [
"examples/example.rb",
"test/helper.rb",
"test/test_sunspot_mongoid.rb"
]
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<mongoid>, [">= 0"])
s.add_runtime_dependency(%q<sunspot>, [">= 1.1.0"])
s.add_runtime_dependency(%q<sunspot_rails>, [">= 1.1.0"])
s.add_development_dependency(%q<shoulda>, [">= 0"])
s.add_development_dependency(%q<rr>, [">= 0"])
else
s.add_dependency(%q<mongoid>, [">= 0"])
s.add_dependency(%q<sunspot>, [">= 1.1.0"])
s.add_dependency(%q<sunspot_rails>, [">= 1.1.0"])
s.add_dependency(%q<shoulda>, [">= 0"])
s.add_dependency(%q<rr>, [">= 0"])
end
else
s.add_dependency(%q<mongoid>, [">= 0"])
s.add_dependency(%q<sunspot>, [">= 1.1.0"])
s.add_dependency(%q<sunspot_rails>, [">= 1.1.0"])
s.add_dependency(%q<shoulda>, [">= 0"])
s.add_dependency(%q<rr>, [">= 0"])
end
end
+12
View File
@@ -0,0 +1,12 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'rr'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'sunspot_mongoid'
class Test::Unit::TestCase
include RR::Adapters::TestUnit
end
@@ -0,0 +1,51 @@
require 'helper'
#
# NOTE: I think tests are too few...
#
class TestSunspotMongoid < Test::Unit::TestCase
class Foo
include Mongoid::Document
field :title
include Sunspot::Mongoid
searchable do
text :title
end
end
class Bar
include Mongoid::Document
field :title
include Sunspot::Mongoid
searchable(:auto_index => false, :auto_remove => false) do
text :title
end
end
context 'default' do
should 'sunspot_options is specified' do
assert Foo.sunspot_options == {:include => []}
assert Bar.sunspot_options == {:auto_index=>false, :auto_remove=>false, :include=>[]}
end
should 'be called Sunspot.setup when call Foo.searchable' do
mock(Sunspot).setup(Foo)
Foo.searchable
end
should 'get as text_fields from Sunspot::Setup' do
text_field = Sunspot::Setup.for(Foo).all_text_fields.first
assert text_field.type == Sunspot::Type::TextType.instance
assert text_field.name == :title
end
should 'search' do
options = {}
mock.proxy(Foo).solr_execute_search(options)
mock(Sunspot).new_search(Foo) { mock(Object.new).execute }
Foo.search(options)
end
end
end