From 52e393a2dfaa500229ed36fde74c7f6371967ab5 Mon Sep 17 00:00:00 2001 From: thomaschen <99703040@nccu.edu.tw> Date: Sun, 25 Aug 2013 17:32:15 +0800 Subject: [PATCH] add solr search(still have some problem) --- .../front_end/dictionary_vocabs_controller.rb | 4 +++- .../dictionary/app/models/dictionary_vocab.rb | 18 +++++------------- .../front_end/dictionary_vocabs/show.html.erb | 2 +- .../dictionary_search_block.html.erb | 1 - 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/vendor/built_in_modules/dictionary/app/controllers/panel/dictionary/front_end/dictionary_vocabs_controller.rb b/vendor/built_in_modules/dictionary/app/controllers/panel/dictionary/front_end/dictionary_vocabs_controller.rb index 685e878c6..3daf22c42 100644 --- a/vendor/built_in_modules/dictionary/app/controllers/panel/dictionary/front_end/dictionary_vocabs_controller.rb +++ b/vendor/built_in_modules/dictionary/app/controllers/panel/dictionary/front_end/dictionary_vocabs_controller.rb @@ -22,7 +22,9 @@ class Panel::Dictionary::FrontEnd::DictionaryVocabsController < OrbitWidgetContr if params[:search_query].empty? @vocabs = DictionaryVocab.all else - @vocabs = DictionaryVocab.search(params[:search_query]) + @vocabs = DictionaryVocab.solr_search do + fulltext params[:search_query] + end.results end # @item = Page.find(params[:page_id]) # @title = @item.title diff --git a/vendor/built_in_modules/dictionary/app/models/dictionary_vocab.rb b/vendor/built_in_modules/dictionary/app/models/dictionary_vocab.rb index 6e23328b5..272c066e0 100644 --- a/vendor/built_in_modules/dictionary/app/models/dictionary_vocab.rb +++ b/vendor/built_in_modules/dictionary/app/models/dictionary_vocab.rb @@ -4,7 +4,7 @@ class DictionaryVocab include Mongoid::Timestamps include Mongoid::MultiParameterAttributes include Mongoid::Sortable - + include Sunspot::Mongo BelongsToCategory = :dictionary_vocab_category include OrbitCoreLib::BelongsToCategoryMayDisable @@ -24,20 +24,12 @@ class DictionaryVocab # field :is_hidden, :type => Boolean, :default => false scope :can_display, where(is_hidden: false) - - belongs_to :dictionary_vocab_category - - def self.search(search) - if search - @search = DictionaryVocab.solr_search do - fulltext(search) - with(:frontend_search, true) - end - else - scoped - end + + searchable do + text :word end + belongs_to :dictionary_vocab_category # has_many :archive_file_multiples, :autosave => true, :dependent => :destroy # accepts_nested_attributes_for :archive_file_multiples, :allow_destroy => true diff --git a/vendor/built_in_modules/dictionary/app/views/panel/dictionary/front_end/dictionary_vocabs/show.html.erb b/vendor/built_in_modules/dictionary/app/views/panel/dictionary/front_end/dictionary_vocabs/show.html.erb index 29a5fe2c3..5ab42030f 100644 --- a/vendor/built_in_modules/dictionary/app/views/panel/dictionary/front_end/dictionary_vocabs/show.html.erb +++ b/vendor/built_in_modules/dictionary/app/views/panel/dictionary/front_end/dictionary_vocabs/show.html.erb @@ -1,5 +1,5 @@
-
+
diff --git a/vendor/built_in_modules/dictionary/app/views/panel/dictionary/widget/dictionary_vocabs/dictionary_search_block.html.erb b/vendor/built_in_modules/dictionary/app/views/panel/dictionary/widget/dictionary_vocabs/dictionary_search_block.html.erb index 02339a5b1..fa1f77aa8 100644 --- a/vendor/built_in_modules/dictionary/app/views/panel/dictionary/widget/dictionary_vocabs/dictionary_search_block.html.erb +++ b/vendor/built_in_modules/dictionary/app/views/panel/dictionary/widget/dictionary_vocabs/dictionary_search_block.html.erb @@ -1,5 +1,4 @@ <%= form_tag panel_dictionary_front_end_dictionary_vocabs_path, method: :get do %> - <%= hidden_field_tag :category_id, params[:category_id] %>

<%= text_field_tag :search_query, params[:search_query],{ value: (params[:search_query].blank? ? '' : params[:search_query]), placeholder: t("dictionary.widget.search") }%> <%= submit_tag t("dictionary.widget.search"), name: nil %>

<%= t :category, :scope => :dictionary %>