在Google App Engine中创建全文搜索索引

时间:2012-07-11 01:54:07

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

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

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

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

由于

2 个答案:

答案 0 :(得分: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查找现有索引,而不是使用可能创建它们的代码,只是为了避免尝试在我的代码中获取索引,而是无意中更改规范。

答案 1 :(得分:0)

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