【问题标题】:Create Index for Full Text Search in Google App Engine在 Google App Engine 中为全文搜索创建索引
【发布时间】:2012-07-10 14:07:51
【问题描述】:

我正在https://developers.google.com/appengine/docs/java/search/overview 阅读有关谷歌应用引擎中全文搜索 api (java) 的文档。他们有获取索引的例子:

public Index getIndex() {
      IndexSpec indexSpec = IndexSpec.newBuilder()
          .setName("myindex")
          .setConsistency(Consistency.PER_DOCUMENT)
          .build();
      return SearchServiceFactory.getSearchService().getIndex(indexSpec);
}

创建索引怎么样?如何创建一个?

谢谢

【问题讨论】:

    标签: google-app-engine full-text-search


    【解决方案1】:

    你刚刚做到了。你刚刚创建了一个。

    public class IndexSpec
    
    Represents information about an index. This class is used to fully specify the index you want to retrieve from the SearchService. To build an instance use the newBuilder() method and set all required parameters, plus optional values different than the defaults.
    

    https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/IndexSpec

    您可以通过查看 SearchService 来确认这一点

    SearchService is also responsible for creating new indexes. For example:
     SearchService searchService = SearchServiceFactory.getSearchService();
      index = searchService.getIndex(IndexSpec.newBuilder().setName("myindex"));
    

    https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/SearchService

    无论如何,如果您的代码不存在,您的代码似乎会创建一个新索引。这就是文档的建议:

     // Get the index. If not yet created, create it.
      Index index = searchService.getIndex(
      IndexSpec.newBuilder()
          .setIndexName("indexName")
          .setConsistency(Consistency.PER_DOCUMENT));
    

    https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/search/Index

    现在,如果再次运行代码并更改一致性会发生什么?您是否拥有具有不同一致性的相同索引?索引是否被覆盖?我不知道。我会使用 SearchService 来查找现有索引,而不是使用可能创建它们的代码,以避免尝试在我的代码中获取索引但无意中更改规范。

    【讨论】:

      【解决方案2】:

      在编写文档时会隐式创建索引。一致性是索引的一个属性,即不能有两个同名的索引具有不同的一致性。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-08
        • 2011-05-23
        • 2011-02-10
        • 2017-01-15
        • 2010-11-20
        • 1970-01-01
        • 2021-11-13
        • 2011-03-20
        相关资源
        最近更新 更多