我正在尝试搜索项目中的索引。 当我用中搜索时 searchText: 学期:" S1 / 2016" AND状态:验证AND emp_id> 0 ,我得到了正确的结果。
当我用中搜索时 searchText: 学期:" S1 / 2016" AND状态:验证AND emp_id> 500 ,我收到以下异常
java.lang.NegativeArraySizeException
at com.google.appengine.api.search.dev.GenericScorer.search(GenericScorer.java:196)
at com.google.appengine.api.search.dev.LocalSearchService.searchForApp(LocalSearchService.java:584)
at com.google.appengine.api.search.dev.LocalSearchService.search(LocalSearchService.java:534)
at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:541)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:484)
at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:461)
at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:493)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:490)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
以下是执行搜索的代码:
public Results<ScoredDocument> retrieveDocuments(String searchText) {
if (searchText.length() > 2000) {
throw new InternalException(new Exception("Error - Too long query !!"),
BaseValidationMessages.SEARCH_STRING_EXCEEDS_LIMIT);
}
QueryOptions options =QueryOptions.newBuilder().setOffset(0).setLimit(2)
.setSortOptions(createSortOptions("emp_id", "asc")).build();
Query query = Query.newBuilder().setOptions(options).build(searchText);
IndexSpec indexSpec = IndexSpec.newBuilder().setName("Beneficiaries").build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
return index.search(query);
}
答案 0 :(得分:0)
如果传递给索引搜索的偏移超出可用结果计数的范围,则Google Appengine会抛出NegativeArraySizeException。
对于例如,考虑搜索索引中有50个文档可用于给定的搜索查询文本,如果搜索查询选项中设置的偏移量大于50,则在执行搜索时会抛出NegativeArraySizeException。
QueryOptions options = QueryOptions.newBuilder().setOffset(**51**)
因此,在设置偏移之前,请确保使用之前的结果可以获得偏移的文档。
第一次查询:
QueryOptions options = QueryOptions.newBuilder().setOffset(0).setLimit(50);
IndexSpec indexSpec = IndexSpec.newBuilder().setName("Beneficiaries").build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
Results<ScoredDocument>results = index.search(query);
如果从上面的查询返回的结果等于50,则搜索Next Set;
QueryOptions options = QueryOptions.newBuilder().setOffset(**51**)
如果返回的结果小于50,那么我们可以假设,没有更多的结果可用于搜索偏移&gt; 50,然后我们可以停止进一步搜索。