Search in sources :

Example 6 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class BackendGlobalStateTest method testIndexClosed.

@Test
public void testIndexClosed() throws IOException {
    StateBackend mockBackend = mock(StateBackend.class);
    PersistentGlobalState initialState = new PersistentGlobalState();
    when(mockBackend.loadOrCreateGlobalState()).thenReturn(initialState);
    MockBackendGlobalState.stateBackend = mockBackend;
    BackendGlobalState backendGlobalState = new MockBackendGlobalState(getConfig(), null);
    backendGlobalState.createIndex("test_index");
    IndexState state1 = backendGlobalState.getIndex("test_index");
    IndexState state2 = backendGlobalState.getIndex("test_index");
    assertSame(state1, state2);
    backendGlobalState.indexClosed("test_index");
    IndexState state3 = backendGlobalState.getIndex("test_index");
    assertNotSame(state1, state3);
    verify(mockBackend, times(1)).loadOrCreateGlobalState();
    ArgumentCaptor<PersistentGlobalState> stateArgumentCaptor = ArgumentCaptor.forClass(PersistentGlobalState.class);
    verify(mockBackend, times(1)).commitGlobalState(stateArgumentCaptor.capture());
    PersistentGlobalState committedState = stateArgumentCaptor.getValue();
    assertEquals(1, committedState.getIndices().size());
    assertNotNull(committedState.getIndices().get("test_index"));
    verifyNoMoreInteractions(mockBackend);
}
Also used : StateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend) RemoteStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend) LocalStateBackend(com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Test(org.junit.Test)

Example 7 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class DocCollectorTest method testQueryOverridesDefaultTimeout.

@Test
public void testQueryOverridesDefaultTimeout() {
    IndexState indexState = Mockito.mock(IndexState.class);
    when(indexState.getDefaultSearchTimeoutSec()).thenReturn(3.0);
    when(indexState.getDefaultSearchTimeoutCheckEvery()).thenReturn(0);
    SearchRequest request = SearchRequest.newBuilder().setTopHits(10).setTimeoutSec(2.0).build();
    TestDocCollector docCollector = new TestDocCollector(request, indexState);
    assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
    assertTrue(docCollector.getWrappedManager() instanceof SearchCutoffWrapper);
    SearchCutoffWrapper<?> cutoffWrapper = (SearchCutoffWrapper<?>) docCollector.getWrappedManager();
    assertEquals(2.0, cutoffWrapper.getTimeoutSec(), 0.0);
    assertEquals(0, cutoffWrapper.getCheckEvery());
}
Also used : SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) SearchCutoffWrapper(com.yelp.nrtsearch.server.luceneserver.search.SearchCutoffWrapper) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Test(org.junit.Test)

Example 8 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class DocCollectorTest method testUsesDefaultTimeoutCheckEvery.

@Test
public void testUsesDefaultTimeoutCheckEvery() {
    IndexState indexState = Mockito.mock(IndexState.class);
    when(indexState.getDefaultSearchTimeoutSec()).thenReturn(6.0);
    when(indexState.getDefaultSearchTimeoutCheckEvery()).thenReturn(10);
    SearchRequest request = SearchRequest.newBuilder().setTopHits(10).build();
    TestDocCollector docCollector = new TestDocCollector(request, indexState);
    assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
    assertTrue(docCollector.getWrappedManager() instanceof SearchCutoffWrapper);
    SearchCutoffWrapper<?> cutoffWrapper = (SearchCutoffWrapper<?>) docCollector.getWrappedManager();
    assertEquals(6.0, cutoffWrapper.getTimeoutSec(), 0.0);
    assertEquals(10, cutoffWrapper.getCheckEvery());
}
Also used : SearchRequest(com.yelp.nrtsearch.server.grpc.SearchRequest) SearchCutoffWrapper(com.yelp.nrtsearch.server.luceneserver.search.SearchCutoffWrapper) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Test(org.junit.Test)

Example 9 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class TerminateAfterWrapperTest method testOverrideDefaultTerminateAfter.

