Skip to content

Commit

Permalink
Properly set Index and Search Analyzer names in FieldBuilder (#35222)
Browse files Browse the repository at this point in the history
  • Loading branch information
alzimmermsft authored Jun 5, 2023
1 parent eb5d469 commit 786f264
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ private static SearchField enrichWithAnnotation(SearchField searchField, Member
if (hasAnalyzerName) {
searchField.setAnalyzerName(LexicalAnalyzerName.fromString(analyzerName));
} else if (hasSearchAnalyzerName || hasIndexAnalyzerName) {
searchField.setAnalyzerName(LexicalAnalyzerName.fromString(searchAnalyzerName));
searchField.setAnalyzerName(LexicalAnalyzerName.fromString(indexAnalyzerName));
searchField.setSearchAnalyzerName(LexicalAnalyzerName.fromString(searchAnalyzerName));
searchField.setIndexAnalyzerName(LexicalAnalyzerName.fromString(indexAnalyzerName));
}

if (hasNormalizerName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -295,6 +296,42 @@ public static final class MissingFunctionalityNormalizer {
public String rightTypeWrongFunctionality;
}

@Test
public void onlyAnalyzerNameSetsOnlyAnalyzerName() {
List<SearchField> fields = SearchIndexClient.buildSearchFields(OnlyAnalyzerName.class, null);

assertEquals(1, fields.size());

SearchField field = fields.get(0);
assertEquals("onlyAnalyzer", field.getAnalyzerName().toString());
assertNull(field.getIndexAnalyzerName());
assertNull(field.getSearchAnalyzerName());
}

@SuppressWarnings("unused")
public static final class OnlyAnalyzerName {
@SearchableField(analyzerName = "onlyAnalyzer")
public String onlyAnalyzer;
}

@Test
public void indexAndSearchAnalyzersSetCorrectly() {
List<SearchField> fields = SearchIndexClient.buildSearchFields(IndexAndSearchAnalyzerNames.class, null);

assertEquals(1, fields.size());

SearchField field = fields.get(0);
assertNull(field.getAnalyzerName());
assertEquals("indexAnalyzer", field.getIndexAnalyzerName().toString());
assertEquals("searchAnalyzer", field.getSearchAnalyzerName().toString());
}

@SuppressWarnings("unused")
public static final class IndexAndSearchAnalyzerNames {
@SearchableField(indexAnalyzerName = "indexAnalyzer", searchAnalyzerName = "searchAnalyzer")
public String indexAndSearchAnalyzer;
}

private void assertListFieldEquals(List<SearchField> expected, List<SearchField> actual) {
assertEquals(expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
Expand Down

0 comments on commit 786f264

Please sign in to comment.