gpt4 book ai didi

search - Solr 不会搜索属于嵌套实体的字段

转载 作者:行者123 更新时间:2023-11-28 23:03:20 25 4
gpt4 key购买 nike

我正在使用 apache solr 来构建网站搜索。我正在使用嵌套实体从不同的表中导入数据。数据导入成功,所有文档都被添加到索引中。我的数据配置是这样的:

<dataConfig>
<dataSource type="JdbcDataSource" driver ="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/purplle_purplle2" user="purplle_purplle" password="purplle123" />

<document name="doc">
<entity name="offer" query="SELECT * FROM service_offering WHERE module LIKE 'location' ">

<field column="name" name="name"/>
<field column="id" name="id" />
<field column="type_id" name="type_id" />

<entity name="offer_type" query=" select name from service_offeringtype where id='${offer.type_id}'" >
<field column="name" name="offer_type" />
</entity>

<entity name="offer_location" query=" select name from service_location where id='${offer.module_id}'" >
<field column="name" name="location_name" />
</entity>

<entity name="offer_address" query=" select * from service_address where module_id='${offer.module_id}' AND module LIKE 'location'" >

<entity name="loc_city" query=" select name from loc_city where id='${offer_address.city}'" >
<field column="name" name="loc_city" />
</entity>

<entity name="loc_area" query=" select name from loc_area where id='${offer_address.area}'" >
<field column="name" name="loc_area" />
</entity>

<entity name="loc_zone" query=" select name from loc_zone where id='${offer_address.zone}'" >
<field column="name" name="loc_zone" />
</entity>

</entity>

</entity>

</document>

</dataConfig>

现在,如果我直接对该索引进行搜索。仅为“名称”字段获取结果。它为其他字段返回 null,即“loc_area”、“location_name”、“loc_city”等。我的架构看起来像这样

<field name="id"  type="int" indexed="true" stored="true" /> 
<field name="name" type="string" indexed="true" stored="true" />
<field name="offer_type" type="string" indexed="true" stored="true" />
<field name="location_name" type="string" indexed="true" stored="true" />
<field name="type_id" type="string" indexed="true" stored="true" />
<field name="loc_city" type="string" indexed="true" stored="true" />
<field name="loc_area" type="string" indexed="true" stored="true" />
<field name="loc_zone" type="string" indexed="true" stored="true" />

但是,如果我将这些字段复制到 schema.xml 中默认存在的“文本”字段中。然后通过搜索“文本”字段,我很容易得到相关结果。

<copyField source="name" dest="text"/>
<copyField source="offer_type" dest="text"/>
<copyField source="location_name" dest="text"/>
<copyField source="loc_city" dest="text"/>
<copyField source="loc_area" dest="text"/>
<copyField source="loc_zone" dest="text"/>

但我不能这样做,因为我必须将提升级别分配给不同的字段以计算分数。当我将其附加到查询语法“&defType=edismax&qf=name^1.0+location_name^10.0+loc_area^50.0”时,它返回空结果。

怎么了?

最佳答案

我猜你的问题是你的字段类型。我不知道你的字段到底包含什么,但是 type="string"type = "text" 是有区别的。

String 类型索引整个字段输入的未标记化字符串值。文本类型对字段进行标记化和分析。例如,如果我针对包含“John Smith”的字符串字段搜索“john”,我预计不会命中,如果该字段是文本字段,我会命中。

由于您的查询似乎适用于文本字段,而不是字符串字段,因此更改类型和重建索引似乎是一个可能的解决方案。

关于search - Solr 不会搜索属于嵌套实体的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14440673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com