Skip to content

Commit

Permalink
Fix ConstantScoreTextFieldTypeTests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayya-sharipova committed Sep 19, 2024
1 parent eee5308 commit 351d1a7
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RegexpQuery;
Expand Down Expand Up @@ -231,20 +232,26 @@ public void testTermIntervals() throws IOException {
public void testPrefixIntervals() throws IOException {
MappedFieldType ft = createFieldType();
IntervalsSource prefixIntervals = ft.prefixIntervals(new BytesRef("foo"), MOCK_CONTEXT);
assertEquals(Intervals.prefix(new BytesRef("foo")), prefixIntervals);
assertEquals(Intervals.prefix(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), prefixIntervals);
}

public void testWildcardIntervals() throws IOException {
MappedFieldType ft = createFieldType();
IntervalsSource wildcardIntervals = ft.wildcardIntervals(new BytesRef("foo"), MOCK_CONTEXT);
assertEquals(Intervals.wildcard(new BytesRef("foo")), wildcardIntervals);
assertEquals(Intervals.wildcard(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), wildcardIntervals);
}

public void testRegexpIntervals() {
MappedFieldType ft = createFieldType();
IntervalsSource regexpIntervals = ft.regexpIntervals(new BytesRef("foo"), MOCK_CONTEXT);
assertEquals(Intervals.regexp(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), regexpIntervals);
}

public void testFuzzyIntervals() throws IOException {
MappedFieldType ft = createFieldType();
IntervalsSource fuzzyIntervals = ft.fuzzyIntervals("foo", 1, 2, true, MOCK_CONTEXT);
FuzzyQuery fq = new FuzzyQuery(new Term("field", "foo"), 1, 2, 128, true);
IntervalsSource expectedIntervals = Intervals.multiterm(fq.getAutomata(), "foo");
IntervalsSource expectedIntervals = Intervals.multiterm(fq.getAutomata(), IndexSearcher.getMaxClauseCount(), "foo");
assertEquals(expectedIntervals, fuzzyIntervals);
}

Expand All @@ -259,6 +266,15 @@ public void testWildcardIntervalsWithIndexedPrefixes() {
ConstantScoreTextFieldType ft = createFieldType();
ft.setIndexPrefixes(1, 4);
IntervalsSource wildcardIntervals = ft.wildcardIntervals(new BytesRef("foo"), MOCK_CONTEXT);
assertEquals(Intervals.wildcard(new BytesRef("foo")), wildcardIntervals);
assertEquals(Intervals.wildcard(new BytesRef("foo"), IndexSearcher.getMaxClauseCount()), wildcardIntervals);
}

public void testRangeIntervals() {
MappedFieldType ft = createFieldType();
IntervalsSource rangeIntervals = ft.rangeIntervals(new BytesRef("foo"), new BytesRef("foo1"), true, true, MOCK_CONTEXT);
assertEquals(
Intervals.range(new BytesRef("foo"), new BytesRef("foo1"), true, true, IndexSearcher.getMaxClauseCount()),
rangeIntervals
);
}
}

0 comments on commit 351d1a7

Please sign in to comment.