@Test
public void testOverrideDefaultTerminateAfter() throws IOException {
    IndexState indexState = getGlobalState().getIndex(DEFAULT_TEST_INDEX);
    try {
        indexState.setDefaultTerminateAfter(15);
        SearchResponse response = doQuery(5, 0.0, false);
        assertEquals(5, response.getHitsCount());
        assertTrue(response.getTerminatedEarly());
    } finally {
        indexState.setDefaultTerminateAfter(0);
    }
}
Also used : IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse) Test(org.junit.Test)

Example 10 with IndexState

use of com.yelp.nrtsearch.server.luceneserver.IndexState in project nrtsearch by Yelp.

the class FacetTopDocs method facetTopDocsSample.

/**
 * Compute facet aggregations based on a sample of the query's top ranked documents. Only
 * processes facets that have sampleTopDocs set to a value greater than zero.
 *
 * @param topDocs top documents from query
 * @param facets facet definition grpc messages
 * @param indexState state for index
 * @param searcher searcher for query
 * @param diagnostics diagnostics builder for storing facet timing
 * @return results for facets over top docs
 * @throws IOException if error reading doc values
 * @throws IllegalArgumentException if top docs facet field is not indexable or does not have doc
 *     values enabled
 */
public static Iterable<FacetResult> facetTopDocsSample(TopDocs topDocs, List<Facet> facets, IndexState indexState, IndexSearcher searcher, Diagnostics.Builder diagnostics) throws IOException {
    List<Facet> sampleFacets = facets.stream().filter(facet -> facet.getSampleTopDocs() > 0).collect(Collectors.toList());
    if (sampleFacets.isEmpty()) {
        return Collections.emptyList();
    }
    List<FacetResult> facetResults = new ArrayList<>(sampleFacets.size());
    for (Facet facet : sampleFacets) {
        long startNS = System.nanoTime();
        facetResults.add(facetFromTopDocs(topDocs, facet, indexState, searcher));
        long endNS = System.nanoTime();
        diagnostics.putFacetTimeMs(facet.getName(), (endNS - startNS) / 1000000.0);
    }
    return facetResults;
}
Also used : Diagnostics(com.yelp.nrtsearch.server.grpc.SearchResponse.Diagnostics) ReaderUtil(org.apache.lucene.index.ReaderUtil) TopDocs(org.apache.lucene.search.TopDocs) IOException(java.io.IOException) HashMap(java.util.HashMap) FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) IndexableFieldDef(com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef) Map(java.util.Map) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Collections(java.util.Collections) Facet(com.yelp.nrtsearch.server.grpc.Facet) LoadedDocValues(com.yelp.nrtsearch.server.luceneserver.doc.LoadedDocValues) FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) IndexSearcher(org.apache.lucene.search.IndexSearcher) ArrayList(java.util.ArrayList) FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult) Facet(com.yelp.nrtsearch.server.grpc.Facet)

Aggregations

IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)23 Test (org.junit.Test)13 SearchRequest (com.yelp.nrtsearch.server.grpc.SearchRequest)9 Path (java.nio.file.Path)6 HashMap (java.util.HashMap)5 SearchCutoffWrapper (com.yelp.nrtsearch.server.luceneserver.search.SearchCutoffWrapper)4 SearchHandler (com.yelp.nrtsearch.server.luceneserver.SearchHandler)3 FieldDef (com.yelp.nrtsearch.server.luceneserver.field.FieldDef)3 IndexableFieldDef (com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef)3 BufferedWriter (java.io.BufferedWriter)3 ArrayList (java.util.ArrayList)3 Facet (com.yelp.nrtsearch.server.grpc.Facet)2 SearchResponse (com.yelp.nrtsearch.server.grpc.SearchResponse)2 VirtualFieldDef (com.yelp.nrtsearch.server.luceneserver.field.VirtualFieldDef)2 TerminateAfterWrapper (com.yelp.nrtsearch.server.luceneserver.search.TerminateAfterWrapper)2 LocalStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.LocalStateBackend)2 RemoteStateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.RemoteStateBackend)2 StateBackend (com.yelp.nrtsearch.server.luceneserver.state.backend.StateBackend)2 List (java.util.List)2 Facets (org.apache.lucene.facet.Facets)2