|
首页>相关研究方向>lucene/nutch> |
J2EE Search的增删查改及检索初步实现 |
|
Visited times , Welcome to Data Mining Forum & Data Mining Expert |
|
|
for (Book book : books) { fullTextEntityManager.index(book); } }
public void allSearch(String s,ApplicationContext ctx) throws ParseException{ EntityManager em=getJpaTemplate().getEntityManagerFactory().createEntityManager(); //这样取得EntityManger,若为getJpaTemplate().getEntityManager();结果为null makeIndex(em); FullTextEntityManager fullTextEntityManager = Search.createFullTextEntityManager(em); MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{"id", "name"},new StandardAnalyzer()); org.apache.lucene.search.Query query = parser.parse(s); FullTextQuery hibQuery = fullTextEntityManager.createFullTextQuery( query, Book.class ); List<Book> result = hibQuery.getResultList(); System.out.println(result); } }
Main: 数据挖掘研究院 package com.main;
import org.apache.lucene.queryParser.ParseException; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.jpa.BookDAO;
public class TestMain {
public static void main(String[] args) throws ParseException { String s="book1"; ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml"); BookDAO bd=BookDAO.getFromApplicationContext(ctx); bd.allSearch(s,ctx); }
} 增删查改很简单,读者自行试验,配置均已完成!
|
| 上一页 1 2 3 4 5 6下一页 |
|
|
|
[数据挖掘专家]
[数据挖掘研究院]
[数据挖掘论坛]
[数据挖掘实验室]
|
上一篇:
FilteredTermEnum (Lucene 2.2.0 API)
下一篇:Grails的全文检索插件
|
|
|
|