Java Code Examples for com.google.appengine.api.search.Query#Builder
The following examples show how to use
com.google.appengine.api.search.Query#Builder .
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: SearchServiceTest.java From appengine-tck with Apache License 2.0 | 6 votes |
@Test public void testSearchAsyncQuery() throws ExecutionException, 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) { QueryOptions.Builder optionBuilder = QueryOptions.newBuilder(); optionBuilder.setLimit(10); Query.Builder queryBuilder = Query.newBuilder().setOptions(optionBuilder.build()); Future<Results<ScoredDocument>> Fres = oneIndex.searchAsync(queryBuilder.build("")); Iterator<ScoredDocument> it = Fres.get().iterator(); assertEquals(docId + "1", it.next().getId()); assertEquals(docId + "2", it.next().getId()); sync(); } }
Example 2
Source File: SearchTestBase.java From appengine-tck with Apache License 2.0 | 5 votes |
protected Results<ScoredDocument> searchDocs(Index index, String query, int limit) { if (limit > 0) { QueryOptions.Builder optionBuilder = QueryOptions.newBuilder(); optionBuilder.setLimit(limit); Query.Builder queryBuilder = Query.newBuilder().setOptions(optionBuilder.build()); return index.search(queryBuilder.build(query)); } else { return index.search(query); } }
Example 3
Source File: SearchServiceTest.java From appengine-tck with Apache License 2.0 | 5 votes |
@Test public void testSortOptions() { for (SortExpression.SortDirection direction : SortExpression.SortDirection.values()) { SortExpression sortExpression = SortExpression.newBuilder() .setExpression("numfield") .setDirection(direction) .setDefaultValueNumeric(9999) .build(); SortOptions sortOptions = SortOptions.newBuilder() .addSortExpression(sortExpression) .build(); QueryOptions options = QueryOptions.newBuilder() .setFieldsToReturn("numfield", "datefield") .setSortOptions(sortOptions) .build(); Query.Builder queryBuilder = Query.newBuilder().setOptions(options); Results<ScoredDocument> results = index.search(queryBuilder.build("")); double pre = -9999; if (direction.equals(SortExpression.SortDirection.DESCENDING)) { pre = 9999; } for (ScoredDocument doc : results) { assertEquals(2, doc.getFieldNames().size()); for (Field numField : doc.getFields("numfield")) { if (direction.equals(SortExpression.SortDirection.DESCENDING)) { assertTrue(pre > numField.getNumber()); } else { assertTrue(pre < numField.getNumber()); } pre = numField.getNumber(); } } } }