0

使用 Google App Engine 的搜索 API,我正在尝试将一些文档索引到测试索引中。我正在使用 Google App Engine 官方文档中给出的代码示例。但是当我尝试运行下面的代码段时。当我通过以下方式放置文档时出现以下错误index.put

线程“主”com.google.apphosting.api.ApiProxy$CallNotFoundException 中的异常:未找到 API 包“搜索”或调用“IndexDocument()”。在 com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:179) 在 com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:177) 在 com.google.appengine.api.utils .FutureWrapper.get(FutureWrapper.java:88) 在 com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88) 在 com.google.appengine.api.search.FutureHelper.getInternal(FutureHelper.java :73) 在 com.google.appengine.api.search.FutureHelper.quietGet(FutureHelper.java:32) 在 com.google.appengine.api.search.IndexImpl.put(IndexImpl.java:486) 在 test.service。 SearchingService.indexADocument(SearchingService.java:52)

这是代码片段:

 IndexSpec indexSpec = IndexSpec.newBuilder().setName(indexName).build();

          SearchService service = SearchServiceFactory.getSearchService(
                   SearchServiceConfig.newBuilder().setDeadline(10.0).setNamespace("geeky").build());
          Index index = service.getIndex(indexSpec);



          final int maxRetry = 3;
          int attempts = 0;
          int delay = 2;
          while (true) {
            try {

              index.put(document); // ERROR!!!!!!!!!!
            } catch (PutException e) {
              if (StatusCode.TRANSIENT_ERROR.equals(e.getOperationResult().getCode())
                  && ++attempts < maxRetry) { // retrying
                Thread.sleep(delay * 1000);
                delay *= 2; // easy exponential backoff
                continue;
              } else {
                throw e; // otherwise throw
              }
            }
            break;
          }

        }

我正在将 appengine-java-sdk-1.9.18 与 Eclipse Kepler 一起使用。我是在本地开发服务器上运行代码还是在 apppot 上托管的生产环境中运行代码都没有关系。我犯了同样的错误。我已经在 Eclipse 中通过我的谷歌帐户进行身份验证,并且能够通过 Eclipse 将我的代码推送到生产环境中。以前有人见过这个错误吗?

4

1 回答 1

0

因此,在尝试调用 Search API 时需要注意的事项很少。我的设置中的第一个错误是我使用的是旧版本的 GAE SDK (1.9.18)。

修复该问题后,尝试索引文档时仍然出现错误。我从 appengine 上下文中调用了搜索查询函数,但我的索引导致了同样的错误,因为它是从“主”函数运行的。应始终在 appengine 上下文中运行 Search API 的所有功能。

于 2016-08-16T12:50:32.990 回答