Package org.hibernate.search.query.dsl

Examples of org.hibernate.search.query.dsl.QueryBuilder


    transaction.commit();
  }

  @Test(expected = SearchException.class)
  public void testIllegalBooleanJunction() {
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .buildQueryBuilder().forEntity( Month.class ).get();
    //forgetting to set any condition on the boolean, an exception shall be thrown:
    BooleanJunction<BooleanJunction> booleanJunction = monthQb.bool();
    assertTrue( booleanJunction.isEmpty() );
    Query query = booleanJunction.createQuery();
    Assert.fail( "should not reach this point" );
  }
View Full Code Here


  }

  @Test
  public void testRangeQueryFromTo() throws Exception {
    Transaction transaction = fullTextSession.beginTransaction();
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .buildQueryBuilder().forEntity( Month.class ).get();

    calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
    calendar.set( 1900, 2, 12, 0, 0, 0 );
    Date from = calendar.getTime();
    calendar.set( 1910, 2, 12, 0, 0, 0 );
    Date to = calendar.getTime();

    Query query = monthQb
        .range()
          .onField( "estimatedCreation" )
          .andField( "justfortest" )
            .ignoreFieldBridge().ignoreAnalyzer()
          .from( from )
          .to( to ).excludeLimit()
          .createQuery();

    assertEquals( 1, fullTextSession.createFullTextQuery( query, Month.class ).getResultSize() );

    query = monthQb
        .range()
          .onField( "estimatedCreation" )
            .ignoreFieldBridge()
          .andField( "justfortest" )
            .ignoreFieldBridge().ignoreAnalyzer()
View Full Code Here

  }

  @Test
  public void testRangeQueryBelow() throws Exception {
    Transaction transaction = fullTextSession.beginTransaction();
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .buildQueryBuilder().forEntity( Month.class ).get();

    calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
    calendar.set( 10 + 1800, 2, 12, 0, 0, 0 );
    Date to = calendar.getTime();

    Query query = monthQb
        .range()
          .onField( "estimatedCreation" )
          .andField( "justfortest" )
            .ignoreFieldBridge().ignoreAnalyzer()
          .below( to )
          .createQuery();

    FullTextQuery hibQuery = fullTextSession.createFullTextQuery( query, Month.class );
    assertEquals( 1, hibQuery.getResultSize() );
    assertEquals( "March", ( (Month) hibQuery.list().get( 0 ) ).getName() );

    query = monthQb
        .range()
          .onField( "estimatedCreation" )
            .ignoreFieldBridge()
          .andField( "justfortest" )
            .ignoreFieldBridge().ignoreAnalyzer()
          .below( DateTools.dateToString( to, DateTools.Resolution.MINUTE ) )
          .createQuery();

    hibQuery = fullTextSession.createFullTextQuery( query, Month.class );
    assertEquals( 1, hibQuery.getResultSize() );
    assertEquals( "March", ( (Month) hibQuery.list().get( 0 ) ).getName() );

    query = monthQb.range()
        .onField( "raindropInMm" )
        .below( 0.24d )
        .createQuery();

    assertTrue( query.getClass().isAssignableFrom( NumericRangeQuery.class ) );
View Full Code Here

  }

  @Test
  public void testRangeQueryAbove() throws Exception {
    Transaction transaction = fullTextSession.beginTransaction();
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .buildQueryBuilder().forEntity( Month.class ).get();

    calendar.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
    calendar.set( 10 + 1900, 2, 12, 0, 0, 0 );
    Date to = calendar.getTime();

    Query query = monthQb
        .range()
          .onField( "estimatedCreation" )
          .andField( "justfortest" )
            .ignoreFieldBridge().ignoreAnalyzer()
          .above( to )
          .createQuery();
    FullTextQuery hibQuery = fullTextSession.createFullTextQuery( query, Month.class );
    assertEquals( 1, hibQuery.getResultSize() );
    assertEquals( "February", ( (Month) hibQuery.list().get( 0 ) ).getName() );

    query = monthQb
        .range()
          .onField( "estimatedCreation" )
            .ignoreFieldBridge()
          .andField( "justfortest" )
            .ignoreFieldBridge().ignoreAnalyzer()
          .above( DateTools.dateToString( to, DateTools.Resolution.MINUTE ) )
          .createQuery();
    hibQuery = fullTextSession.createFullTextQuery( query, Month.class );
    assertEquals( 1, hibQuery.getResultSize() );
    assertEquals( "February", ( (Month) hibQuery.list().get( 0 ) ).getName() );

    // test the limits, inclusive
    query = monthQb
        .range()
          .onField( "estimatedCreation" )
          .andField( "justfortest" )
            .ignoreFieldBridge().ignoreAnalyzer()
          .above( february )
          .createQuery();
    hibQuery = fullTextSession.createFullTextQuery( query, Month.class );
    assertEquals( 1, hibQuery.getResultSize() );
    assertEquals( "February", ( (Month) hibQuery.list().get( 0 ) ).getName() );

    // test the limits, exclusive
    query = monthQb
        .range()
          .onField( "estimatedCreation" )
          .andField( "justfortest" )
            .ignoreFieldBridge().ignoreAnalyzer()
          .above( february ).excludeLimit()
View Full Code Here

  }

  @Test
  public void testNullIndexingWithDSLQueryIgnoringFieldBridge() throws Exception {
    try {
      QueryBuilder queryBuilder = getSearchFactory().buildQueryBuilder().forEntity( Value.class ).get();
      queryBuilder.keyword().onField( "value" ).ignoreFieldBridge().matching( null ).createQuery();
      fail();
    }
    catch (SearchException e) {
      // success
    }
View Full Code Here

    parser.setAllowLeadingWildcard( true );
    return parser.parse( "*" );
  }

  private Query createDSLQuery() {
    QueryBuilder queryBuilder = getSearchFactory().buildQueryBuilder().forEntity( Value.class ).get();
    return queryBuilder.keyword().onField( "value" ).matching( null ).createQuery();
  }
