使用lucene配置mysql时无法按某些列搜索
我的数据库有三列,我将 lucene 配置为索引。但是,我只能搜索其中之一。完整的描述如下:
我按照这些说明配置 solr 以使用 mysql 数据:
http://digitalpbk.com/apachesolr/apache-solr-mysql-sample-data-config
我下载了jdbc驱动程序,将其放在/example/lib中,并创建了一个新的/example/conf/solrconfig.xml 中的 requestHandler
。
我的数据库表 items
有三列:
id
:int、primary、autoincrement key名称
:varchar(256)描述
: varchar(511)
因此,我创建以下 data-config.xml:
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://SERVER/DATABASE"
user="USERNAME"
password="PASSWORD"/>
<document name="content">
<entity name="node" query="select id, name, description from items">
<field column="id" name="id" />
<field column="name" name="name" />
<field column="description" name="description" />
</entity>
</document>
</dataConfig>
接下来,我在 /example/solr/conf 中编辑 schema.xml 以使其知道关于新名称:
<field name="id" type="string" indexed="true" stored="true">
<field name="name" type="string" indexed="true" stored="true">
<field name="description" type="string" indexed="true" stored="true">
我必须取消注释先前在此文件中存在的 id 和 name 的描述,因为它们与我的描述冲突。
接下来,我成功导入了数据库(大约 100K 行)。
最后,我可以成功地按 name
进行搜索,但无法按 description
或 id
进行搜索。我不明白为什么会这样。任何帮助或指示将不胜感激。
My database has three columns, which I configured lucene to index. However, I can search by only one of them. Complete description is the following:
I am following these instructions to configure solr to use mysql data:
http://digitalpbk.com/apachesolr/apache-solr-mysql-sample-data-config
I downloaded the jdbc driver, put it in /example/lib, and created a new requestHandler
in /example/conf/solrconfig.xml.
My database table items
has three columns:
id
: int, primary, autoincrement keyname
: varchar(256)description
: varchar(511)
So, I create following data-config.xml:
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://SERVER/DATABASE"
user="USERNAME"
password="PASSWORD"/>
<document name="content">
<entity name="node" query="select id, name, description from items">
<field column="id" name="id" />
<field column="name" name="name" />
<field column="description" name="description" />
</entity>
</document>
</dataConfig>
Next, I edit schema.xml in /example/solr/conf to let it know about new names:
<field name="id" type="string" indexed="true" stored="true">
<field name="name" type="string" indexed="true" stored="true">
<field name="description" type="string" indexed="true" stored="true">
I had to uncomment the descriptions of id
and name
which were present in this file earlier, since they clashed with my descriptions.
Next, I imported the database (around 100K rows) successfully.
At the end of all this, I can successfully search by name
, but I am unable to search by description
or by id
. I do not understand why this should be the case. Any help or pointers would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
名称字段可以是要搜索的默认字段名称。因此,请确保您在查询中引用字段名称。
要在
description
字段中搜索,请使用查询:description:queryString
要在所有字段中搜索,请使用查询:
id:queryString OR name:queryString OR description:queryString
有关详细信息,请检查 http://wiki.apache.org/solr/SolrRelevancyFAQ
Name field may be the default field name to search. So make sure you are referring the field names in your query.
To search in
description
field use query:description:queryString
To search in all fields use query:
id:queryString OR name:queryString OR description:queryString
For more information please check http://wiki.apache.org/solr/SolrRelevancyFAQ