Search in sources :

Example 11 with BatchSearch

use of org.icij.datashare.batch.BatchSearch in project datashare by ICIJ.

the class BatchSearchResourceTest method testTripleQuote.

private void testTripleQuote(Boolean phraseMatch, String query, String tripleQuoteResult) {
    when(batchSearchRepository.save(any())).thenReturn(true);
    Response response = postRaw("/api/batch/search/prj", "multipart/form-data;boundary=AaB03x", new MultipartContentBuilder("AaB03x").addField("name", "my batch search").addFile(new FileUpload("csvFile").withFilename("search.csv").withContentType("text/csv").withContent(query + "\"query two\"\r\n" + "query three\r\n" + "query\" four\r\n")).addField("phrase_matches", String.valueOf(phraseMatch)).build()).response();
    assertThat(response.code()).isEqualTo(200);
    ArgumentCaptor<BatchSearch> argument = ArgumentCaptor.forClass(BatchSearch.class);
    verify(batchSearchRepository).save(argument.capture());
    assertThat(argument.getValue().queries.keySet()).containsOnly(tripleQuoteResult, "\"query two\"", "query three", "query\" four");
}
Also used : Response(net.codestory.rest.Response) BatchSearch(org.icij.datashare.batch.BatchSearch)

Example 12 with BatchSearch

use of org.icij.datashare.batch.BatchSearch in project datashare by ICIJ.

the class BatchSearchResourceTest method test_get_queries_json.

@Test
public void test_get_queries_json() {
    when(batchSearchRepository.get(User.local(), "batchSearchId")).thenReturn(new BatchSearch(project("prj"), "name", "desc", asSet("q1", "q2"), User.local()));
    get("/api/batch/search/batchSearchId/queries").should().respond(200).haveType("application/json;charset=UTF-8").contain("[\"q1\",\"q2\"]");
}
Also used : BatchSearch(org.icij.datashare.batch.BatchSearch) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 13 with BatchSearch

use of org.icij.datashare.batch.BatchSearch in project datashare by ICIJ.

the class BatchSearchResourceTest method test_upload_batch_search_csv_with_name_and_csvfile_should_send_OK.

@Test
public void test_upload_batch_search_csv_with_name_and_csvfile_should_send_OK() throws InterruptedException {
    when(batchSearchRepository.save(any())).thenReturn(true);
    Response response = postRaw("/api/batch/search/prj", "multipart/form-data;boundary=AaB03x", new MultipartContentBuilder("AaB03x").addField("name", "nameValue").addFile(new FileUpload("csvFile").withContent("query\r\néèàç\r\n")).build()).response();
    assertThat(response.code()).isEqualTo(200);
    BatchSearch expected = new BatchSearch(response.content(), project("prj"), "nameValue", null, asSet("query", "éèàç"), new Date(), BatchSearch.State.QUEUED, User.local());
    verify(batchSearchRepository).save(eq(expected));
    assertThat(batchSearchQueue.take()).isEqualTo(expected.uuid);
}
Also used : Response(net.codestory.rest.Response) BatchSearch(org.icij.datashare.batch.BatchSearch) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 14 with BatchSearch

use of org.icij.datashare.batch.BatchSearch in project datashare by ICIJ.

the class BatchSearchRunnerIntTest method test_search_with_paths_ko.

@Test
public void test_search_with_paths_ko() throws Exception {
    Document mydoc = createDoc("mydoc").build();
    indexer.add(TEST_INDEX, mydoc);
    BatchSearch searchKo = new BatchSearch(project(TEST_INDEX), "name", "desc", asSet("mydoc"), User.local(), false, null, singletonList("/foo/bar"), 0);
    new BatchSearchRunner(indexer, new PropertiesProvider(), searchKo, resultConsumer).call();
    verify(resultConsumer, never()).apply(eq(searchKo.uuid), eq("mydoc"), anyList());
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchSearch(org.icij.datashare.batch.BatchSearch) Document(org.icij.datashare.text.Document)

Example 15 with BatchSearch

use of org.icij.datashare.batch.BatchSearch in project datashare by ICIJ.

the class BatchSearchRunnerIntTest method test_search_with_phraseMatches_with_ner.

@Test
public void test_search_with_phraseMatches_with_ner() throws Exception {
    Document mydoc = createDoc("docId").with("anne's doc to find").build();
    indexer.add(TEST_INDEX, mydoc);
    indexer.add(TEST_INDEX, NamedEntity.create(NamedEntity.Category.PERSON, "anne", asList(12L), mydoc.getId(), mydoc.getRootDocument(), Pipeline.Type.CORENLP, Language.FRENCH));
    BatchSearch searchKo = new BatchSearch(project(TEST_INDEX), "name", "desc", asSet("anne doc"), User.local(), false, null, null, true);
    BatchSearch searchOk = new BatchSearch(project(TEST_INDEX), "name", "desc", asSet("anne's doc"), User.local(), false, null, null, true);
    new BatchSearchRunner(indexer, new PropertiesProvider(), searchKo, resultConsumer).call();
    new BatchSearchRunner(indexer, new PropertiesProvider(), searchOk, resultConsumer).call();
    verify(resultConsumer, never()).apply(eq(searchKo.uuid), eq("anne doc"), anyList());
    verify(resultConsumer).apply(searchOk.uuid, "anne's doc", singletonList(mydoc));
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchSearch(org.icij.datashare.batch.BatchSearch) Document(org.icij.datashare.text.Document)

Aggregations

BatchSearch (org.icij.datashare.batch.BatchSearch)32 PropertiesProvider (org.icij.datashare.PropertiesProvider)18 Test (org.junit.Test)17 Document (org.icij.datashare.text.Document)15 AbstractProdWebServerTest (org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)9 Date (java.util.Date)6 Response (net.codestory.rest.Response)4 BatchSearchRepository (org.icij.datashare.batch.BatchSearchRepository)4 SearchException (org.icij.datashare.batch.SearchException)4 JooqBatchSearchRepository (org.icij.datashare.db.JooqBatchSearchRepository)4 User (org.icij.datashare.user.User)4 CollectionUtils.asSet (org.icij.datashare.CollectionUtils.asSet)3 SearchResult (org.icij.datashare.batch.SearchResult)3 Project.project (org.icij.datashare.text.Project.project)3 HashMap (java.util.HashMap)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 NotFoundException (net.codestory.http.errors.NotFoundException)2