我已经使用以下maven依赖
设置了hibernate <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>
我使用这段代码
配置了Hibernate索引 jpaProperties.put("hibernate.search.default.directory_provide","filesystem" );
jpaProperties.put("hibernate.search.default.indexBase","C:\\Index" );
这是我正在运行的代码
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;
}
这是我的模型类
@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;
}
但是当我坚持一个对象时,Hibernate搜索数据被索引,但是hibernate搜索没有获取持久化对象的细节。控制台中没有错误。错误是什么?
答案 0 :(得分:1)
我终于发现了错误,错误是我用于hibernate搜索的参数dealname有空值,因为它没有获取结果。