Java Code Examples for com.google.appengine.api.search.Index#getRange()
The following examples show how to use
com.google.appengine.api.search.Index#getRange() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaintenanceTasksServlet.java From MobileShoppingAssistant-sample with Apache License 2.0 | 6 votes |
/** * 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); } }
Example 2
Source File: IndexTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@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); } }
Example 3
Source File: IndexTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@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); } }
Example 4
Source File: IndexServlet.java From java-docs-samples with Apache License 2.0 | 5 votes |
@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()); }
Example 5
Source File: MaintenanceTasksServlet.java From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 | 5 votes |
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()); } }