简体   繁体   English

Apache Solr搜索

[英]Apache Solr Search

I'm using Apache Solr for search.I import data from mysql table using data import handler.But when i use q=KOHLI insted of q=lastname:KOHLI ,i didn't get any results. 我正在使用Apache Solr进行搜索。我使用数据导入处理程序从mysql表中导入数据。但是当我使用q=KOHLI q=lastname:KOHLI ,我没有得到任何结果。

Here is response for q=lastname:KOHLI 这是q=lastname:KOHLI

{
  "responseHeader": {
      "status": 0,
      "QTime": 1,
      "params": {
      "q": "lastname:KOHLI",
      "indent": "true",
      "wt": "json",
      "_": "1427802213299"
    }
  },
  "response": {
     "numFound": 1,
     "start": 0,
     "docs": [
      {
        "lastname": "KOHLI",
        "town": "DELHI",
        "id": "2",
        "firstname": "VIRAT",
        "_version_": 1497158663291273200
      }
    ]
  }
}

schema.xml: schema.xml中:

<copyField source="firstname" dest="text"/>
<copyField source="lastname" dest="text"/>
<copyField source="town" dest="text"/>
<field name="firstname" type="text_general" indexed="true" stored="true"/>
<field name="lastname" type="text_general" indexed="true" stored="true"/>
<field name="town" type="text_general" indexed="true" stored="true"/>`

Are you using a query parser? 您正在使用查询解析器吗? If yes, in your file solrconfig.xml , what is the query field that you are using inside your requestHandler ? 如果是,在文件solrconfig.xml中 ,您在requestHandler中使用的查询字段是什么? ( qf parameter). qf参数)。 If you don't have your field lastname , here it's a normal behaviour. 如果您没有字段姓氏 ,这是正常现象。

If you don't use a query parser, in your file schema.xml , what is your defaultSearchField ? 如果不使用查询解析器,则在文件schema.xml中defaultSearchField是什么?

Can you add snippets of your Solr's files? 您可以添加Solr文件的摘要吗?

When you don't specify a field for the search, it searches the default search field. 当您不指定搜索字段时,它将搜索默认搜索字段。 If you want to perform a search like that, you may create new field and copy all other fields that you want to make them a target for search to that field, then set it as default search field. 如果要执行这样的搜索,则可以创建新字段并将要使其成为搜索目标的所有其他字段复制到该字段,然后将其设置为默认搜索字段。

Here are some resources: 以下是一些资源:

This is because you did not set default search field correctly. 这是因为您没有正确设置默认搜索字段。 If you did not pass a field name in "q", it will search input to default field, which you set in config file for your project. 如果您没有在“ q”中传递字段名称,它将搜索输入到默认字段,该默认字段是您在项目的配置文件中设置的。

To set default field, you can do either way: 要设置默认字段,您可以采用以下两种方法之一:

  1. In your schema.xml, change <defaultSearchField>id</defaultSearchField> to <defaultSearchField>lastname</defaultSearchField> 在您的schema.xml中,将<defaultSearchField>id</defaultSearchField>更改为<defaultSearchField>lastname</defaultSearchField>

  2. Run with q={!type=dismax qf=lastname}KOHLI in your q (remove "q=" if in web port) 在您的q中使用q={!type=dismax qf=lastname}KOHLI (如果在Web端口中,请删除“ q =“)

Reference: 参考:

See Query Type Short Form 请参阅查询类型简表

https://archive.apache.org/dist/lucene/solr/ref-guide/apache-solr-ref-guide-4.9.pdf https://archive.apache.org/dist/lucene/solr/ref-guide/apache-solr-ref-guide-4.9.pdf

Hope it could help. 希望它能有所帮助。 Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM