在 solr 4.9 中使用 q=*:* && q={keyword} && q=field:{keyword} 查询
Query with q=*:* && q={keyword} && q=field:{keyword} in solr 4.9
- 我刚刚找到有关 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 returned 很多结果
title
与单词 love
. 匹配
- 这里的问题如果我查询与:
love
相同,而 URL 与:
http://my_ip:8080/solr/music/select?q=love&wt=json&indent=true
- Apache Solr 没有return任何结果。
想问一下为什么q=love
没有return结果?希望大家帮帮我。非常感谢。
这是我的 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>
如果您查看 solrconfig.xml
文件,您会看到 /select requestHandler
配置了默认搜索字段如:
<lst name="defaults">
<str name="df">name</str>
</lst>
在这里,您可以输入您想要的字段,例如:
<lst name="defaults">
<str name="df">title</str>
</lst>
您可以查看另一个关于 this subject and the Solr 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>
- 我刚刚找到有关 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 returned 很多结果
title
与单词love
. 匹配
- 这里的问题如果我查询与:
love
相同,而 URL 与:http://my_ip:8080/solr/music/select?q=love&wt=json&indent=true
- Apache Solr 没有return任何结果。
想问一下为什么q=love
没有return结果?希望大家帮帮我。非常感谢。
这是我的 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>
如果您查看 solrconfig.xml
文件,您会看到 /select requestHandler
配置了默认搜索字段如:
<lst name="defaults">
<str name="df">name</str>
</lst>
在这里,您可以输入您想要的字段,例如:
<lst name="defaults">
<str name="df">title</str>
</lst>
您可以查看另一个关于 this subject and the Solr 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>