Search in sources :

Example 1 with MatchPredicate

use of io.crate.expression.symbol.MatchPredicate in project crate by crate.

the class SelectStatementAnalyzerTest method testMatchOnIndex.

@Test
public void testMatchOnIndex() throws Exception {
    var executor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    QueriedSelectRelation relation = executor.analyze("select * from users where match(name_text_ft, 'Arthur Dent')");
    assertThat(relation.where(), instanceOf(MatchPredicate.class));
    MatchPredicate match = (MatchPredicate) relation.where();
    assertThat(match.identBoostMap(), hasEntry(isReference("name_text_ft"), isLiteral(null)));
    assertThat(match.queryTerm(), isLiteral("Arthur Dent"));
    assertThat(match.matchType(), is("best_fields"));
    assertThat(match.options(), isLiteral(Map.of()));
}
Also used : MatchPredicate(io.crate.expression.symbol.MatchPredicate) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 2 with MatchPredicate

use of io.crate.expression.symbol.MatchPredicate in project crate by crate.

the class SelectStatementAnalyzerTest method testWhereMatchOnColumn.

@Test
public void testWhereMatchOnColumn() throws Exception {
    var executor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    QueriedSelectRelation relation = executor.analyze("select * from users where match(name, 'Arthur Dent')");
    assertThat(relation.where(), Matchers.instanceOf(MatchPredicate.class));
    MatchPredicate matchPredicate = (MatchPredicate) relation.where();
    assertThat(matchPredicate.queryTerm(), isLiteral("Arthur Dent"));
    assertThat(matchPredicate.identBoostMap(), hasEntry(isReference("name"), isLiteral(null)));
    assertThat(matchPredicate.matchType(), is("best_fields"));
    assertThat(matchPredicate.options(), isLiteral(Map.of()));
}
Also used : MatchPredicate(io.crate.expression.symbol.MatchPredicate) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 3 with MatchPredicate

use of io.crate.expression.symbol.MatchPredicate in project crate by crate.

the class SelectStatementAnalyzerTest method testSelectWhereFullMatchPredicate.

@Test
public void testSelectWhereFullMatchPredicate() throws Exception {
    var executor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    QueriedSelectRelation relation = executor.analyze("select * from users " + "where match ((name 1.2, text), 'awesome') using best_fields with (analyzer='german')");
    Symbol query = relation.where();
    assertThat(query, instanceOf(MatchPredicate.class));
    MatchPredicate match = (MatchPredicate) query;
    assertThat(match.identBoostMap(), hasEntry(isReference("name"), isLiteral(1.2)));
    assertThat(match.identBoostMap(), hasEntry(isReference("text"), isLiteral(null)));
    assertThat(match.queryTerm(), isLiteral("awesome"));
    assertThat(match.matchType(), is("best_fields"));
    assertThat(match.options(), isLiteral(Map.of("analyzer", "german")));
}
Also used : ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) AliasSymbol(io.crate.expression.symbol.AliasSymbol) MatchPredicate(io.crate.expression.symbol.MatchPredicate) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 4 with MatchPredicate

use of io.crate.expression.symbol.MatchPredicate in project crate by crate.

the class SingleRowSubselectAnalyzerTest method testMatchPredicateWithSingleRowSubselect.

@Test
public void testMatchPredicateWithSingleRowSubselect() throws Exception {
    QueriedSelectRelation relation = e.analyze("select * from users where match(shape 1.2, (select shape from users limit 1))");
    assertThat(relation.where(), instanceOf(MatchPredicate.class));
    MatchPredicate match = (MatchPredicate) relation.where();
    assertThat(match.identBoostMap(), hasEntry(isReference("shape"), isLiteral(1.2)));
    assertThat(match.queryTerm(), instanceOf(SelectSymbol.class));
    assertThat(match.matchType(), is("intersects"));
}
Also used : SelectSymbol(io.crate.expression.symbol.SelectSymbol) MatchPredicate(io.crate.expression.symbol.MatchPredicate) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 5 with MatchPredicate

use of io.crate.expression.symbol.MatchPredicate in project crate by crate.

the class SelectStatementAnalyzerTest method testWhereMatchAllOptions.

@Test
public void testWhereMatchAllOptions() throws Exception {
    var executor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    QueriedSelectRelation relation = executor.analyze("select * from users " + "where match ((name 1.2, text), 'awesome') using best_fields with " + "(" + "  analyzer='german'," + "  boost=4.6," + "  tie_breaker=0.75," + "  operator='or'," + "  minimum_should_match=4," + "  fuzziness=12," + "  max_expansions=3," + "  prefix_length=4," + "  rewrite='constant_score_boolean'," + "  fuzzy_rewrite='top_terms_20'," + "  zero_terms_query='all'," + "  cutoff_frequency=5," + "  slop=3" + ")");
    MatchPredicate match = (MatchPredicate) relation.where();
    assertThat(match.options(), isLiteral(Map.ofEntries(Map.entry("analyzer", "german"), Map.entry("boost", 4.6), Map.entry("cutoff_frequency", 5), Map.entry("fuzziness", 12), Map.entry("fuzzy_rewrite", "top_terms_20"), Map.entry("max_expansions", 3), Map.entry("minimum_should_match", 4), Map.entry("operator", "or"), Map.entry("prefix_length", 4), Map.entry("rewrite", "constant_score_boolean"), Map.entry("slop", 3), Map.entry("tie_breaker", 0.75), Map.entry("zero_terms_query", "all"))));
}
Also used : MatchPredicate(io.crate.expression.symbol.MatchPredicate) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

MatchPredicate (io.crate.expression.symbol.MatchPredicate)6 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)6 Test (org.junit.Test)6 SelectSymbol (io.crate.expression.symbol.SelectSymbol)2 AliasSymbol (io.crate.expression.symbol.AliasSymbol)1 ParameterSymbol (io.crate.expression.symbol.ParameterSymbol)1 Symbol (io.crate.expression.symbol.Symbol)1