【问题标题】:java code for solr geolocation indexingsolr地理定位索引的java代码
【发布时间】:2014-01-27 07:18:39
【问题描述】:

我正在使用 solr 来修复我的索引和搜索功能,并且是 solr 的初学者。 我实际上想将地理位置索引到 solr 索引中,并且还想对其进行查询,所以浏览了一些文章, http://wiki.apache.org/solr/SpatialSearch 我的 schema.xml 中确实存在一些架构类型。

现在我的问题是我想编写一个 java 代码来索引地理位置,同时为动态地理位置字段索引它。那么如何编写它,是否有任何用于索引它的示例 java 代码。我找了它,但没有找到,请如果有人可以帮助我。

我也明白,在建立索引时,我们需要写一些类似的东西:

document.addField(myDynLocFld+"_p", val));

如果使用这种方法,val 应该是一个位置对象的实例,其中嵌入了 lat 和 lng 值。那么如何解决这个问题,或者 solr java 中是否有任何不同的方法呢?

提前致谢。

【问题讨论】:

    标签: solr solrj


    【解决方案1】:

    检查此代码示例,

    // Store the index in memory:
    //Directory directory = new RAMDirectory();
    // To store an index on disk
    Directory directory = FSDirectory.open("/tmp/testindex");
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer);
    IndexWriter iwriter = new IndexWriter(directory, config);
    Document doc = new Document();
    String text = "This is the text to be indexed.";
    doc.add(new Field("fieldname", text, TextField.TYPE_STORED));
    iwriter.addDocument(doc);
    iwriter.close();
    

    更多详情请查看Lucene APIs

    【讨论】:

    • 这段代码 sn-p 用于 lucene 将单个文档索引到索引中。我希望 java 代码将 geolcation 详细信息添加到 solr 的 SolrInputDocument 并索引然后获取它们。
    猜你喜欢
    • 1970-01-01
    • 2023-03-16
    • 2020-11-28
    • 2016-07-24
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多