Search in sources :

Example 1 with FragmentSearchQuerySpec

use of io.druid.query.search.search.FragmentSearchQuerySpec in project druid by druid-io.

the class SearchQuerySpecDimExtractionFnTest method testCaseSensitiveExtraction2.

@Test
public void testCaseSensitiveExtraction2() {
    SearchQuerySpec spec = new FragmentSearchQuerySpec(Arrays.asList("To", "yo"), true);
    ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
    List<String> expected = ImmutableList.of("Tokyo", "Toyokawa");
    List<String> extracted = Lists.newArrayList();
    for (String str : testStrings) {
        String res = extractionFn.apply(str);
        if (res != null) {
            extracted.add(res);
        }
    }
    Assert.assertEquals(expected, extracted);
}
Also used : FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchQuerySpec(io.druid.query.search.search.SearchQuerySpec) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) Test(org.junit.Test)

Example 2 with FragmentSearchQuerySpec

use of io.druid.query.search.search.FragmentSearchQuerySpec in project druid by druid-io.

the class SearchQueryQueryToolChestTest method testCacheStrategy.

@Test
public void testCacheStrategy() throws Exception {
    CacheStrategy<Result<SearchResultValue>, Object, SearchQuery> strategy = new SearchQueryQueryToolChest(null, null).getCacheStrategy(new SearchQuery(new TableDataSource("dummy"), null, Granularities.ALL, 1, new MultipleIntervalSegmentSpec(ImmutableList.of(new Interval("2015-01-01/2015-01-02"))), ImmutableList.of(Druids.DIMENSION_IDENTITY.apply("dim1")), new FragmentSearchQuerySpec(ImmutableList.of("a", "b")), null, null));
    final Result<SearchResultValue> result = new Result<>(new DateTime(123L), new SearchResultValue(ImmutableList.of(new SearchHit("dim1", "a"))));
    Object preparedValue = strategy.prepareForCache().apply(result);
    ObjectMapper objectMapper = new DefaultObjectMapper();
    Object fromCacheValue = objectMapper.readValue(objectMapper.writeValueAsBytes(preparedValue), strategy.getCacheObjectClazz());
    Result<SearchResultValue> fromCacheResult = strategy.pullFromCache().apply(fromCacheValue);
    Assert.assertEquals(result, fromCacheResult);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchHit(io.druid.query.search.search.SearchHit) MultipleIntervalSegmentSpec(io.druid.query.spec.MultipleIntervalSegmentSpec) DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) TableDataSource(io.druid.query.TableDataSource) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 3 with FragmentSearchQuerySpec

use of io.druid.query.search.search.FragmentSearchQuerySpec in project druid by druid-io.

the class SearchQueryRunnerTest method testFragmentSearch.

@Test
public void testFragmentSearch() {
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query(new FragmentSearchQuerySpec(Arrays.asList("auto", "ve"))).build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.qualityDimension, "automotive", 93));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchHit(io.druid.query.search.search.SearchHit) Test(org.junit.Test)

Example 4 with FragmentSearchQuerySpec

use of io.druid.query.search.search.FragmentSearchQuerySpec in project druid by druid-io.

the class SearchQuerySpecDimExtractionFnTest method testCaseSensitiveExtraction.

@Test
public void testCaseSensitiveExtraction() {
    SearchQuerySpec spec = new FragmentSearchQuerySpec(Arrays.asList("to", "yo"), true);
    ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
    List<String> expected = ImmutableList.of("Kyoto");
    List<String> extracted = Lists.newArrayList();
    for (String str : testStrings) {
        String res = extractionFn.apply(str);
        if (res != null) {
            extracted.add(res);
        }
    }
    Assert.assertEquals(expected, extracted);
}
Also used : FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchQuerySpec(io.druid.query.search.search.SearchQuerySpec) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) Test(org.junit.Test)

Example 5 with FragmentSearchQuerySpec

use of io.druid.query.search.search.FragmentSearchQuerySpec in project druid by druid-io.

the class SearchQuerySpecDimExtractionFnTest method testExtraction.

@Test
public void testExtraction() {
    SearchQuerySpec spec = new FragmentSearchQuerySpec(Arrays.asList("tO", "yO"));
    ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
    List<String> expected = ImmutableList.of("Kyoto", "Tokyo", "Toyokawa", "Yorktown");
    List<String> extracted = Lists.newArrayList();
    for (String str : testStrings) {
        String res = extractionFn.apply(str);
        if (res != null) {
            extracted.add(res);
        }
    }
    Assert.assertEquals(expected, extracted);
}
Also used : FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) SearchQuerySpec(io.druid.query.search.search.SearchQuerySpec) FragmentSearchQuerySpec(io.druid.query.search.search.FragmentSearchQuerySpec) Test(org.junit.Test)

Aggregations

FragmentSearchQuerySpec (io.druid.query.search.search.FragmentSearchQuerySpec)6 Test (org.junit.Test)6 SearchQuerySpec (io.druid.query.search.search.SearchQuerySpec)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)2 SearchHit (io.druid.query.search.search.SearchHit)2 SearchQuery (io.druid.query.search.search.SearchQuery)2 Result (io.druid.query.Result)1 TableDataSource (io.druid.query.TableDataSource)1 MultipleIntervalSegmentSpec (io.druid.query.spec.MultipleIntervalSegmentSpec)1 DateTime (org.joda.time.DateTime)1 Interval (org.joda.time.Interval)1