Search in sources :

Example 16 with IndexState

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

the class BackendGlobalState method createIndex.

@Override
public synchronized IndexState createIndex(String name) throws IOException {
    Path rootDir = getIndexDir(name);
    if (immutableState.persistentGlobalState.getIndices().containsKey(name)) {
        throw new IllegalArgumentException("index \"" + name + "\" already exists");
    }
    if (Files.exists(rootDir)) {
        throw new IllegalArgumentException("rootDir \"" + rootDir + "\" already exists");
    }
    IndexState state = new IndexState(this, name, rootDir, true, false);
    Map<String, IndexInfo> updatedIndexInfoMap = new HashMap<>(immutableState.persistentGlobalState.getIndices());
    updatedIndexInfoMap.put(name, new IndexInfo());
    PersistentGlobalState updatedState = immutableState.persistentGlobalState.asBuilder().withIndices(updatedIndexInfoMap).build();
    stateBackend.commitGlobalState(updatedState);
    Map<String, IndexState> updatedIndexStateMap = new HashMap<>(immutableState.indexStateMap);
    updatedIndexStateMap.put(name, state);
    immutableState = new ImmutableState(updatedState, updatedIndexStateMap);
    return state;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) IndexInfo(com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState.IndexInfo) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState)

Example 17 with IndexState

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

the class LegacyGlobalState method createIndex.

/**
 * Create a new index.
 */
@Override
public IndexState createIndex(String name) throws IOException {
    synchronized (indices) {
        Path rootDir = getIndexDir(name);
        if (indexNames.get(name) != null) {
            throw new IllegalArgumentException("index \"" + name + "\" already exists");
        }
        if (rootDir == null) {
            indexNames.addProperty(name, NULL);
        } else {
            if (Files.exists(rootDir)) {
                throw new IllegalArgumentException("rootDir \"" + rootDir + "\" already exists");
            }
            indexNames.addProperty(name, name);
        }
        saveIndexNames();
        IndexState state = new IndexState(this, name, rootDir, true, false);
        indices.put(name, state);
        return state;
    }
}
Also used : Path(java.nio.file.Path) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState)

Example 18 with IndexState

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

the class TerminateAfterWrapperTest method testDefaultTerminateAfter.

@Test
public void testDefaultTerminateAfter() throws IOException {
    IndexState indexState = getGlobalState().getIndex(DEFAULT_TEST_INDEX);
    try {
        indexState.setDefaultTerminateAfter(15);
        SearchResponse response = doQuery(0, 0.0, false);
        assertEquals(15, 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 19 with IndexState

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

the class DocCollectorTest method testUsesDefaultTimeout.

@Test
public void testUsesDefaultTimeout() {
    IndexState indexState = Mockito.mock(IndexState.class);
    when(indexState.getDefaultSearchTimeoutSec()).thenReturn(3.0);
    when(indexState.getDefaultSearchTimeoutCheckEvery()).thenReturn(0);
    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(3.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 20 with IndexState

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

the class DocCollectorTest method testQueryOverridesDefaultTimeoutCheckEvery.

@Test
public void testQueryOverridesDefaultTimeoutCheckEvery() {
    IndexState indexState = Mockito.mock(IndexState.class);
    when(indexState.getDefaultSearchTimeoutSec()).thenReturn(0.0);
    when(indexState.getDefaultSearchTimeoutCheckEvery()).thenReturn(20);
    SearchRequest request = SearchRequest.newBuilder().setTopHits(10).setTimeoutSec(7.0).setTimeoutCheckEvery(30).build();
    TestDocCollector docCollector = new TestDocCollector(request, indexState);
    assertTrue(docCollector.getManager() instanceof TestDocCollector.TestCollectorManager);
    assertTrue(docCollector.getWrappedManager() instanceof SearchCutoffWrapper);
    SearchCutoffWrapper<?> cutoffWrapper = (SearchCutoffWrapper<?>) docCollector.getWrappedManager();
    assertEquals(7.0, cutoffWrapper.getTimeoutSec(), 0.0);
    assertEquals(30, 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)

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