add solr search(still have some problem)

This commit is contained in:
thomaschen 2013-08-25 17:32:15 +08:00 committed by chris
parent 481f04c07b
commit 52e393a2df
4 changed files with 9 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
<div class="row">
<div class="span8 offset1">
<div class="span8">
<table class="table" align ="center">
<tr>
<td ><%= t :category, :scope => :dictionary %></td>

View File

@ -1,5 +1,4 @@
<%= form_tag panel_dictionary_front_end_dictionary_vocabs_path, method: :get do %>
<%= hidden_field_tag :category_id, params[:category_id] %>
<p>
<%= 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 %>