Skip to content

Commit

Permalink
In flattened fields make only the value (not the field name) subject …
Browse files Browse the repository at this point in the history
…to case insensitive search
  • Loading branch information
markharwood committed May 6, 2021
1 parent 2cb91df commit 6d55f99
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,19 @@ public Query termQueryCaseInsensitive(Object value, SearchExecutionContext conte
@Override
public TermsEnum getTerms(boolean caseInsensitive, String string, SearchExecutionContext queryShardContext) throws IOException {
IndexReader reader = queryShardContext.searcher().getTopReaderContext().reader();
String searchString = FlattenedFieldParser.createKeyedValue(key, string);
Terms terms = MultiTerms.getTerms(reader, name());
if (terms == null) {
// Field does not exist on this shard.
return null;
}
Automaton a = caseInsensitive
? AutomatonQueries.caseInsensitivePrefix(searchString)
: Automata.makeString(searchString);
a = Operations.concatenate(a, Automata.makeAnyString());

Automaton a = Automata.makeString(key + FlattenedFieldParser.SEPARATOR);
if (caseInsensitive) {
a = Operations.concatenate(a, AutomatonQueries.caseInsensitivePrefix(string));
} else {
a = Operations.concatenate(a, Automata.makeString(string));
a = Operations.concatenate(a, Automata.makeAnyString());
}
a = MinimizationOperations.minimize(a, Integer.MAX_VALUE);

CompiledAutomaton automaton = new CompiledAutomaton(a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,39 @@ teardown:
body: {"field": "foo.bar", "string":"b"}
- length: {terms: 1}

---
"Test case insensitivity":
- do:
termsenum:
index: test_k
body: {"field": "foo", "string":"B"}
- length: {terms: 0}

- do:
termsenum:
index: test_k
body: {"field": "foo", "string":"B", "case_insensitive": true}
- length: {terms: 1}

- do:
termsenum:
index: test_f
body: {"field": "foo.bar", "string":"B"}
- length: {terms: 0}

- do:
termsenum:
index: test_f
body: {"field": "foo.bar", "string":"B", "case_insensitive": true}
- length: {terms: 1}

- do:
termsenum:
index: test_f
body: {"field": "foo.Bar", "string":"B", "case_insensitive": true}
- length: {terms: 0}


---
"Test index filtering":
- do:
Expand Down

0 comments on commit 6d55f99

Please sign in to comment.