本文整理汇总了Java中com.google.appengine.api.search.Index.getRange方法的典型用法代码示例。如果您正苦于以下问题:Java Index.getRange方法的具体用法?Java Index.getRange怎么用?Java Index.getRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.search.Index
的用法示例。
在下文中一共展示了Index.getRange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeAll
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
protected int removeAll() {
int count = 0;
Index index = getIndex();
GetRequest request = GetRequest.newBuilder().setReturningIdsOnly(true).setLimit(200).build();
GetResponse<Document> response = index.getRange(request);
// can only deleteUnit documents in blocks of 200 so we need to iterate until they're all gone
while (!response.getResults().isEmpty()) {
List<String> ids = new ArrayList<>();
for (Document document : response) {
ids.add(document.getId());
}
index.delete(ids);
count += ids.size();
response = index.getRange(request);
}
return count;
}
示例2: removeAllDocumentsFromIndex
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
/**
* Cleans the index of places from all entries.
*/
private void removeAllDocumentsFromIndex() {
Index index = PlacesHelper.getIndex();
// As the request will only return up to 1000 documents,
// we need to loop until there are no more documents in the index.
// We batch delete 1000 documents per iteration.
final int numberOfDocuments = 1000;
while (true) {
GetRequest request = GetRequest.newBuilder()
.setReturningIdsOnly(true)
.build();
ArrayList<String> documentIds = new ArrayList<>(numberOfDocuments);
GetResponse<Document> response = index.getRange(request);
for (Document document : response.getResults()) {
documentIds.add(document.getId());
}
if (documentIds.size() == 0) {
break;
}
index.delete(documentIds);
}
}
示例3: doGet
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
Document document = Document.newBuilder()
.setId("AZ125")
.addField(Field.newBuilder().setName("myField").setText("myValue")).build();
try {
Utils.indexADocument(INDEX, document);
} catch (InterruptedException e) {
out.println("Interrupted");
return;
}
out.println("Indexed a new document.");
// [START get_document]
IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
// Fetch a single document by its doc_id
Document doc = index.get("AZ125");
// Fetch a range of documents by their doc_ids
GetResponse<Document> docs = index.getRange(
GetRequest.newBuilder().setStartId("AZ125").setLimit(100).build());
// [END get_document]
out.println("myField: " + docs.getResults().get(0).getOnlyField("myField").getText());
}
示例4: testPutGetRangeGetRequest
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Test
public void testPutGetRangeGetRequest() throws InterruptedException {
String indexName = "put-index";
String docId = "testPutDocs";
Index index = createIndex(indexName, docId);
GetIndexesRequest request = GetIndexesRequest.newBuilder()
.setIndexNamePrefix(indexName)
.build();
GetResponse<Index> response = searchService.getIndexes(request);
List<Index> listIndexes = response.getResults();
for (Index oneIndex : listIndexes) {
GetResponse<Document> docs = oneIndex.getRange(GetRequest.newBuilder().setStartId(docId + "1").setLimit(10).build());
sync();
assertEquals(docs.getResults().size(), 2);
}
}
示例5: testPutGetRangeBuilder
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Test
public void testPutGetRangeBuilder() throws InterruptedException {
String indexName = "put-index";
String docId = "testPutDocs";
Index index = createIndex(indexName, docId);
GetIndexesRequest request = GetIndexesRequest.newBuilder()
.setIndexNamePrefix(indexName)
.build();
GetResponse<Index> response = searchService.getIndexes(request);
List<Index> listIndexes = response.getResults();
for (Index oneIndex : listIndexes) {
GetResponse<Document> docs = oneIndex.getRange(GetRequest.newBuilder().setStartId(docId + "1").setLimit(10));
sync();
assertEquals(docs.getResults().size(), 2);
}
}
示例6: doGet
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
Document document =
Document.newBuilder()
.setId("AZ125")
.addField(Field.newBuilder().setName("myField").setText("myValue"))
.build();
try {
Utils.indexADocument(INDEX, document);
} catch (InterruptedException e) {
out.println("Interrupted");
return;
}
out.println("Indexed a new document.");
// [START get_document]
IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build();
Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec);
// Fetch a single document by its doc_id
Document doc = index.get("AZ125");
// Fetch a range of documents by their doc_ids
GetResponse<Document> docs =
index.getRange(GetRequest.newBuilder().setStartId("AZ125").setLimit(100).build());
// [END get_document]
out.println("myField: " + docs.getResults().get(0).getOnlyField("myField").getText());
}
示例7: removeAllDocumentsFromIndex
import com.google.appengine.api.search.Index; //导入方法依赖的package包/类
private void removeAllDocumentsFromIndex() {
Index index = PlacesHelper.getIndex();
GetRequest request = GetRequest.newBuilder().setReturningIdsOnly(true).build();
GetResponse<Document> response = index.getRange(request);
for (Document document : response.getResults()) {
index.delete(document.getId());
}
}
开发者ID:googlearchive,项目名称:solutions-mobile-shopping-assistant-backend-java,代码行数:11,代码来源:MaintenanceTasksServlet.java