private static LuceneQuery mockLuceneQuery(int limit, int pageSize) { LuceneQuery mockLuceneQuery = mock(LuceneQuery.class); when(mockLuceneQuery.getLimit()).thenReturn(limit); when(mockLuceneQuery.getPageSize()).thenReturn(pageSize); ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findKeys()) .thenReturn(Collections.emptySet()), Collections.emptySet()); rethrowAsRuntimeException(() -> when(mockLuceneQuery.findPages()) .thenThrow(newUnsupportedOperationException("Operation Not Supported!"))); ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findResults()) .thenReturn(Collections.emptyList()), Collections.emptyList()); ObjectUtils.doOperationSafely(() -> when(mockLuceneQuery.findValues()) .thenReturn(Collections.emptyList()), Collections.emptyList()); return mockLuceneQuery; }
public static void findNearbyTrainStops(LuceneService luceneService) throws InterruptedException, LuceneQueryException { LuceneQuery<Integer, TrainStop> query = luceneService.createLuceneQueryFactory().create("simpleIndex", "example-region", index -> SpatialHelper.findWithin(-122.8515139, 45.5099231, 0.25)); Collection<TrainStop> results = query.findValues(); System.out.println("Found stops: " + results); }
private static void query(ClientCache cache) throws LuceneQueryException { LuceneService lucene = LuceneServiceProvider.get(cache); LuceneQuery<Integer, EmployeeData> query = lucene.createLuceneQueryFactory() .create(SIMPLE_INDEX, EXAMPLE_REGION, "firstName:Chris~2", "firstname"); System.out.println("Employees with first names like Chris: " + query.findValues()); }
private static void queryNestedObject(ClientCache cache) throws LuceneQueryException { LuceneService lucene = LuceneServiceProvider.get(cache); LuceneQuery<Integer, EmployeeData> query = lucene.createLuceneQueryFactory().create( NESTEDOBJECT_INDEX, EXAMPLE_REGION, "5035330001 AND 5036430001", "contacts.phoneNumbers"); System.out.println("Employees with phone number 5035330001 and 5036430001 in their contacts: " + query.findValues()); }