View Full Code Here

  }

  @Test
  public void testPhraseQuery() throws Exception {
    Transaction transaction = fullTextSession.beginTransaction();
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .buildQueryBuilder().forEntity( Month.class ).get();

    Query query = monthQb
        .phrase()
          .onField( "mythology" )
          .sentence( "colder and whitening" )
          .createQuery();

    assertEquals(
        "test exact phrase", 1, fullTextSession.createFullTextQuery( query, Month.class ).getResultSize()
    );

    query = monthQb
        .phrase()
          .onField( "mythology" )
          .sentence( "Month whitening" )
          .createQuery();

    assertEquals( "test slop", 0, fullTextSession.createFullTextQuery( query, Month.class ).getResultSize() );

    query = monthQb
        .phrase()
          .withSlop( 3 )
          .onField( "mythology" )
          .sentence( "Month whitening" )
          .createQuery();

    assertEquals( "test slop", 1, fullTextSession.createFullTextQuery( query, Month.class ).getResultSize() );

    query = monthQb
        .phrase()
          .onField( "mythology" )
          .sentence( "whitening" )
          .createQuery();
View Full Code Here

  public void testFacetEmbeddedAndCollections() throws Exception {
    FullTextSession fullTextSession = Search.getFullTextSession( openSession() );

    FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( new MatchAllDocsQuery(), Book.class );

    QueryBuilder builder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity( Book.class ).get();
    FacetingRequest facetReq = builder.facet()
        .name( "someFacet" )
        .onField( "authors.name_untokenized" )
        .discrete()
        .orderedBy( FacetSortOrder.COUNT_DESC )
        .includeZeroCounts( false ).maxFacetCount( 10 )
View Full Code Here

  @Test
  @TestForIssue(jiraKey = "HSEARCH-1074")
  public void testPhraseQueryWithNoTermsAfterAnalyzerApplication() throws Exception {
    Transaction transaction = fullTextSession.beginTransaction();
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .buildQueryBuilder().forEntity( Month.class ).get();

    Query query = monthQb.
        phrase()
        .onField( "mythology" )
        .sentence( "and" )
        .createQuery();
View Full Code Here

  }

  @Test
  public void testNumericRangeQueries() {
    Transaction transaction = fullTextSession.beginTransaction();
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .buildQueryBuilder().forEntity( Month.class ).get();

    Query query = monthQb
        .range()
          .onField( "raindropInMm" )
          .from( 0.23d )
          .to( 0.24d )
          .createQuery();
View Full Code Here

TOP

Related Classes of org.hibernate.search.query.dsl.QueryBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.