【问题标题】:Query with q=*:* && q={keyword} && q=field:{keyword} in solr 4.9在 solr 4.9 中使用 q=*:* && q={keyword} && q=field:{keyword} 进行查询
【发布时间】:2015-07-22 15:42:14
【问题描述】:
  • 我刚刚发现了关于 apache solr 的信息,并且在我成功使用 Tomcat 安装了 apache Solr 之后。我开始使用 Apache Solr 进行搜索。
  • 但是我对 Apache Solr 的结果有些问题。
  • 当我查询与title: love 相同的字段时,URL 与以下相同:
    • http://my_ip:8080/solr/music/select?q=title%3A+love&wt=json&indent=true.
    • Apache Solr 返回很多结果title 与单词 love 匹配。
  • 这里的问题如果我查询相同:love,并且 URL 相同:
    • http://my_ip:8080/solr/music/select?q=love&wt=json&indent=true
    • Apache Solr 没有返回任何结果

我想问为什么q=love没有返回任何结果?希望大家可以帮助我。非常感谢。

这是我的schema.xml 文件:

<schema name="example" version="1.5">
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="title" type="text_vi" indexed="true" stored="true"/>
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field name="type_music" type="text_vi" indexed="true" stored="true"/>

<dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>
<dynamicField name="*_is" type="int"    indexed="true"  stored="true"  multiValued="true"/>
<dynamicField name="*_s"  type="string"  indexed="true"  stored="true" />
<dynamicField name="*_ss" type="string"  indexed="true"  stored="true" multiValued="true"/>
<dynamicField name="*_l"  type="long"   indexed="true"  stored="true"/>
<dynamicField name="*_ls" type="long"   indexed="true"  stored="true"  multiValued="true"/>
<dynamicField name="*_t"  type="text_general"    indexed="true"  stored="true"/>
<dynamicField name="*_txt" type="text_general"   indexed="true"  stored="true" multiValued="true"/>
<dynamicField name="*_en"  type="text_en"    indexed="true"  stored="true" multiValued="true"/>
<dynamicField name="*_b"  type="boolean" indexed="true" stored="true"/>
<dynamicField name="*_bs" type="boolean" indexed="true" stored="true"  multiValued="true"/>
<dynamicField name="*_f"  type="float"  indexed="true"  stored="true"/>
<dynamicField name="*_fs" type="float"  indexed="true"  stored="true"  multiValued="true"/>
<dynamicField name="*_d"  type="double" indexed="true"  stored="true"/>
<dynamicField name="*_ds" type="double" indexed="true"  stored="true"  multiValued="true"/>

<!-- Type used to index the lat and lon components for the "location" FieldType -->
<dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="false" />

<dynamicField name="*_dt"  type="date"    indexed="true"  stored="true"/>
<dynamicField name="*_dts" type="date"    indexed="true"  stored="true" multiValued="true"/>
<dynamicField name="*_p"  type="location" indexed="true" stored="true"/>

<!-- some trie-coded dynamic fields for faster range queries -->
<dynamicField name="*_ti" type="tint"    indexed="true"  stored="true"/>
<dynamicField name="*_tl" type="tlong"   indexed="true"  stored="true"/>
<dynamicField name="*_tf" type="tfloat"  indexed="true"  stored="true"/>
<dynamicField name="*_td" type="tdouble" indexed="true"  stored="true"/>
<dynamicField name="*_tdt" type="tdate"  indexed="true"  stored="true"/>

<dynamicField name="*_c"   type="currency" indexed="true"  stored="true"/>

<dynamicField name="ignored_*" type="ignored" multiValued="true"/>
<dynamicField name="attr_*" type="text_general" indexed="true" stored="true" multiValued="true"/>

<dynamicField name="random_*" type="random" />
<uniqueKey>id</uniqueKey>

<fieldType name="string" class="solr.StrField" sortMissingLast="true" />

<!-- boolean type: "true" or "false" -->
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="tint" class="solr.TrieIntField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tfloat" class="solr.TrieFloatField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tlong" class="solr.TrieLongField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
<fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>

这是我的solrconfig.xml 文件:

<luceneMatchVersion>4.9</luceneMatchVersion>
<lib dir="../../../contrib/analysis-extras/lib" regex=".*\.jar" />
<lib dir="../../../contrib/extraction/lib" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-cell-\d.*\.jar" />
<lib dir="../../../contrib/clustering/lib/" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-clustering-\d.*\.jar" />
<lib dir="../../../contrib/langid/lib/" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-langid-\d.*\.jar" />
<lib dir="../../../contrib/velocity/lib" regex=".*\.jar" />
<lib dir="../../../dist/" regex="solr-velocity-\d.*\.jar" />
<lib dir="../../../contrib/dataimporthandler/lib" regex=".*\.jar" />
<lib dir="/home/my_name/apache_solr/apache-tomcat-8.0.24/dist" regex="solr-dataimporthandler-4.9.0.jar" />
<lib dir="/home/my_name/apache_solr/apache-tomcat-8.0.24/dist" regex="solr-dataimporthandler-extras-4.9.0.jar" />
<lib dir="../../../lib" regex="mysql-connector-java-5.1.31-bin.jar" />

这是data-config.xml文件:

<dataConfig>
<dataSource type="JdbcDataSource"  driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1/sieunhac_development"  user="root"  password=""/>
<document name="musics">
<entity name="musics" pk="id"
  query="select p.id, LCASE(p.title) as title, birthday_singer, p.type_music from musics p order by updated_at desc;">
  <field column="id" name="id" template="id"/>
  <field column="title" name="title"/>

  <field name="type_music" column="type_music" />
</entity>
</document>
</dataConfig>

【问题讨论】:

    标签: tomcat solr solr4


    【解决方案1】:

    如果您查看 solrconfig.xml 文件,您会看到 /select requestHandler 配置了默认搜索字段:

    <lst name="defaults">
      <str name="df">name</str>
    </lst>
    

    在这里,您可以输入您想要的字段,例如:

    <lst name="defaults">
      <str name="df">title</str>
    </lst>
    

    您可以查看有关this subjectSolr Documentation 的另一个主题。

    更新

    要回复您的评论,您可以在schema.xml 中创建一个新字段:

    <field name="searchable_field" type="text_general" indexed="true" stored="true"  multiValued="true" />
    

    之后,您可以在新字段中复制所需的字段:

    <copyField source="title" dest="searchable_field"/>
    <copyField source="author" dest="searchable_field"/>
    <copyField source="production" dest="searchable_field"/>
    

    最后,您只需将这个新字段放入您的solrconfig.xml

    <lst name="defaults">
      <str name="df">searchable_field</str>
    </lst>
    

    【讨论】:

    • 我刚试过,效果很好。非常感谢。顺便说一句,如果我不仅要搜索field title,还要搜索其他字段(组合)。有什么解决办法吗?
    • 太棒了。非常感谢。
    • 是的,你的回答很清楚。再次感谢您。
    猜你喜欢
    • 2017-09-16
    • 1970-01-01
    • 2015-02-28
    • 2015-11-12
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 2017-03-20
    相关资源
    最近更新 更多