Package org.hibernate.search.jpa

Examples of org.hibernate.search.jpa.FullTextQuery


    public <T extends DomainEntity> List<T> search(Class<T> clazz, String field, String query, int offset, int number) {
        FullTextEntityManager fullTextEntityManager = Search.createFullTextEntityManager(getEntityManager());
        MultiFieldQueryParser parser = new MultiFieldQueryParser(getAllIndexedFields(clazz, field), new StandardAnalyzer());
        try {
            org.apache.lucene.search.Query parsedquery = parser.parse(query.trim().replaceAll(" ", "* ") + "*");
            FullTextQuery hq = fullTextEntityManager.createFullTextQuery(parsedquery, clazz);
            hq.setMaxResults(number > 0 ? number : MAX_RESULTS);
            hq.setFirstResult(offset > 0 ? offset : 0);
            return hq.getResultList();
        } catch (Exception ex) {
            throw new IWebMvcException("Could not perform search", ex);
        }
    }
View Full Code Here


    else
      return null;
  }

  public List<E> list(Query query) {
    FullTextQuery fQuery = this.fem.createFullTextQuery(query, this.type);
    // 查询结果
    return fQuery.getResultList();
  }
View Full Code Here

  public Page<E> page(Pagination pagination, Query query) {
    if (pagination == null)
      throw new RuntimeException("分页对象不能为空");

    FullTextQuery fQuery = this.fem.createFullTextQuery(query, this.type);
    // 结果总数
    int size = fQuery.getResultSize();

    // 分页处理
    fQuery.setFirstResult(pagination.getFirstResult());
    fQuery.setMaxResults(pagination.getMaxResults());

    // 查询结果
    List<E> resultList = fQuery.getResultList();
    // 生成分页对象
    Page<E> page = new Page<E>(pagination.getFirstResult(), size,
        pagination.getPageSize(), resultList);
    return page;
  }
View Full Code Here

      Assert.hasText(query);
        try {
            FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(getEntityManager());
            List<String> indexedFields = getAllIndexedFields(clazz, "");
            MultiFieldQueryParser parser = new MultiFieldQueryParser(indexedFields.toArray(new String[indexedFields.size()]), new StandardAnalyzer());
            FullTextQuery hq = fullTextEntityManager.createFullTextQuery(parser.parse(query.trim().replaceAll(" ", "* ") + "*"), clazz);
            hq.setMaxResults(number > 0 ? number : MAX_RESULTS);
            hq.setFirstResult(offset > 0 ? offset : 0);
            return hq.getResultList();
        } catch (Exception ex) {
            throw new IWebMvcException("Could not perform search", ex);
        }
    }
View Full Code Here

        return ( searchResults != null ) && ( currentPage == 0 );
    }

    @SuppressWarnings("unchecked")
    private void updateResults() {
        FullTextQuery query;
        try {
            query = searchQuery(searchQuery);
        } catch (ParseException pe) {
            return;
        }
     
        List<Product> items = query
            .setMaxResults(pageSize + 1)
            .setFirstResult(pageSize * currentPage)
            .getResultList();
        numberOfResults = query.getResultSize();
       
        if (items.size() > pageSize) {
            searchResults = new ArrayList(items.subList(0, pageSize));
            hasMore = true;
        } else {
View Full Code Here

    final QueryBuilder b = ftem.getSearchFactory()
        .buildQueryBuilder()
        .forEntity( Insurance.class )
        .get();
    final Query lq = b.keyword().onField( "name" ).matching( "Macif" ).createQuery();
    final FullTextQuery ftQuery = ftem.createFullTextQuery( lq, Insurance.class );
    ftQuery.initializeObjectsWith( ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID );
    final List<Insurance> resultList = ftQuery.getResultList();
    assertThat( getFactory().getPersistenceUnitUtil().isLoaded( resultList.get( 0 ) ) ).isTrue();
    assertThat( resultList ).hasSize( 1 );
    for ( Object e : resultList ) {
      ftem.remove( e );
    }
View Full Code Here

    );

    org.apache.lucene.search.Query luceneQuery;
    luceneQuery = parser.parse( searchQuery );

    final FullTextQuery query = ftEm.createFullTextQuery( luceneQuery, Book.class );

    return query;
  }
View Full Code Here

                boostPerField);

        org.apache.lucene.search.Query luceneQuery;
        luceneQuery = parser.parse(searchQuery);

        final FullTextQuery query = ftEm.createFullTextQuery(luceneQuery, Book.class);

        return query;
    }
View Full Code Here

    );

    org.apache.lucene.search.Query luceneQuery;
    luceneQuery = parser.parse( searchQuery );

    final FullTextQuery query = ftEm.createFullTextQuery( luceneQuery, Book.class );

    return query;
  }
View Full Code Here

    );

    org.apache.lucene.search.Query luceneQuery;
    luceneQuery = parser.parse( searchQuery );

    final FullTextQuery query = ftEm.createFullTextQuery( luceneQuery, Book.class );

    return query;
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.jpa.FullTextQuery

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.