Search sold edition,rake sunspot:solr:run. NewsBulletin.solr_search,NewsBulletin.solr_reindex. Not working
This commit is contained in:
1 parent
8dd1ab32c1
commit
cb17fe0825
46 files changed
+2597
-263
No files matched your search
@@ -5,6 +5,9 @@ class Bulletin
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
include Impressionist::Impressionable
|
||||
include NccuSearch
|
||||
|
||||
scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false)
|
||||
|
||||
is_impressionable :counter_cache => { :column_name => :view_count }
|
||||
|
||||
@@ -54,7 +57,11 @@ class Bulletin
|
||||
|
||||
after_save :save_bulletin_links
|
||||
after_save :save_bulletin_files
|
||||
|
||||
|
||||
|
||||
def publish_month
|
||||
published_at.strftime("%B %Y")
|
||||
end
|
||||
|
||||
def self.search( search = nil, category_id = nil )
|
||||
if category_id.to_s.size > 0 and search.to_s.size > 0
|
||||
|
||||
Vendored
+19
-10
@@ -9,20 +9,29 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
|
||||
# GET /news_bulletins.xml
|
||||
|
||||
def index
|
||||
date_now = Time.now
|
||||
if !params[:category_id].blank?
|
||||
@news_bulletins = NewsBulletin.can_display.where(:news_bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10)
|
||||
elsif !params[:tag_id].blank?
|
||||
tmp = NewsTag.find(params[:tag_id]) rescue nil
|
||||
tmp = NewsTag.where(key: params[:tag_id])[0] unless tmp
|
||||
@news_bulletins = tmp.news_bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10) rescue nil
|
||||
else
|
||||
@news_bulletins = NewsBulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10)
|
||||
end
|
||||
if !params[:search_query].blank?
|
||||
@news_bulletins = NewsBulletin.solr_search do
|
||||
fulltext params[:search_query] do
|
||||
fields(:text,:title=>2.0)
|
||||
end
|
||||
end.each_hit_with_result
|
||||
|
||||
else
|
||||
date_now = Time.now
|
||||
if !params[:category_id].blank?
|
||||
@news_bulletins = NewsBulletin.can_display.where(:news_bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10)
|
||||
elsif !params[:tag_id].blank?
|
||||
tmp = NewsTag.find(params[:tag_id]) rescue nil
|
||||
tmp = NewsTag.where(key: params[:tag_id])[0] unless tmp
|
||||
@news_bulletins = tmp.news_bulletins.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10) rescue nil
|
||||
else
|
||||
@news_bulletins = NewsBulletin.can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(10)
|
||||
end
|
||||
end
|
||||
get_categorys
|
||||
|
||||
@current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
Vendored
+3
@@ -46,6 +46,9 @@ class Panel::News::Widget::NewsBulletinsController < OrbitWidgetController
|
||||
get_categorys
|
||||
end
|
||||
|
||||
# def news_bulletins_search_block
|
||||
# end
|
||||
|
||||
def home_banner
|
||||
if !params[:category_id].blank?
|
||||
@news_bulletins = NewsBulletin.can_display.where(:news_bulletin_category_id => params[:category_id]).widget_datas.limit(9)
|
||||
|
||||
+65
-1
@@ -5,6 +5,16 @@ class NewsBulletin
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
include Impressionist::Impressionable
|
||||
# include OrbitBasis::BaseModel
|
||||
# include OrbitSearchLib::ObjectSearchable
|
||||
# include NccuSearch
|
||||
# include Redis::Objects
|
||||
include Mongoid::BaseModel
|
||||
|
||||
include Sunspot::Mongoid
|
||||
|
||||
|
||||
# scope :searchable,where(:is_checked=>true,:is_hidden=>false,:is_pending=>false)
|
||||
|
||||
is_impressionable :counter_cache => { :column_name => :view_count }
|
||||
|
||||
@@ -54,7 +64,61 @@ class NewsBulletin
|
||||
|
||||
after_save :save_news_bulletin_links
|
||||
after_save :save_news_bulletin_files
|
||||
|
||||
# include OrbitBasis::ClassMethods
|
||||
|
||||
|
||||
searchable do
|
||||
text :title do
|
||||
titles = ""
|
||||
titles << (self.title.zh_tw.nil? ? '':self.title.zh_tw)
|
||||
titles << (self.title.en.nil? ? '':self.title.en)
|
||||
#(titles << self.title.en )unless self.title.nil?
|
||||
doc = Nokogiri::HTML(titles)
|
||||
doc.text
|
||||
#VALID_LOCALES
|
||||
end
|
||||
|
||||
text :text do
|
||||
texts = ""
|
||||
texts << (self.text.zh_tw.nil? ? '':self.text.zh_tw)
|
||||
texts << (self.text.en.nil? ? '':self.text.en)
|
||||
#texts << self.text.en )unless self.text.en.nil?
|
||||
doc = Nokogiri::HTML(texts)
|
||||
doc.text
|
||||
#VALID_LOCALES
|
||||
end
|
||||
# text :sub_titles do
|
||||
# self.subtitle.zh_tw
|
||||
# #VALID_LOCALES
|
||||
# end
|
||||
# text :text do
|
||||
# self.text.zh_tw
|
||||
# #VALID_LOCALES
|
||||
# end
|
||||
# text :content, :publish_month
|
||||
# text :comments do
|
||||
# comments.map(&:content)
|
||||
# end
|
||||
# time :published_at
|
||||
# string :publish_month
|
||||
end
|
||||
# mapping do
|
||||
# indexes :title, :analyzer => 'cjk', :boost => 10
|
||||
# indexes :sub_titles, :analyzer => 'cjk', :boost => 5
|
||||
# indexes :text, :analyzer => 'cjk'
|
||||
# end
|
||||
|
||||
# def to_indexed_json
|
||||
# titles = title.zh_tw + title.en
|
||||
# sub_titles = subtitle.zh_tw + subtitle.en
|
||||
# texts = text.zh_tw + text.en
|
||||
# {
|
||||
# :id => id,
|
||||
# :title => titles,
|
||||
# :sub_titles => sub_titles,
|
||||
# :text => texts
|
||||
# }.to_json
|
||||
# end
|
||||
|
||||
def self.search( search = nil, category_id = nil )
|
||||
if category_id.to_s.size > 0 and search.to_s.size > 0
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<%= form_tag panel_news_front_end_news_bulletins_path, method: :get do %>
|
||||
<p>
|
||||
<%= text_field_tag :search_query, params[:search_query] %>
|
||||
<%= submit_tag "Search", name: nil %>
|
||||
</p>
|
||||
<% end %>
|
||||
@@ -45,6 +45,7 @@ Rails.application.routes.draw do
|
||||
match "reload_news_bulletins" => "news_bulletins#reload_news_bulletins"
|
||||
match "reload_web_links" => "news_bulletins#reload_web_links"
|
||||
match "news_bulletins_side_bar" => "news_bulletins#news_bulletins_side_bar"
|
||||
match "news_bulletins_search_block" => "news_bulletins#news_bulletins_search_block"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+1
-2
@@ -5,8 +5,7 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll
|
||||
#before_filter :is_admin?
|
||||
|
||||
def index
|
||||
|
||||
@page_contexts = params[:sort] ? get_sorted_and_filtered("page_contexts", {:archived => false}) : PageContext.where(:archived => false).page(params[:page]).per(10)
|
||||
@page_contexts = (params.has_key?:sort)? get_sorted_and_filtered("page_contexts", {:archived => false}) : PageContext.where(:archived => false).page(params[:page]).per(10)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
||||
+1
-1
@@ -19,5 +19,5 @@
|
||||
<%end -%>
|
||||
</td>
|
||||
<td><%= display_date_time(page_context.updated_at) %></td>
|
||||
<td><%= User.find(page_context.create_user_id).name %></td>
|
||||
<td><%= User.find(page_context.create_user_id).name rescue ''%></td>
|
||||
</tr>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
README.rdoc
|
||||
lib/**/*.rb
|
||||
bin/*
|
||||
features/**/*.feature
|
||||
LICENSE
|
||||
+20
@@ -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
@@ -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
@@ -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
@@ -0,0 +1 @@
|
||||
0.4.1
|
||||
@@ -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
@@ -0,0 +1 @@
|
||||
require 'sunspot_mongoid'
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
require 'sunspot/mongoid'
|
||||
@@ -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
@@ -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
|
||||
Reference in new issue
Block a user