Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用“太阳黑子”solr高亮显示所属对象的场_Ruby On Rails_Solr_Sunspot_Highlighting_Searchable - Fatal编程技术网

Ruby on rails 使用“太阳黑子”solr高亮显示所属对象的场

Ruby on rails 使用“太阳黑子”solr高亮显示所属对象的场,ruby-on-rails,solr,sunspot,highlighting,searchable,Ruby On Rails,Solr,Sunspot,Highlighting,Searchable,我正在使用sunspot_solr在ruby on rails中实现快速查找。我正在对许多项目对象进行全文搜索,但也希望通过自有注释的内容进行搜索。我将搜索设置为在用户键入时显示突出显示的命中结果。我可以让代码要么显示突出显示的结果,要么在notes中返回命中结果,但不能两者兼而有之 返回注释结果的代码: 在Project.rb中 可访问属性:标题,:说明 你有很多笔记吗 searchable do text :title, :boost => 5 text :descri

我正在使用sunspot_solr在ruby on rails中实现快速查找。我正在对许多项目对象进行全文搜索,但也希望通过自有注释的内容进行搜索。我将搜索设置为在用户键入时显示突出显示的命中结果。我可以让代码要么显示突出显示的结果,要么在notes中返回命中结果,但不能两者兼而有之

返回注释结果的代码:

在Project.rb中 可访问属性:标题,:说明 你有很多笔记吗

searchable do
    text :title, :boost => 5
    text :description
    text :notes do
      notes.map(&:content)
    end
  end
在Project_controller.rb中

def quick
     unless params[:q].nil? || params[:q].empty?
       @search = Project.search do
        fulltext params[:q]
       end

      @projects = @search.results
     else
      @projects = Project.none
     end

     respond_to do |format|
      format.json { render :json => @projects }
     end
   end
def quick
    unless params[:q].nil? || params[:q].empty?
      @search = Project.search do
        fulltext params[:q] do
          highlight :title
          highlight :description
        end

        adjust_solr_params do |sunspot_params|
          sunspot_params[:rows] = 15
        end
      end

      @result = []
      @search.each_hit_with_result do |hit, project|
        @highlight = hit.highlight(nil)
        @field_name = @highlight.field_name
        @text = hit.highlight(nil).format { |word| "<span style='color: orange;'>#{word}</span>" }
        @result << {:text => @text, :id => project.id, :fieldname => @field_name}
      end
    else
      @result = []
    end

    respond_to do |format|
      format.json { render :json => @result }
    end
  end
在Note.rb中 属性可访问:内容,:项目id 属于:项目

突出显示点击的代码,不搜索注释内容: Project_controller.rb

def quick
     unless params[:q].nil? || params[:q].empty?
       @search = Project.search do
        fulltext params[:q]
       end

      @projects = @search.results
     else
      @projects = Project.none
     end

     respond_to do |format|
      format.json { render :json => @projects }
     end
   end
def quick
    unless params[:q].nil? || params[:q].empty?
      @search = Project.search do
        fulltext params[:q] do
          highlight :title
          highlight :description
        end

        adjust_solr_params do |sunspot_params|
          sunspot_params[:rows] = 15
        end
      end

      @result = []
      @search.each_hit_with_result do |hit, project|
        @highlight = hit.highlight(nil)
        @field_name = @highlight.field_name
        @text = hit.highlight(nil).format { |word| "<span style='color: orange;'>#{word}</span>" }
        @result << {:text => @text, :id => project.id, :fieldname => @field_name}
      end
    else
      @result = []
    end

    respond_to do |format|
      format.json { render :json => @result }
    end
  end
def-quick
除非参数[:q].nil?| |params[:q]。是否为空?
@search=Project.search-do
全文参数[:q]do
推荐理由:标题
亮点:描述
结束
调整太阳黑子参数|
太阳黑子参数[:行]=15
结束
结束
@结果=[]
@search.each_hit_与_result do|hit,project|
@highlight=hit.highlight(无)
@field\u name=@highlight.field\u name
@text=hit.highlight(nil).format{| word |“{word}”
@结果@text,:id=>project.id,:fieldname=>@field\u name}
结束
其他的
@结果=[]
结束
回应待办事项|格式|
format.json{render:json=>@result}
结束
结束
Project.rb和Note.rb在这里基本相同,只是我在项目的标题/描述中添加了
:stored=>true

然而,尽管尝试了各种选项对注释内容进行全文搜索,并返回注释内容的突出显示结果,但我似乎不知道如何进行搜索。每次我尝试添加任何类型的代码来存储和/或突出显示便笺内容时,代码都会停止工作。这是不可能的,还是我缺少正确的语法


Solr的版本是4.2.0,Sunspot的版本是2.1.1,因此,在寻找解决方案时,我发现了更多关于Solr性能的信息。尤其是存储字段与索引字段的性能。我开始认为,将字段存储在与正在搜索的表具有多对一关系的表上可能是不可能的,即使是这样,也不值得性能损失

因此,虽然在理论上,当你打字时实时突出显示笔记中的文本的功能对我来说可能真的很好,但实际上它太慢了,不太有用,所以我不仅不介意突出显示笔记,而且我可能也会放弃存储描述,只显示标题中突出显示的点击

所以我想这个问题的答案是“这可能是可能的,但即使是也绝对不值得。”