但是,我遇到了特殊字符(即撇號)的問題,只有當呈現是嵌套關聯時。ThinkingSphinx與特殊字符關聯的摘錄問題
我有一個'Vendor'模型和一個'Event'模型,其中一個Vendor has_many事件。下面是索引文件:
vendor_index:
ThinkingSphinx::Index.define :vendor, :with => :active_record do
indexes :name
indexes city
set_property :min_prefix_len => 2
set_property :enable_star => true
end
event_index:
ThinkingSphinx::Index.define :event, :with => :active_record do
indexes title
indexes subtitle
indexes venue_name
indexes vendor.name, :as => :vendor_name
indexes vendor.city, :as => :vendor_city
indexes genre.name, :as => :genre_name
where "workflow_state = 'published'"
set_property :min_prefix_len => 2
set_property :enable_star => true
end
我使用的是ExcerptorPane,像這樣,在我的搜索#index動作:
class SearchController < ApplicationController
helper_method :format_autocomplete
def index
@events = Event.search params[:search], {:star => true , :per_page => 5, :page => params[:events_page]}
@events.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
@vendors = Vendor.search params[:search], { :star => true , :per_page => 5, :page => params[:vendors_page]}
@vendors.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
@users = User.search params[:search], { :star => true , :per_page => 5, :page => params[:users_page]}
@users.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
end
# methods used for ajax-y pagination
def vendor_results
@vendors = Vendor.search params[:search], { :star => true , :per_page => 5, :page => params[:vendors_page]}
@vendors.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
respond_to do |format|
format.js
end
end
def user_results
@users = User.search params[:search], { :star => true , :per_page => 5, :page => params[:users_page]}
@users.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
respond_to do |format|
format.js
end
end
def event_results
@events = Event.search params[:search], { :star => true , :per_page => 5, :page => params[:events_page]}
@events.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
respond_to do |format|
format.js
end
end
def get_terms
results = ThinkingSphinx.search(params[:search], {:star => true})
results.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
results_json = format_autocomplete(results)
respond_to do |format|
format.js { render :json => results_json }
end
end
private
def format_autocomplete(r)
bucket = [];
r.each do |result|
puts result.class
if result.class.name == "Event"
title = result.excerpts.title
name = result.excerpts.vendor_name
bucket << {
:label => title,
:value => title,
:category => "Events",
:subtitle => result.excerpts.subtitle,
:url => event_url(result),
:vendor_name => name,
:vendor_city => result.excerpts.vendor_city,
:genre_name => result.excerpts.genre_name,
:venue_name => result.excerpts.venue_name
}
elsif result.class.name == "Vendor"
name = result.excerpts.name
bucket << {
:label => name,
:value => name,
:category => "Vendors",
:subtitle => result.excerpts.city,
:url => vendor_url(result)
}
elsif result.class.name == "User"
name = result.excerpts.name
bucket << {
:label => name,
:value => name,
:category => "Users",
:subtitle => result.excerpts.city,
:url => user_url(result)
}
end
end
bucket
end
結束
我還在我的think_sphinx.yml文件中包含了charset_table和ignore_chars。
現在,當我搜索名稱中有撇號的供應商時,如果供應商沒有任何事件,則一切正常。如果供應商有事件,雖然,我得到一個錯誤試圖呈現事件的VENDOR_NAME:(完整的供應商名稱是「VIFF的Vancity劇院和搜索查詢是‘VIFF’)
sphinxql: syntax error, unexpected IDENT, expecting ')' near 's Vancity Theatre', 'event_core', '*viff*', '<span class="match">' AS before_match, '</span>' AS after_match, ' … ' AS chunk_separator)'
在此行中提出我的觀點:
<p><%= link_to (raw event.excerpts.vendor_name), vendor_path(event.vendor) %></p>
我一直在尋找了一段時間,但找不到什麼幫助......任何想法,什麼可能導致這個
感謝
! UPDA TE:
如果我搜索「van」或「vanc」,一切都很好,它會變得很怪異,並且與供應商名稱「Viff's Vancity Theatre」(以及所有活動和供應商的城市='Vancouver') 「Vancity」標記爲匹配。但是,如果我搜索「vanco」,它會再次崩潰。當我在特定模型上執行搜索時會發生這種情況。然而,當我執行全局搜索時(對於自動完成),我會得到相反的行爲 - 'vanco'將起作用,但是更短的任何東西都會引發相同的錯誤。我用完整的search_controller.rb更新了上面的代碼。
什麼是您處理的供應商名稱?你用什麼版本的獅身人面像和思維獅身人面像? – pat
Sphinx 2.0.6-release(r3473);和ThinkingSphinx提交「7dfa8f24af」 – sooks
和供應商名稱是「VIFF的Vancity劇場」 – sooks