Package org.hibernate.search.query.dsl

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


      luceneQuery = parsingResult.getQuery();

      if (!cache.getCacheConfiguration().compatibility().enabled()) {
         // restrict on entity type
         QueryBuilder qb = searchFactory.buildQueryBuilder().forEntity(parsingResult.getTargetEntity()).get();
         luceneQuery = qb.bool()
               .must(qb.keyword().onField(TYPE_FIELD_NAME)
                           .ignoreFieldBridge()
                           .ignoreAnalyzer()
                           .matching(parsingResult.getTargetEntityName()).createQuery())
               .must(luceneQuery)
               .createQuery();
View Full Code Here


    @Override
    @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
    public List fullTextSearch(String filter) {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
        QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Question.class).get();
        org.apache.lucene.search.Query query = qb
                .keyword()
                .onFields("title", "text", "comments.text")
                .matching(filter)
                .createQuery();
View Full Code Here

    }


    private <T> FullTextQuery getFullTextQuery(Criteria query, Class<T> clazz, String keyword, Iterable<String> additionalFields) {
        final FullTextEntityManager session = Search.getFullTextEntityManager(entityManager);
        QueryBuilder qb = session.getSearchFactory()
                .buildQueryBuilder().forEntity(clazz).get();

        String[] searchTerms = keyword.split(" ");
        final TermMatchingContext context = qb.keyword().wildcard().onField("name");
        for (String field : additionalFields) {
            context.andField(field);
        }

        BooleanJunction<BooleanJunction> bool = qb.bool();
        for (String searchTerm : searchTerms) {
            bool.must(context.matching(String.format("*%s*", searchTerm.toLowerCase())).createQuery());
        }

        final FullTextQuery fullTextQuery = session.createFullTextQuery(bool.createQuery(), clazz);
View Full Code Here

     */
    private FullTextQuery createSearchQuery(
            FullTextSession fullTextSession,
            String searchText,
            PageRequest pageRequest) {
        QueryBuilder queryBuilder = fullTextSession.
                getSearchFactory().
                buildQueryBuilder().
                forEntity(Topic.class).
                get();
        org.apache.lucene.search.Query luceneQuery = queryBuilder.
                keyword().
                onField(Topic.TOPIC_TITLE_FIELD_DEF).
                andField(Topic.TOPIC_TITLE_FIELD_RU).
                andField(Topic.TOPIC_POSTS_PREFIX + Post.POST_CONTENT_FIELD_DEF).
                andField(Topic.TOPIC_POSTS_PREFIX + Post.POST_CONTENT_FIELD_RU).
View Full Code Here

    em.getTransaction().commit();

    em.clear();

    em.getTransaction().begin();
    final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( Clock.class ).get();
    Query query = builder.keyword().onField( "brand" ).matching( "Seiko" ).createQuery();
    FullTextQuery hibernateQuery = em.createFullTextQuery( query, Clock.class );

    hibernateQuery.setHint( "javax.persistence.query.timeout", 100 ); //not too low or we can't reproduce it consistently
    try {
      hibernateQuery.getResultSize();
View Full Code Here

    em.getTransaction().commit();

    em.clear();

    em.getTransaction().begin();
    final QueryBuilder builder = em.getSearchFactory().buildQueryBuilder().forEntity( Clock.class ).get();
    Query query = builder.keyword().onField( "brand" ).matching( "Seiko" ).createQuery();
    FullTextQuery hibernateQuery = em.createFullTextQuery( query, Clock.class );
    List results = hibernateQuery.getResultList();
    assertEquals( 500, results.size() );

    em.clear();

    query = builder.keyword().onField( "brand" ).matching( "Swatch" ).createQuery();
    hibernateQuery = em.createFullTextQuery( query, Clock.class );
    hibernateQuery.limitExecutionTimeTo( 1, TimeUnit.NANOSECONDS );
    List result = hibernateQuery.getResultList();
    System.out.println( "Result size early: " + result.size() );
    assertEquals( "Test early failure, before the number of results are even fetched", 0, result.size() );
View Full Code Here

    fullTextSession.close();
    super.tearDown();
  }

  public FullTextQuery createMatchAllQuery(Class<?> clazz) {
    QueryBuilder builder = queryBuilder( clazz );
    Query luceneQuery = builder.all().createQuery();
    return fullTextSession.createFullTextQuery( luceneQuery, clazz );
  }
View Full Code Here

  @Override
  @Before
  public void setUp() throws Exception {
    super.setUp();
    fts = Search.getFullTextSession( openSession() );
    QueryBuilder builder = fts.getSearchFactory().buildQueryBuilder().forEntity( Clock.class ).get();
    allSeikoClocksQuery = builder.keyword().onField( "brand" ).matching( "Seiko" ).createQuery();
    allSwatchClocksQuery = builder.keyword().onField( "brand" ).matching( "Swatch" ).createQuery();
    noMatchQuery = builder.keyword().onField( "brand" ).matching( "Blah" ).createQuery();
    matchAllQuery = builder.all().createQuery();
    storeClocks( fts );
  }
View Full Code Here

      return cars;
    }

    private void buildFullTextQuery(String queryString, FullTextSession fullTextSession) {
      // get a query builder
      final QueryBuilder builder = fullTextSession.getSearchFactory()
          .buildQueryBuilder()
          .forEntity( Car.class )
          .get();

      // build a Lucene query
      final Query query = builder.keyword().onField( "make" ).matching( queryString ).createQuery();

      // create facets for navigation
      // discrete faceting
      final FacetingRequest colorFacet = builder.facet()
          .name( colorFacetName )
          .onField( "color" )
          .discrete()
          .createFacetingRequest();
      // range faceting
      final FacetingRequest priceFacet = builder.facet()
          .name( cubicCapacityFacetName )
          .onField( "cubicCapacity" )
          .range()
          .below( 2500 ).excludeLimit()
          .from( 2500 ).to( 3000 )
View Full Code Here

  @Test
  @SuppressWarnings("unchecked")
  public void testBoolean() throws Exception {
    Transaction transaction = fullTextSession.beginTransaction();
    final QueryBuilder monthQb = fullTextSession.getSearchFactory()
        .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() );

    //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() );
    assertEquals( "February", results.get( 0 ).getName() );
    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() );
    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

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.