我已经安装了solr 4.5(带有Tomcat 7.0.37容器)并从MySQL数据库导入了数据。通过对collection1的solr admin默认查询,我可以看到所有数据都已导入并编入索引。索引数据涉及一个主表意见和一个相关的表度假村。我对意见表中的字段进行默认搜索没有问题,但无法对相关嵌套表格中的字段进行默认搜索。 (我已将所有意见字段和度假村相关字段复制到默认文本字段中。)在solr管理查询中使用collection1,在q框中输入resort_name:Galveston,显示预期结果,但输入Galveston,显示0结果。
这是我的data-config.xml主要内容
<entity name="opinion" pk="Id" query="select Id, fd1, Resort_id,
fd2, Create_date, Update_date FROM mydb.opinion"
deltaImportQuery="select * FROM mydb.opinion where Id = '${dih.delta.Id}'"
deltaQuery="select Id FROM mydb.opinion
WHERE Create_date > '${dih.last_index_time}' OR
Update_date > '${dih.last_index_time}'"
transformer="RegexTransformer">
<field column="Id" name="id" />
<field column="fd1" name="fd1" />
<field column="Resort_id" name="Resort_id" />
<field column="fd2" name="fd2" />
<field column="Create_date" name="Create_date" />
<field column="Update_date" name="Update_date"/>
<entity name="resort" pk="Id" query="select Id, Resort_name, State_prov, Country from mydb.resorts where Id='${opinion.Resort_id}'"
deltaQuery="select Id FROM mydb.resorts WHERE Create_date > '${dih.last_index_time}' OR Update_date > '${dih.last_index_time}'"
parentDeltaQuery="select Resort_id from opinion where Resort_Id=${resort.Id}"
transformer="RegexTransformer">
<field name="rstid" column="Id" />
<field name="Resort_name" column="Resort_name" />
<field name="State_prov" column="State_prov" />
<field name="Country" column="Country" />
</entity>
</entity>
我知道默认搜索会转到&#34; text&#34;字段,我已将相关的嵌套字段复制到schema.xml中的文本字段。这是schema.xml中的部分:
...
<field name="Resort_name" type="text_general" indexed="true" stored="true" multiValued="false" />
<field name="State_prov" type="text_general" indexed="true" stored="true" multiValued="false" />
<field name="Country" type="text_general" indexed="true" stored="true" multiValued="false"/>
<!-- this is for Id of resorts table -->
<field name="rstid" type="string" indexed="true" stored="true" required="true" />
...
<uniqueKey>id</uniqueKey>
....
<copyField source="id" dest="text"/>
<copyField source="rstid" dest="text"/>
<copyField source="fd1" dest="text"/>
<copyField source="fd2" dest="text"/>
<copyField source="Resort_id" dest="text"/>
<copyfield source="Create_date" dest="text"/>
<copyfield source="Update_date" dest="text"/>
<copyfield source="Resort_name" dest="text"/>
<copyfield source="State_prov" dest="text"/>
<copyfield source="Country" type="text"/>
In solrconfig.xml, I added the following part to the installed solrconfig.xml:
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">my-data-config.xml</str>
</lst>
</requestHandler>
I did not modify anything else in the solrconfig.xml, here is the select and query request handler:
<requestHandler name="/select" class="solr.SearchHandler">
<!-- default values for query parameters can be specified, these
will be overridden by parameters in the request
-->
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="df">text</str>
</lst>
</requestHandler>
<!-- A request handler that returns indented JSON by default -->
<requestHandler name="/query" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">text</str>
</lst>
</requestHandler>
嵌套表字段的默认搜索对我的应用程序很重要,而且我已经停留在这个solr配置上好几天了。任何建议或帮助都将受到高度赞赏!