Search in sources :

Example 1 with SearchAsYouTypeAnalyzer

use of org.opensearch.index.mapper.SearchAsYouTypeFieldMapper.SearchAsYouTypeAnalyzer in project OpenSearch by opensearch-project.

the class SearchAsYouTypeFieldMapperTests method assertShingleFieldType.

private static void assertShingleFieldType(ShingleFieldType fieldType, int shingleSize, String analyzerName, PrefixFieldType prefixFieldType) {
    assertThat(fieldType.shingleSize, equalTo(shingleSize));
    for (NamedAnalyzer analyzer : asList(fieldType.indexAnalyzer(), fieldType.getTextSearchInfo().getSearchAnalyzer())) {
        assertThat(analyzer.name(), equalTo(analyzerName));
        if (shingleSize > 1) {
            final SearchAsYouTypeAnalyzer wrappedAnalyzer = (SearchAsYouTypeAnalyzer) analyzer.analyzer();
            assertThat(wrappedAnalyzer.shingleSize(), equalTo(shingleSize));
            assertThat(wrappedAnalyzer.indexPrefixes(), equalTo(false));
        }
    }
    assertThat(fieldType.prefixFieldType, equalTo(prefixFieldType));
}
Also used : NamedAnalyzer(org.opensearch.index.analysis.NamedAnalyzer) SearchAsYouTypeAnalyzer(org.opensearch.index.mapper.SearchAsYouTypeFieldMapper.SearchAsYouTypeAnalyzer)

Example 2 with SearchAsYouTypeAnalyzer

use of org.opensearch.index.mapper.SearchAsYouTypeFieldMapper.SearchAsYouTypeAnalyzer in project OpenSearch by opensearch-project.

the class SearchAsYouTypeAnalyzerTests method testCase.

private void testCase(String text, Function<Integer, SearchAsYouTypeAnalyzer> analyzerFunction, Function<Integer, List<String>> expectedTokensFunction) throws IOException {
    for (int shingleSize = 2; shingleSize <= 4; shingleSize++) {
        final SearchAsYouTypeAnalyzer analyzer = analyzerFunction.apply(shingleSize);
        final List<String> expectedTokens = expectedTokensFunction.apply(shingleSize);
        final List<String> actualTokens = analyze(analyzer, text);
        assertThat("analyzed correctly with " + analyzer, actualTokens, equalTo(expectedTokens));
    }
}
Also used : SearchAsYouTypeAnalyzer(org.opensearch.index.mapper.SearchAsYouTypeFieldMapper.SearchAsYouTypeAnalyzer)

Example 3 with SearchAsYouTypeAnalyzer

use of org.opensearch.index.mapper.SearchAsYouTypeFieldMapper.SearchAsYouTypeAnalyzer in project OpenSearch by opensearch-project.

the class SearchAsYouTypeFieldMapperTests method assertPrefixFieldType.

private static void assertPrefixFieldType(PrefixFieldType fieldType, int shingleSize, String analyzerName) {
    for (NamedAnalyzer analyzer : asList(fieldType.indexAnalyzer(), fieldType.getTextSearchInfo().getSearchAnalyzer())) {
        assertThat(analyzer.name(), equalTo(analyzerName));
    }
    final SearchAsYouTypeAnalyzer wrappedIndexAnalyzer = (SearchAsYouTypeAnalyzer) fieldType.indexAnalyzer().analyzer();
    final SearchAsYouTypeAnalyzer wrappedSearchAnalyzer = (SearchAsYouTypeAnalyzer) fieldType.getTextSearchInfo().getSearchAnalyzer().analyzer();
    for (SearchAsYouTypeAnalyzer analyzer : asList(wrappedIndexAnalyzer, wrappedSearchAnalyzer)) {
        assertThat(analyzer.shingleSize(), equalTo(shingleSize));
    }
    assertThat(wrappedIndexAnalyzer.indexPrefixes(), equalTo(true));
    assertThat(wrappedSearchAnalyzer.indexPrefixes(), equalTo(false));
}
Also used : NamedAnalyzer(org.opensearch.index.analysis.NamedAnalyzer) SearchAsYouTypeAnalyzer(org.opensearch.index.mapper.SearchAsYouTypeFieldMapper.SearchAsYouTypeAnalyzer)

Aggregations

SearchAsYouTypeAnalyzer (org.opensearch.index.mapper.SearchAsYouTypeFieldMapper.SearchAsYouTypeAnalyzer)3 NamedAnalyzer (org.opensearch.index.analysis.NamedAnalyzer)2