查询q = *:*&& q = {keyword}&& q = field:solr 4.9中的{keyword}

时间:2015-07-22 15:42:14

标签: tomcat solr solr4

  • 我刚刚发现了apache solr,并且在我成功安装了apache Solr和Tomcat之后。我开始使用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>

1 个答案:

答案 0 :(得分:2)

如果查看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>