我遇到了特殊字符(撇号,即)的问题,但只有在存在时才是嵌套关联。
我有一个'供应商'模型和'事件'模型,其中供应商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 action:
中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 Theatre,搜索查询是'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>
我一直在寻找,但找不到任何帮助...有什么想法可能导致这个?
谢谢!
更新:
如果我搜索“van”或“vanc”,所有内容都很好,“Vancity”,供应商名称为“Viff's Vancity Theatre”,(以及所有活动和供应商都有城市='温哥华')标记为匹配。但是,如果我搜索“vanco”,它会再次破裂。当我在特定模型上执行搜索时会发生这种情况。然而,当我执行全局搜索时(对于自动完成),我得到相反的行为 - 'vanco'将起作用,但是任何更短的行为都会抛出相同的错误。我用完整的search_controller.rb更新了上面的代码。
答案 0 :(得分:0)
我刚收到Riddle的拉取请求,可能包含此修复程序。尝试将以下内容添加到您的Gemfile中:
gem 'riddle', '~> 1.5.6',
:git => 'git://github.com/pat/riddle.git',
:branch => 'master',
:ref => '50d410cda6'