Lucene 只找到了一些命中
我尝试对 Domain.class 实体进行简单搜索。我有两个测试。第一个应该创建索引,第二个进行实际搜索。当我运行索引时,它只对数据库运行 25-30 个选择语句。当我进行搜索测试时,它只获得 13 个命中。点击率应该在6300左右。
这是我的代码:
public class luceneTests {
DAOFacade dao = PMF.getTestDAO();
@Test(enabled = false)//only run once to fill the index
public void runFirstOnly() throws InterruptedException{
EntityManager em = dao.getEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
fullTextEntityManager.createIndexer(Domain.class).startAndWait();
}
@Test(enabled = true)
public void simpleSearchTest(){
EntityManager em = dao.getEntityManager();
FullTextEntityManager fullTextEntityManager =
org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
em.getTransaction().begin();
// create native Lucene query unsing the query DSL
// alternatively you can write the Lucene query using the Lucene query parser
// or the Lucene programmatic API. The Hibernate Search DSL is recommended though
QueryBuilder qb = fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity( Domain.class ).get();
org.apache.lucene.search.Query query = qb
.keyword().wildcard()
.onField("domain")
// .andField("state")
.matching("domaindom*")
.createQuery();
// wrap Lucene query in a javax.persistence.Query
javax.persistence.Query persistenceQuery =
fullTextEntityManager.createFullTextQuery(query, Domain.class).;
// execute search
List result = persistenceQuery.setFirstResult(0).setMaxResults(100).getResultList();
System.out.println("SIZE : " +result.size());
for(Object o : result){
if(o instanceof Domain)
System.out.println(" Object: "+o + ((Domain)o).getDomainId() + " " + ((Domain)o).getNameservers());
}
em.getTransaction().commit();
em.close();
}
}
域实体
@Entity
@Indexed
@Table(name="Domain", schema="domains")
@DiscriminatorValue(value="DOMAIN")
public class Domain implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="domainId", nullable=false)
public String domainId;
@Column(name="domain", nullable=false)
@Field(index = Index.UN_TOKENIZED, store= Store.NO)
public String domain;
// there is alot more in this entity but I dont belive its needed.
关于我在这里做错了什么有什么建议吗?
Im trying to do a simple search on a Domain.class entity. I have two test. The first should create the indexes and the second does a actual search. When I run the index it only runs 25-30 select statements to the DB. When I do my search test it only get 13 hits. It should be around 6300 hits.
This is my code:
public class luceneTests {
DAOFacade dao = PMF.getTestDAO();
@Test(enabled = false)//only run once to fill the index
public void runFirstOnly() throws InterruptedException{
EntityManager em = dao.getEntityManager();
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
fullTextEntityManager.createIndexer(Domain.class).startAndWait();
}
@Test(enabled = true)
public void simpleSearchTest(){
EntityManager em = dao.getEntityManager();
FullTextEntityManager fullTextEntityManager =
org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
em.getTransaction().begin();
// create native Lucene query unsing the query DSL
// alternatively you can write the Lucene query using the Lucene query parser
// or the Lucene programmatic API. The Hibernate Search DSL is recommended though
QueryBuilder qb = fullTextEntityManager.getSearchFactory()
.buildQueryBuilder().forEntity( Domain.class ).get();
org.apache.lucene.search.Query query = qb
.keyword().wildcard()
.onField("domain")
// .andField("state")
.matching("domaindom*")
.createQuery();
// wrap Lucene query in a javax.persistence.Query
javax.persistence.Query persistenceQuery =
fullTextEntityManager.createFullTextQuery(query, Domain.class).;
// execute search
List result = persistenceQuery.setFirstResult(0).setMaxResults(100).getResultList();
System.out.println("SIZE : " +result.size());
for(Object o : result){
if(o instanceof Domain)
System.out.println(" Object: "+o + ((Domain)o).getDomainId() + " " + ((Domain)o).getNameservers());
}
em.getTransaction().commit();
em.close();
}
}
domain entity
@Entity
@Indexed
@Table(name="Domain", schema="domains")
@DiscriminatorValue(value="DOMAIN")
public class Domain implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="domainId", nullable=false)
public String domainId;
@Column(name="domain", nullable=false)
@Field(index = Index.UN_TOKENIZED, store= Store.NO)
public String domain;
// there is alot more in this entity but I dont belive its needed.
Any suggestions on what im doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何在 DAO 中创建 EntityManager? IE
也许这个 EntityManager 没有看到之前所做的更改......
How do you create your EntityManager in the DAO? I.e.
Maybe this EntityManager doesn't see the changes made before ...