Package org.hibernate.search.query.dsl

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


           .buildQueryBuilder().forEntity(Product.class).get();
       
        //Hibernate Search fulltext query example:
       
        //query to match exact terms occurrence, using custom boosts:
        Query queryToFindExactTerms = queryBuilder.keyword()
           .onFields("title").boostedTo(4f)
           .andField("description").boostedTo(2f)
           .andField("actors.name").boostedTo(2f)
           .andField("categories.name").boostedTo(0.5f)
           .matching(textQuery)
View Full Code Here


           .andField("categories.name").boostedTo(0.5f)
           .matching(textQuery)
           .createQuery();
       
        //Similar query, but using NGram matching instead of exact terms:
        Query queryToFindMathingNGrams = queryBuilder.keyword()
           .onFields("title:ngrams").boostedTo(2f)
           .andField("description:ngrams")
           .andField("actors.name:ngrams")
           .andField("categories.name:ngrams").boostedTo(0.2f)
           .matching(textQuery)
View Full Code Here

         .buildQueryBuilder()
         .forEntity(BlogEntry.class)
         .get();
     
      //A fulltext query using English Analyzer
      Query queryUsingEnglishStemmer = queryBuilder.keyword()
         .onFields("title:en").boostedTo(4f)
         .andField("body:en")
         .matching(searchPattern)
         .createQuery();
     
View Full Code Here

         .andField("body:en")
         .matching(searchPattern)
         .createQuery();
     
      //A fulltext query using ngrams
      Query queryUsingNGrams = queryBuilder.keyword()
         .onFields("title:ngrams").boostedTo(2f)
         .andField("body:ngrams").boostedTo(0.4f)
         .matching(searchPattern)
         .createQuery();
     
View Full Code Here

    transaction = fts.beginTransaction();
    final QueryBuilder b = fts.getSearchFactory()
        .buildQueryBuilder()
        .forEntity( Insurance.class )
        .get();
    final Query lq = b.keyword().onField( "name" ).matching( "Macif" ).createQuery();
    final FullTextQuery ftQuery = fts.createFullTextQuery( lq, Insurance.class );
    ftQuery.initializeObjectsWith( ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID );
    final List<Insurance> resultList = ftQuery.list();
    assertThat( resultList ).hasSize( 1 );
    for ( Object e : resultList ) {
View Full Code Here

    getTransactionManager().begin();
    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 );
View Full Code Here

    getTransactionManager().begin();
    final QueryBuilder b = ftSession.getSearchFactory()
        .buildQueryBuilder()
        .forEntity( Insurance.class )
        .get();
    final Query lq = b.keyword().onField( "name" ).matching( "Macif" ).createQuery();
    final org.hibernate.search.FullTextQuery ftQuery = ftSession.createFullTextQuery( lq, Insurance.class );
    ftQuery.initializeObjectsWith( ObjectLookupMethod.SKIP, DatabaseRetrievalMethod.FIND_BY_ID );
    final List<Insurance> resultList = ftQuery.list();
    assertThat( getFactory().getPersistenceUnitUtil().isLoaded( resultList.get( 0 ) ) ).isTrue();
    assertThat( resultList ).hasSize( 1 );
View Full Code Here

    FullTextEntityManager fullTextEm = null;
    try {
      getTransactionManager().begin();
      fullTextEm = Search.getFullTextEntityManager( createEntityManager() );
      QueryBuilder queryBuilder = fullTextEm.getSearchFactory().buildQueryBuilder().forEntity( IndexedNews.class ).get();
      Query luceneQuery = queryBuilder.keyword().wildcard().onField( "newsId" ).ignoreFieldBridge().matching( "tit*" ).createQuery();
      @SuppressWarnings("unchecked")
      List<IndexedNews> list = fullTextEm.createFullTextQuery( luceneQuery ).getResultList();
      assertThat( list ).hasSize( 1 );

      List<IndexedLabel> labels = list.get( 0 ).getLabels();
View Full Code Here

    try {
      getTransactionManager().begin();
      fullTextEm = Search.getFullTextEntityManager( createEntityManager() );
      QueryBuilder b = fullTextEm.getSearchFactory().buildQueryBuilder().forEntity( IndexedLabel.class ).get();
      {
        Query luceneQuery = b.keyword().wildcard().onField( "name" ).matching( "tes*" ).createQuery();
        List<IndexedLabel> labels = fullTextEm.createFullTextQuery( luceneQuery ).getResultList();
        assertThat( labels ).hasSize( 1 );
        assertThat( contains( labels, "test" ) ).isTrue();
      }
      {
View Full Code Here

        List<IndexedLabel> labels = fullTextEm.createFullTextQuery( luceneQuery ).getResultList();
        assertThat( labels ).hasSize( 1 );
        assertThat( contains( labels, "test" ) ).isTrue();
      }
      {
        Query luceneQuery = b.keyword().wildcard().onField( "name" ).matching( "mas*" ).createQuery();
        List<IndexedLabel> labels = fullTextEm.createFullTextQuery( luceneQuery ).getResultList();
        assertThat( labels ).hasSize( 1 );
        assertThat( contains( labels, "massindex" ) ).isTrue();
      }
      operationSuccessful = true;
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.