briantaurostack7
briantaurostack7

Reputation: 1273

Hibernate Search 5.5.3 final not fetching indexed data results?

I have set up hibernate with the following maven dependency

     <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.1.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.1.0.Final</version>
    </dependency>
   <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search-orm</artifactId>
        <version>5.5.3.Final</version>
    </dependency>
     <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.7.2.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql.driver.version}</version>
    </dependency>

I have configure Hibernate with indexing using this piece of code

   jpaProperties.put("hibernate.search.default.directory_provide","filesystem" );
    jpaProperties.put("hibernate.search.default.indexBase","C:\\Index" );

This is the code I am running

  public List<Deals> findDealBySubcatIdhsearch(long subCatId,String search){
    //Option or suboption may be included in future, if needed
    logger.info("Deal nameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"+search+"iiiiiiiiiiid"+subCatId);

    FullTextEntityManager fullTextEntityManager  = org.hibernate.search.jpa.Search.
                getFullTextEntityManager(em);
     QueryBuilder qb = fullTextEntityManager.getSearchFactory()
     .buildQueryBuilder().forEntity(Deals.class).get();
   org.apache.lucene.search.Query query = qb
     .keyword().wildcard().onFields("dealName").matching("*"+search.toLowerCase()+"*")
     .createQuery();

   org.hibernate.search.jpa.FullTextQuery jpaQueryy = 
      fullTextEntityManager.createFullTextQuery(query, Deals.class);

//jpaQueryy.enableFullTextFilter("category").setParameter("categoryId", 1);
   List<Deals> results = jpaQueryy.getResultList();


                    logger.info("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"+jpaQueryy.getResultSize()+"Subid"+subCatId);
                    if(jpaQueryy.getResultList().size()==0)
                    {
                          query = qb
                                 .keyword().onFields("dealName").matching("*"+search.toLowerCase()+"*")
                                 .createQuery();

                                jpaQueryy = 
                                  fullTextEntityManager.createFullTextQuery(query, Deals.class);

                                results = jpaQueryy.getResultList();
                    }
                     List<Deals> output = 
                            results.parallelStream()
                              .filter(d -> d.getSubcategories().getSubcategoryId() == subCatId)
                              .collect(Collectors.toList());

   return output;
}

Here are my model classes

@Entity
@Indexed
@Table(name = "deals")
 public class Deal
 {

 @Id
 @Basic(optional = false)
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Column(name = "deal_id")
 private Long dealId;

 @Column(name = "deal_name")
 @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
 private String dealName;
 }

DealOptions

@Entity
@Indexed
@Table(name = "dealoptions")
public class DealOptions
{

 @Id
 @Basic(optional = false)
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 @Column(name = "option_id")
 private Long optionId;

 @Column(name = "name")
 @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
 private String Name;


 } 

But when i persist a object Hibernate search data is indexed but hibernate search does not fetch the details of the persisted object.There is no error in the console.What is the error?

Upvotes: 1

Views: 256

Answers (1)

briantaurostack7
briantaurostack7

Reputation: 1273

I finally found the error the error was that the parameter dealname which i was using for hibernate search had null values because of that it did not fetch the result.

Upvotes: 1

Related Questions