Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Dec 21, 2023
1 parent a7f6bd2 commit 58a7774
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,7 @@ public Query termQuery(Object value, QueryShardContext context) {
query = new BoostQuery(query, boost());
}
if (isSearchable() && hasDocValues()) {
return new IndexOrDocValuesQuery(
query,
SortedSetDocValuesField.newSlowExactQuery(name(), indexedValueForSearch(value))
);
return new IndexOrDocValuesQuery(query, SortedSetDocValuesField.newSlowExactQuery(name(), indexedValueForSearch(value)));
}
if (hasDocValues()) {
return SortedSetDocValuesField.newSlowExactQuery(name(), indexedValueForSearch(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

package org.opensearch.index.query;

import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.ScoreMode;
import org.opensearch.common.Nullable;
import org.opensearch.common.geo.GeoPoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ protected TokenStream normalize(String fieldName, TokenStream in) {
}
};
MappedFieldType ft = new KeywordFieldType("field", new NamedAnalyzer("my_normalizer", AnalyzerScope.INDEX, normalizer));
assertEquals(new IndexOrDocValuesQuery(new TermQuery(new Term("field", "foo bar")), SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef("foo bar"))), ft.termQuery("fOo BaR", null));
assertEquals(
new IndexOrDocValuesQuery(
new TermQuery(new Term("field", "foo bar")),
SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef("foo bar"))
),
ft.termQuery("fOo BaR", null)
);
}

public void testTermsQuery() {
Expand Down Expand Up @@ -345,9 +351,21 @@ public void testWildCardQuery() {

public void testNormalizeQueries() {
MappedFieldType ft = new KeywordFieldType("field");
assertEquals(new IndexOrDocValuesQuery(new TermQuery(new Term("field", new BytesRef("FOO"))), SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef("FOO"))), ft.termQuery("FOO", null));
assertEquals(
new IndexOrDocValuesQuery(
new TermQuery(new Term("field", new BytesRef("FOO"))),
SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef("FOO"))
),
ft.termQuery("FOO", null)
);
ft = new KeywordFieldType("field", Lucene.STANDARD_ANALYZER);
assertEquals(new IndexOrDocValuesQuery(new TermQuery(new Term("field", new BytesRef("foo"))), SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef("foo"))), ft.termQuery("FOO", null));
assertEquals(
new IndexOrDocValuesQuery(
new TermQuery(new Term("field", new BytesRef("foo"))),
SortedSetDocValuesField.newSlowExactQuery("field", new BytesRef("foo"))
),
ft.termQuery("FOO", null)
);
}

public void testFetchSourceValue() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@ public void testToQueryMultipleFieldsDisableDismax() throws Exception {
.tieBreaker(1.0f)
.toQuery(createShardContext());
Query expected = new DisjunctionMaxQuery(
List.of(new TermQuery(new Term(TEXT_FIELD_NAME, "test")), new IndexOrDocValuesQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "test")), SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("test")))),
List.of(
new TermQuery(new Term(TEXT_FIELD_NAME, "test")),
new IndexOrDocValuesQuery(
new TermQuery(new Term(KEYWORD_FIELD_NAME, "test")),
SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("test"))
)
),
1
);
assertEquals(expected, query);
Expand All @@ -253,7 +259,13 @@ public void testToQueryMultipleFieldsDisableDismax() throws Exception {
public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
Query query = multiMatchQuery("test").field(TEXT_FIELD_NAME).field(KEYWORD_FIELD_NAME).toQuery(createShardContext());
Query expected = new DisjunctionMaxQuery(
List.of(new TermQuery(new Term(TEXT_FIELD_NAME, "test")), new IndexOrDocValuesQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "test")), SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("test")))),
List.of(
new TermQuery(new Term(TEXT_FIELD_NAME, "test")),
new IndexOrDocValuesQuery(
new TermQuery(new Term(KEYWORD_FIELD_NAME, "test")),
SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("test"))
)
),
0
);
assertEquals(expected, query);
Expand All @@ -262,7 +274,13 @@ public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
public void testToQueryFieldsWildcard() throws Exception {
Query query = multiMatchQuery("test").field("mapped_str*").tieBreaker(1.0f).toQuery(createShardContext());
Query expected = new DisjunctionMaxQuery(
List.of(new TermQuery(new Term(TEXT_FIELD_NAME, "test")), new IndexOrDocValuesQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "test")), SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("test")))),
List.of(
new TermQuery(new Term(TEXT_FIELD_NAME, "test")),
new IndexOrDocValuesQuery(
new TermQuery(new Term(KEYWORD_FIELD_NAME, "test")),
SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("test"))
)
),
1
);
assertEquals(expected, query);
Expand Down Expand Up @@ -461,7 +479,13 @@ public void testDefaultField() throws Exception {
DisjunctionMaxQuery expected = new DisjunctionMaxQuery(
Arrays.asList(
new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new BoostQuery(new IndexOrDocValuesQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")), SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("hello"))), 5.0f)
new BoostQuery(
new IndexOrDocValuesQuery(
new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")),
SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("hello"))
),
5.0f
)
),
0.0f
);
Expand Down Expand Up @@ -489,7 +513,13 @@ public void testDefaultField() throws Exception {
Arrays.asList(
new MatchNoDocsQuery("failed [mapped_int] query, caused by number_format_exception:[For input string: \"hello\"]"),
new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new BoostQuery(new IndexOrDocValuesQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")), SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("hello"))), 5.0f)
new BoostQuery(
new IndexOrDocValuesQuery(
new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")),
SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("hello"))
),
5.0f
)
),
0.0f
);
Expand Down Expand Up @@ -533,8 +563,20 @@ public void testWithStopWords() throws Exception {
new BooleanQuery.Builder().add(new TermQuery(new Term(TEXT_FIELD_NAME, "quick")), BooleanClause.Occur.SHOULD)
.add(new TermQuery(new Term(TEXT_FIELD_NAME, "fox")), BooleanClause.Occur.SHOULD)
.build(),
new BooleanQuery.Builder().add(new IndexOrDocValuesQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "quick")), SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("quick"))), BooleanClause.Occur.SHOULD)
.add(new IndexOrDocValuesQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "fox")), SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("fox"))), BooleanClause.Occur.SHOULD)
new BooleanQuery.Builder().add(
new IndexOrDocValuesQuery(
new TermQuery(new Term(KEYWORD_FIELD_NAME, "quick")),
SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("quick"))
),
BooleanClause.Occur.SHOULD
)
.add(
new IndexOrDocValuesQuery(
new TermQuery(new Term(KEYWORD_FIELD_NAME, "fox")),
SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("fox"))
),
BooleanClause.Occur.SHOULD
)
.build()
),
0f
Expand Down Expand Up @@ -590,7 +632,13 @@ private void assertQueryWithAllFieldsWildcard(Query query) {
assertEquals(9, noMatchNoDocsQueries);
assertThat(
disjunctionMaxQuery.getDisjuncts(),
hasItems(new TermQuery(new Term(TEXT_FIELD_NAME, "hello")), new IndexOrDocValuesQuery(new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")), SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("hello"))))
hasItems(
new TermQuery(new Term(TEXT_FIELD_NAME, "hello")),
new IndexOrDocValuesQuery(
new TermQuery(new Term(KEYWORD_FIELD_NAME, "hello")),
SortedSetDocValuesField.newSlowExactQuery(KEYWORD_FIELD_NAME, new BytesRef("hello"))
)
)
);
}

Expand Down
Loading

0 comments on commit 58a7774

Please sign in to comment.