1
我試圖做一個Domain.class實體的簡單搜索。我有兩個測試。第一個應該創建索引,第二個應該進行實際的搜索。當我運行索引時,它只運行25-30個選擇語句到數據庫。當我做我的搜索測試時,它只獲得13次點擊。它應該在6300點左右。Lucene只發現幾個匹配
這是我的代碼:
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.
做錯了什麼即時通訊有什麼建議?
我檢查了這一點和EM應該罰款。感謝您的建議,但 – Marthin