本文整理汇总了Java中com.google.appengine.api.search.GetRequest类的典型用法代码示例。如果您正苦于以下问题:Java GetRequest类的具体用法?Java GetRequest怎么用?Java GetRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetRequest类属于com.google.appengine.api.search包,在下文中一共展示了GetRequest类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeAll
import com.google.appengine.api.search.GetRequest; //导入依赖的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: clear
import com.google.appengine.api.search.GetRequest; //导入依赖的package包/类
@Override
public <E> int clear(Class<E> entityClass) {
Index index = getIndex(entityClass);
GetRequest request = GetRequest.newBuilder()
.setReturningIdsOnly(true)
.setLimit(200) //Delete only allows 200 records at a time.
.build();
int count = 0;
for (List<Document> documents = getDocumentIds(index, request); !documents.isEmpty(); documents = getDocumentIds(index, request)) {
count += documents.size();
unindex(entityClass, documents.stream().map(Document::getId));
}
return count;
}
示例3: removeAllDocumentsFromIndex
import com.google.appengine.api.search.GetRequest; //导入依赖的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);
}
}
示例4: doGet
import com.google.appengine.api.search.GetRequest; //导入依赖的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());
}
示例5: testPutGetRangeGetRequest
import com.google.appengine.api.search.GetRequest; //导入依赖的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);
}
}
示例6: testPutGetRangeBuilder
import com.google.appengine.api.search.GetRequest; //导入依赖的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);
}
}
示例7: testPutGetRangeAsyncGetResponse
import com.google.appengine.api.search.GetRequest; //导入依赖的package包/类
@Test
public void testPutGetRangeAsyncGetResponse() throws InterruptedException, ExecutionException {
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) {
Future<GetResponse<Document>> futurDocs = oneIndex.getRangeAsync(GetRequest.newBuilder().setStartId(docId + "1").setLimit(10).build());
sync();
assertEquals(futurDocs.get().getResults().size(), 2);
}
}
示例8: testPutGetRangeAsyncBuilder
import com.google.appengine.api.search.GetRequest; //导入依赖的package包/类
@Test
public void testPutGetRangeAsyncBuilder() throws InterruptedException, ExecutionException {
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) {
Future<GetResponse<Document>> futurDocs = oneIndex.getRangeAsync(GetRequest.newBuilder().setStartId(docId + "1").setLimit(10));
sync();
assertEquals(futurDocs.get().getResults().size(), 2);
}
}
示例9: doGet
import com.google.appengine.api.search.GetRequest; //导入依赖的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());
}
示例10: verifyDocCount
import com.google.appengine.api.search.GetRequest; //导入依赖的package包/类
private void verifyDocCount(Index index, int docCount) {
if (docCount == -1) {
String name = index.getName();
docCount = Integer.valueOf(name.substring(name.length() - 1));
}
List<Document> docList = index.getRange(GetRequest.newBuilder().build()).getResults();
assertEquals(docCount, docList.size());
}
示例11: removeAllDocumentsFromIndex
import com.google.appengine.api.search.GetRequest; //导入依赖的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
示例12: getDocumentIds
import com.google.appengine.api.search.GetRequest; //导入依赖的package包/类
private List<Document> getDocumentIds(Index index, GetRequest request) {
return index.getRange(request).getResults();
}