Search in sources :

Example 1 with IntervalsSource

use of org.apache.lucene.queries.intervals.IntervalsSource in project OpenSearch by opensearch-project.

the class IntervalBuilderTests method testUnorderedNoOverlap.

public void testUnorderedNoOverlap() throws IOException {
    CannedTokenStream ts = new CannedTokenStream(new Token("term1", 1, 2), new Token("term2", 3, 4), new Token("term3", 5, 6));
    IntervalsSource source = BUILDER.analyzeText(new CachingTokenFilter(ts), -1, IntervalMode.UNORDERED_NO_OVERLAP);
    IntervalsSource expected = Intervals.unorderedNoOverlaps(Intervals.unorderedNoOverlaps(Intervals.term("term1"), Intervals.term("term2")), Intervals.term("term3"));
    assertEquals(expected, source);
}
Also used : CachingTokenFilter(org.apache.lucene.analysis.CachingTokenFilter) Token(org.apache.lucene.analysis.Token) IntervalsSource(org.apache.lucene.queries.intervals.IntervalsSource) CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream)

Example 2 with IntervalsSource

use of org.apache.lucene.queries.intervals.IntervalsSource in project OpenSearch by opensearch-project.

the class IntervalBuilderTests method testSimpleSynonyms.

public void testSimpleSynonyms() throws IOException {
    CannedTokenStream ts = new CannedTokenStream(new Token("term1", 1, 2), new Token("term2", 3, 4), new Token("term4", 0, 3, 4), new Token("term3", 5, 6));
    IntervalsSource source = BUILDER.analyzeText(new CachingTokenFilter(ts), -1, true);
    IntervalsSource expected = Intervals.ordered(Intervals.term("term1"), Intervals.or(Intervals.term("term2"), Intervals.term("term4")), Intervals.term("term3"));
    assertEquals(expected, source);
}
Also used : CachingTokenFilter(org.apache.lucene.analysis.CachingTokenFilter) Token(org.apache.lucene.analysis.Token) IntervalsSource(org.apache.lucene.queries.intervals.IntervalsSource) CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream)

Example 3 with IntervalsSource

use of org.apache.lucene.queries.intervals.IntervalsSource in project OpenSearch by opensearch-project.

the class IntervalBuilderTests method testSimpleTerm.

public void testSimpleTerm() throws IOException {
    CannedTokenStream ts = new CannedTokenStream(new Token("term1", 1, 2));
    IntervalsSource source = BUILDER.analyzeText(new CachingTokenFilter(ts), -1, true);
    IntervalsSource expected = Intervals.term("term1");
    assertEquals(expected, source);
}
Also used : CachingTokenFilter(org.apache.lucene.analysis.CachingTokenFilter) Token(org.apache.lucene.analysis.Token) IntervalsSource(org.apache.lucene.queries.intervals.IntervalsSource) CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream)

Example 4 with IntervalsSource

use of org.apache.lucene.queries.intervals.IntervalsSource in project OpenSearch by opensearch-project.

the class IntervalBuilderTests method testUnordered.

public void testUnordered() throws IOException {
    CannedTokenStream ts = new CannedTokenStream(new Token("term1", 1, 2), new Token("term2", 3, 4), new Token("term3", 5, 6));
    IntervalsSource source = BUILDER.analyzeText(new CachingTokenFilter(ts), -1, false);
    IntervalsSource expected = Intervals.unordered(Intervals.term("term1"), Intervals.term("term2"), Intervals.term("term3"));
    assertEquals(expected, source);
}
Also used : CachingTokenFilter(org.apache.lucene.analysis.CachingTokenFilter) Token(org.apache.lucene.analysis.Token) IntervalsSource(org.apache.lucene.queries.intervals.IntervalsSource) CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream)

Example 5 with IntervalsSource

use of org.apache.lucene.queries.intervals.IntervalsSource in project OpenSearch by opensearch-project.

the class IntervalBuilderTests method testEmptyTokenStream.

public void testEmptyTokenStream() throws IOException {
    CannedTokenStream ts = new CannedTokenStream();
    IntervalsSource source = BUILDER.analyzeText(new CachingTokenFilter(ts), 0, true);
    assertSame(IntervalBuilder.NO_INTERVALS, source);
}
Also used : CachingTokenFilter(org.apache.lucene.analysis.CachingTokenFilter) IntervalsSource(org.apache.lucene.queries.intervals.IntervalsSource) CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream)

Aggregations

IntervalsSource (org.apache.lucene.queries.intervals.IntervalsSource)18 CachingTokenFilter (org.apache.lucene.analysis.CachingTokenFilter)12 CannedTokenStream (org.apache.lucene.analysis.CannedTokenStream)12 Token (org.apache.lucene.analysis.Token)11 ArrayList (java.util.ArrayList)3 PositionIncrementAttribute (org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute)2 TermToBytesRefAttribute (org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute)2 BytesRef (org.apache.lucene.util.BytesRef)2 TokenStream (org.apache.lucene.analysis.TokenStream)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 Term (org.apache.lucene.index.Term)1 IntervalQuery (org.apache.lucene.queries.intervals.IntervalQuery)1 GraphTokenStreamFiniteStrings (org.apache.lucene.util.graph.GraphTokenStreamFiniteStrings)1 NamedAnalyzer (org.opensearch.index.analysis.NamedAnalyzer)1 MappedFieldType (org.opensearch.index.mapper.MappedFieldType)1 Result (org.opensearch.percolator.QueryAnalyzer.Result)1 QueryAnalyzer.selectBestResult (org.opensearch.percolator.QueryAnalyzer.selectBestResult)1