Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Froh <[email protected]>
  • Loading branch information
msfroh committed May 30, 2024
1 parent 5412e3e commit f1c74d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@

import static org.opensearch.index.mapper.KeywordFieldMapper.normalizeValue;

/**
* Mapper for the "wildcard" field type, which supports (relatively) efficient matching by wildcard, prefix, and regexp
* queries. It's not really a "full-text" field type, but rather an "unstructured string" field type.
*
* @opensearch.internal
*/
public class WildcardFieldMapper extends ParametrizedFieldMapper {
private final String nullValue;
private final int ignoreAbove;
Expand Down Expand Up @@ -202,8 +208,12 @@ protected void parseCreateField(ParseContext context) throws IOException {
Tokenizer tokenizer = new WildcardFieldTokenizer();
tokenizer.setReader(new StringReader(value));
context.doc().add(new TextField(fieldType().name(), tokenizer));
if (hasDocValues) {
if (fieldType().hasDocValues()) {
context.doc().add(new SortedSetDocValuesField(fieldType().name(), binaryValue));
} else {
if (fieldType().hasDocValues() == false) {
createFieldNamesField(context);
}
}
}

Expand Down Expand Up @@ -302,6 +312,9 @@ public boolean incrementToken() throws IOException {
}
}

/**
* Implements the various query types over wildcard fields.
*/
public static final class WildcardFieldType extends StringFieldType {
private final int ignoreAbove;
private final String nullValue;
Expand Down Expand Up @@ -614,6 +627,11 @@ private static BooleanQuery matchAllTermsQuery(String fieldName, Set<String> ter
}
}

/**
* Custom two-phase query type for queries over the wildcard field. The expected behavior is that a first-phase
* query provides the best possible filter over the indexed trigrams, while the second phase matcher eliminates
* false positives by evaluating the true field value.
*/
static class WildcardMatchingQuery extends Query {
private static final long MATCH_COST_ESTIMATE = 1000L;
private final String fieldName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void writeFieldValue(XContentBuilder builder) throws IOException {
@Override
protected void registerParameters(ParameterChecker checker) throws IOException {
checker.registerConflictCheck("normalizer", b -> b.field("normalizer", "lowercase"));
checker.registerConflictCheck("doc_values", b -> b.field("doc_values", false));
checker.registerConflictCheck("doc_values", b -> b.field("doc_values", true));
checker.registerConflictCheck("null_value", b -> b.field("null_value", "foo"));
checker.registerUpdateCheck(b -> b.field("ignore_above", 256), m -> assertEquals(256, ((WildcardFieldMapper) m).ignoreAbove()));
}
Expand Down

0 comments on commit f1c74d9

Please sign in to comment.