0

但是,我遇到了特殊字符(即撇号)的问题,仅当存在嵌套关联时。

我有一个“供应商”模型和一个“事件”模型,其中供应商有_many 事件。以下是索引文件:

供应商索引:

ThinkingSphinx::Index.define :vendor, :with => :active_record do
  indexes :name
  indexes city

  set_property :min_prefix_len => 2 
  set_property :enable_star => true
end

事件索引:

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

我在我的 search#index 操作中使用了 ExcerptorPane,就像这样:

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

结尾

我还在thinking_sphinx.yml 文件中包含了一个charset_table 和ignore_chars。

现在,当我搜索名称中带有撇号的供应商时,如果供应商没有事件,一切都会正常。但是,如果供应商有事件,我在尝试呈现事件的供应商名称时会出错:(供应商的完整名称是“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, ' &#8230; ' AS chunk_separator)'

在我看来,在这一行提出:

<p><%= link_to ( raw event.excerpts.vendor_name ), vendor_path(event.vendor) %></p>

我一直在寻找一段时间,但找不到任何帮助......关于可能导致这种情况的任何想法?

谢谢!

更新:

它变得更奇怪了......供应商名称为“Viff's Vancity Theatre”,(所有活动和供应商都有 city = 'Vancouver' )如果我搜索“van”或“vanc”,一切都很好,“Vancity”标记为匹配。但是,如果我搜索“vanco”,它会再次中断。当我在特定模型上执行搜索时会发生这种情况。但是,当我执行全局搜索(用于自动完成)时,我得到了相反的行为 - 'vanco' 会起作用,但任何更短的东西都会抛出相同的错误。我已经用完整的 search_controller.rb 更新了上面的代码。

4

1 回答 1

0

我刚刚收到了一个对 Riddle 的拉取请求,其中可能包含对此的修复。尝试将以下内容添加到您的 Gemfile:

gem 'riddle', '~> 1.5.6',
  :git    => 'git://github.com/pat/riddle.git',
  :branch => 'master',
  :ref    => '50d410cda6'
于 2013-06-28T01:12:40.793 回答