我错过了 Solr-Sunspot 设置的哪一部分? [英] What part of this Solr-Sunspot setup am I missing?

查看:40
本文介绍了我错过了 Solr-Sunspot 设置的哪一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为我有这个小菜一碟..但是每当我对任何关键字进行查询时,它都不会从 SQL 加载任何表.我没有收到任何错误.

I thought I had this down piece-of-cake .. but anytime I do a query on any keyword it doesn't load any tables from SQL. I get no errors.

user.rb

searchable do
  string  :first_name
  string  :last_name
  string  :name
  string  :email
  time    :created_at
end

users_controller.rb

class Admin::UsersController < Admin::ApplicationController

  def index
    s = Sunspot.search User do |query|
      query.keywords params[:q]
      query.any_of do |any_of|
        any_of.with(:first_name)
        any_of.with(:first_name)
        any_of.with(:email)
        any_of.with(:name)
      end
      query.paginate :page => (params[:page] && params[:page].to_i || 1), :per_page => 20
      query.order_by('created_at', 'desc')
    end

    s.execute!
    @users = s.results

    render :action => 'index'
  end

然后我跑了:

$> script/console
$> User.reindex

当我根本不进行搜索时..它成功显示了所有 User 结果

When I make no search at all..it successfully displays all User results

相信我要把所有这些字符串标签都变成文本标签,但会返回这个错误:

I believe I am to make all those string tags into text tags but that returns this error:

Sunspot::UnrecognizedFieldError in Admin/usersController#index

No field configured for User with name 'first_name'

我错过了什么才能让这个响应关键字?

What am I missing to get this to respond to keywords?

推荐答案

(一个更完整的解释你自己的自我跟进.)

关于您的设置:

searchable do
  string  :first_name
  string  :last_name
  string  :name
  string  :email
  time    :created_at
end

Solr 中的字符串旨在用于精确匹配.它不像文本列那样进行预处理或标记化.这些文字匹配用于过滤(其中 category_name 等于 'Sale'")、分面、排序等.

A string in Solr is intended to be used for exact matches. It isn't pre-processed or tokenized the way a text column would be. These literal matches are used for filtering ("where category_name equals 'Sale'"), faceting, sorting, and so on.

您更有可能需要 text 字段.文本字段使用 Standard Tokenizer 标记化,使用 LowerCaseFilterFactory">小写过滤器,并使用 Standard Filter 以及许多其他潜在选项.

You more likely want text fields. Text fields are tokenized with the Standard Tokenizer, lowercased with the LowerCase Filter, and have their dots and apostrophes removed with the Standard Filter among many other potential options.

当人们想到 Solr 的全文搜索功能时,他们会想到它如何处理 text 字段.

When people think of the functionality of Solr's full-text search, they're thinking of how it processes text fields.

此外,默认情况下,Sunspot 的 keywords 搜索方法会针对您的所有文本字段进行搜索,这解释了为什么当您包含 keywords -- 您的文档时没有获得结果没有可搜索的文本字段.

Furthermore, Sunspot's keywords search method by default searches against all of your text fields, which explains why you aren't getting results when you include keywords -- your documents have no text fields to search against.

正如您在自我跟进中所指出的,您需要切换到 text 字段以获得您期望的结果.

As you note in your self-followup, you'll want to switch to text fields to get the results you're expecting.

这篇关于我错过了 Solr-Sunspot 设置的哪一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