0

我刚刚开始在 Solr 周围玩一点,并设法让它在 Tomcat servlet 容器中运行。我现在想使用 Spring Data 中的存储库方法,但在尝试处理 lat/lon 字段(即:地理空间数据)时遇到了困难。我想存储一些类似推文的数据。这是我目前使用的模式(试图遵循wiki):

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="tweets" version="1.1">

  <types>

    <fieldType name="string" class="solr.StrField"/>

    <fieldType name="text1" class="solr.TextField">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.HunspellStemFilterFactory" 
                dictionary="../../dictionaries/es_ANY.dic" 
                affix="../../dictionaries/es_ANY.aff" 
                ignoreCase="true" />
        <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
      </analyzer>
    </fieldType>

    <fieldType name="text2" class="solr.TextField">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

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

    <dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="false"/>

    <fieldType name="date" class="solr.DateField"/>

    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>

  </types>

  <fields>
    <field name="id" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="username" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="pictureURL" type="string" indexed="false" stored="true" multiValued="false"/>
    <field name="topic" type="string" indexed="true" stored="true" multiValued="false"/>
    <field name="content" type="text1" indexed="true" stored="true"/>
    <field name="hashtags" type="text2" indexed="true" stored="true"/>
    <field name="geo" type="location" indexed="true" stored="true"/>
    <field name="timestamp" type="date" indexed="true" stored="true"/>
    <field name="_version_" type="long" indexed="true" stored="true"/>
  </fields>

  <uniqueKey>id</uniqueKey>
  <defaultSearchField>id</defaultSearchField>

</schema>

如果没有地理字段,这会很好,我不知道如何在我的 POJO 中进行映射(我尝试在地理字段中使用双重 [],如 MongoDB 和 String,但没有取得多大成功):

public class Tweet {

    @Id
    @Field
    private String id;

    @Field
    private String username;

    @Field
    private String pictureURL;

    @Field
    private String topic;

    @Field
    private String content;

    @Field
    private List<String> hashtags;

    @Field
    private String geo;

    @Field
    private Date timestamp;

    /** Getters/setters omitted **/
}

将地理字段映射为简单字符串 ([lat],[lng]) 时,抛出的异常是:

org.springframework.data.solr.UncategorizedSolrException: undefined field: "geo_0_coordinate"; nested exception is org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: undefined field: "geo_0_coordinate"

我尝试查看项目测试,但没有找到任何使用地理字段的 POJO。

关于如何进行的任何想法?

谢谢!

4

1 回答 1

0

我终于找到了解决方案。首先,geo 字段应该是一个 GeoLocation:

@Field
private GeoLocation geo;

schema.xml 文件中需要进行另一项更改:

<fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
<fieldType name="double" class="solr.DoubleField"/>
<dynamicField name="*_coordinate"  type="tdouble" indexed="true"  stored="false"/>

<!-- ... -->

<field name="geo" type="location" indexed="true" stored="true"/>
<field name="geo_0_coordinate" type="double" indexed="true" stored="true" />
<field name="geo_1_coordinate" type="double" indexed="true" stored="true" />

事实证明,Solr 在内部将 LatLonTypes 存储为一对也应在模式中定义的双精度数。

希望这对其他人有帮助!

于 2013-10-23T14:43:07.157 回答