Package org.hibernate.search.query.dsl

Examples of org.hibernate.search.query.dsl.QueryBuilder.keyword()


        .buildQueryBuilder().forEntity( Month.class ).get();

    //must
    Query query = monthQb
        .bool()
        .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() )
        .createQuery();

    List<Month> results = fullTextSession.createFullTextQuery( query, Month.class ).list();
    assertEquals( 1, results.size() );
    assertEquals( "January", results.get( 0 ).getName() );
View Full Code Here


    //must not + all
    query = monthQb
        .bool()
          .should( monthQb.all().createQuery() )
          .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() )
            .not()
          .createQuery();

    results = fullTextSession.createFullTextQuery( query, Month.class ).list();
    assertEquals( 2, results.size() );
View Full Code Here

    assertEquals( "March", results.get( 1 ).getName() );

    //implicit must not + all (not recommended)
    query = monthQb
        .bool()
          .must( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() )
            .not()
          .createQuery();
    results = fullTextSession.createFullTextQuery( query, Month.class ).list();
    assertEquals( 2, results.size() );
    assertEquals( "February", results.get( 0 ).getName() );
View Full Code Here

    assertEquals( "March", results.get( 1 ).getName() );

    //all except (recommended)
    query = monthQb
        .all()
          .except( monthQb.keyword().onField( "mythology" ).matching( "colder" ).createQuery() )
        .createQuery();

    results = fullTextSession.createFullTextQuery( query, Month.class ).list();
    assertEquals( 2, results.size() );
    assertEquals( "February", results.get( 0 ).getName() );
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

    return parser.parse( "*" );
  }

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

  private void searchKeywordWithExpectedNumberOfResults(FullTextSession fullTextSession, String queryString, int expectedNumberOfResults)
      throws Exception {
    TermQuery query = new TermQuery( new Term( "value", queryString ) );
View Full Code Here

    Transaction transaction = session.beginTransaction();
    QueryBuilder queryBuilder = fullTextSession.getSearchFactory()
        .buildQueryBuilder()
        .forEntity( FormulaAdd.class )
        .get();
    Query luceneQuery = queryBuilder.keyword().onField( "aplusB" ).ignoreAnalyzer().matching( value ).createQuery();
    FullTextQuery query = fullTextSession.createFullTextQuery( luceneQuery, FormulaAdd.class );
    List resultsList = query.list();
    transaction.commit();
    Assert.assertEquals( 1, resultsList.size() );
    FormulaAdd result = (FormulaAdd) resultsList.get( 0 );
View Full Code Here

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

    Query query = monthQb.keyword()
        .onField( "raindropInMm" )
        .matching( 0.231d )
        .createQuery();

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

  @Test
  public void testFieldBridge() {
    Transaction transaction = fullTextSession.beginTransaction();
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .buildQueryBuilder().forEntity( Month.class ).get();
    Query query = monthQb.keyword()
        .onField( "monthRomanNumber" )
        .matching( 2 )
        .createQuery();
    FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery( query, Month.class );
    List<?> results = fullTextQuery.list();
View Full Code Here

        .getSearchFactory()
        .buildQueryBuilder()
        .forEntity( Car.class )
        .get();

    Query query = builder.keyword().onField( "name" ).matching( "Morris" ).createQuery();
    List<?> results = fullTextSession.createFullTextQuery( query ).list();

    assertEquals( "expected one instance of indexed sub-type", 1, results.size() );
    assertEquals( 180, ( (SportsCar) results.get( 0 ) ).getEnginePower() );
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.