Example usage for org.springframework.data.solr.core.query Criteria connect

List of usage examples for org.springframework.data.solr.core.query Criteria connect

Introduction

In this page you can find the example usage for org.springframework.data.solr.core.query Criteria connect.

Prototype

public Criteria connect() 

Source Link

Document

Explicitly connect Criteria with another one allows to create explicit bracketing.

Usage

From source file:org.springframework.data.solr.core.DefaultQueryParserTests.java

/**
 * @see DATASOLR-196/*from   w w w.  j a  va  2s  .c o m*/
 */
@Test
public void connectShouldAllowConcatinationOfCriteriaWithAndPreservingDesiredBracketing() {

    Criteria part1 = Criteria.where("z").is("roo");
    Criteria part2 = Criteria.where("x").is("foo").or("y").is("bar");
    Criteria criteria = part1.connect().and(part2);

    Assert.assertEquals("z:roo AND (x:foo OR y:bar)", queryParser.createQueryStringFromNode(criteria));
}

From source file:org.springframework.data.solr.core.DefaultQueryParserTests.java

/**
 * @see DATASOLR-196/*from  w  w w .java2s  . c  o  m*/
 */
@Test
public void connectShouldAllowConcatinationOfCriteriaWithAndPreservingDesiredBracketingReverse() {

    Criteria part1 = Criteria.where("z").is("roo");
    Criteria part2 = Criteria.where("x").is("foo").or("y").is("bar");
    Criteria criteria = part2.connect().and(part1);

    Assert.assertEquals("(x:foo OR y:bar) AND z:roo", queryParser.createQueryStringFromNode(criteria));
}

From source file:org.springframework.data.solr.core.DefaultQueryParserTests.java

/**
 * @see DATASOLR-196/*from www  . j av a  2s  .  c om*/
 */
@Test
public void connectShouldAllowConcatinationOfCriteriaWithOrPreservingDesiredBracketing() {

    Criteria part1 = Criteria.where("z").is("roo");
    Criteria part2 = Criteria.where("x").is("foo").or("y").is("bar");
    Criteria criteria = part1.connect().or(part2);

    Assert.assertEquals("z:roo OR (x:foo OR y:bar)", queryParser.createQueryStringFromNode(criteria));
}

From source file:org.springframework.data.solr.core.DefaultQueryParserTests.java

/**
 * @see DATASOLR-196/*from ww  w  .ja v  a  2 s .  co m*/
 */
@Test
public void connectShouldAllowConcatinationOfCriteriaWithOrPreservingDesiredBracketingReverse() {

    Criteria part1 = Criteria.where("z").is("roo");
    Criteria part2 = Criteria.where("x").is("foo").or("y").is("bar");
    Criteria criteria = part2.connect().or(part1);

    Assert.assertEquals("(x:foo OR y:bar) OR z:roo", queryParser.createQueryStringFromNode(criteria));
}

From source file:org.springframework.data.solr.core.DefaultQueryParserTests.java

/**
 * @see DATASOLR-196/*from  w ww .  ja  v  a2  s .  c o m*/
 */
@Test
public void notOperatorShouldWrapWholeExpression() {

    Criteria part1 = Criteria.where("text").startsWith("fx").or("product_code").startsWith("fx");
    Criteria part2 = Criteria.where("text").startsWith("option").or("product_code").startsWith("option");
    Criteria criteria = part1.connect().and(part2).notOperator();

    String expected = "-((text:fx* OR product_code:fx*) AND (text:option* OR product_code:option*))";
    Assert.assertEquals(expected, queryParser.createQueryStringFromNode(criteria));
}

From source file:org.springframework.data.solr.core.DefaultQueryParserTests.java

/**
 * @see DATASOLR-196//from  w ww  .j  av  a 2 s . c om
 */
@Test
public void notOperatorShouldWrapNestedExpressionCorrectly() {

    Criteria part1 = Criteria.where("z").is("roo");
    Criteria part2 = Criteria.where("x").is("foo").or("y").is("bar").notOperator();

    Criteria criteria = part1.connect().or(part2);

    Assert.assertEquals("z:roo OR -(x:foo OR y:bar)", queryParser.createQueryStringFromNode(criteria));
}

From source file:org.springframework.data.solr.core.DefaultQueryParserTests.java

/**
 * @see DATASOLR-196//from w w w.  j  av a  2s. c o  m
 */
@Test
public void notOperatorShouldWrapNestedExpressionCorrectlyReverse() {

    Criteria part1 = Criteria.where("z").is("roo");
    Criteria part2 = Criteria.where("x").is("foo").or("y").is("bar").notOperator();

    Criteria criteria = part2.connect().or(part1);

    Assert.assertEquals("-(x:foo OR y:bar) OR z:roo", queryParser.createQueryStringFromNode(criteria));
}

From source file:org.springframework.data.solr.core.DefaultQueryParserTests.java

/**
 * @see DATASOLR-196//w  w  w  .j  a  v a  2 s . c o  m
 */
@Test
public void notOperatorShouldWrapNestedExpressionCorrectlyReverseWithDoubleNegation() {

    Criteria part1 = Criteria.where("z").is("roo");
    Criteria part2 = Criteria.where("x").is("foo").or("y").is("bar").notOperator();

    Criteria criteria = part2.connect().and(part1).notOperator();

    Assert.assertEquals("-(-(x:foo OR y:bar) AND z:roo)", queryParser.createQueryStringFromNode(criteria));
}