11

我有一个 Solr 架构,其中包含一个location字段(使用默认值solr.LatLonType):

<field name="latlng" type="location" indexed="true" stored="true"/>

我正在尝试使用 DataImportHandler 填充它。目前我SELECT的值是 nvarchar,格式为17.74628,-64.70725; 但是它没有填充 Solr 字段(它保持为空)。

此列应该采用什么类型和格式来更新locationSolr 中的字段?

4

2 回答 2

15

solr.LatLonType 是多维类型;您可以将字段类型定义为:

<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>

使用您的“latlng”字段名称,坐标字段的模式将如下所示(注意用于二维字段类型 solr.LatLonType 的“subFieldSuffix”):

<field name="latlng" type="location" indexed="true" stored="true" />
<field name="latlng_0_coordinate" type="double" indexed="true" stored="true" />
<field name="latlng_1_coordinate" type="double" indexed="true" stored="true" />

“latlng_0_coordinate”应该是纬度,“latlng_1_coordinate”应该是经度。您的选择语句应加载“latlng_0_coordinate”和“latlng_1_coordinate”作为双精度数。

于 2011-09-22T21:36:34.813 回答
3

上一个答案有效,因为您正在手动创建 Solr 用于单独存储 lat 和 long 的字段,但是为此目的有一个动态字段。

<!-- Type used to index the lat and lon components for the "location" FieldType --> <dynamicField name="*_coordinate" type="tdouble" indexed="true" stored="false" />

如果您检查字段类型位置,您可能会发现它使用后缀 _coordinate 作为它们的值:

<!-- A specialized field for geospatial search. If indexed, this fieldType must not be multivalued. -->

<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>

这在 Solr 4 beta 中对我有用,我相信自 Solr 3.6 或更早版本就存在。无论如何,只是另一种解决方案!

希望这可以帮助。

于 2012-09-13T02:20:22.083 回答