Hibernate Search 5.5.3 final 不获取索引数据结果?
Hibernate Search 5.5.3 final not fetching indexed data results?
我已经使用以下 Maven 依赖项设置了休眠
<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;
}
交易选项
@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 搜索不获取持久化的细节 object.There 没有错误 console.What 是错误吗?
我终于找到了错误,错误是我用于休眠搜索的参数 dealname 具有空值,因为它没有获取结果。
我已经使用以下 Maven 依赖项设置了休眠
<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;
}
交易选项
@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 搜索不获取持久化的细节 object.There 没有错误 console.What 是错误吗?
我终于找到了错误,错误是我用于休眠搜索的参数 dealname 具有空值,因为它没有获取结果。