本文整理匯總了Java中net.paoding.analysis.analyzer.PaodingAnalyzer類的典型用法代碼示例。如果您正苦於以下問題:Java PaodingAnalyzer類的具體用法?Java PaodingAnalyzer怎麽用?Java PaodingAnalyzer使用的例子?那麽恭喜您, 這裏精選的類代碼示例或許可以為您提供幫助。
PaodingAnalyzer類屬於net.paoding.analysis.analyzer包,在下文中一共展示了PaodingAnalyzer類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: searchIndex
點讚 3
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
/**
* 查詢索引
*
* @param keywords
* @return
* @throws Exception
*/
public List searchIndex(Integer typeId, String keywords) throws Exception {
// 1.init searcher
Analyzer analyzer = new PaodingAnalyzer();
IndexReader reader = IndexReader.open(typeId == appConfig.getGameTypeId() ? appConfig.getGameIndexDir()
: appConfig.getSoftIndexDir());
BooleanClause.Occur[] flags = new BooleanClause.Occur[] { BooleanClause.Occur.SHOULD,
BooleanClause.Occur.SHOULD };
Query query = MultiFieldQueryParser.parse(keywords, appConfig.getQueryFields(), flags, analyzer);
query = query.rewrite(reader);
// 2.search
List docs = new ArrayList();
Hits hits = (typeId == appConfig.getGameTypeId() ? gameSearcher.search(query, Sort.RELEVANCE) : softSearcher
.search(query, Sort.RELEVANCE));// searcher.search(query,
// Sort.RELEVANCE);
for (int i = 0; i < hits.length(); i++) {
docs.add(hits.doc(i));
}
// 3.return
reader.close();
return docs;
}
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:31,
示例2: search
點讚 3
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
@RequestMapping("/search")
public ModelAndView search(@RequestParam(value="keyword")String keyword,@RequestParam(value="start")int start,@RequestParam(value="pagesize")int pagesize){
QueryResult queryResult= null;
try {
keyword=keyword==null?"":keyword.trim();
//keyword=new String(keyword.getBytes("iso-8859-1"),"utf-8");
if(!"".equals(keyword)){
queryResult = bookService.query(keyword, start, pagesize, new PaodingAnalyzer());
}
} catch (Exception e) {
e.printStackTrace();
}
ModelAndView modelAndView = new ModelAndView("list");
modelAndView.addObject("queryResult", queryResult);
return modelAndView;
}
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:17,
示例3: search
點讚 3
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
@Test
public void search(){
int start=0;
int pagesize=5;
Analyzer analyzer=new PaodingAnalyzer();
String[] field=new String[]{"name","description","authors.name"};
QueryResult queryResult= null;
try {
queryResult = bookDao.query("實戰", start, pagesize, analyzer, field);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("共檢索到["+queryResult.getSearchresultsize()+"]條記錄!");
for (Book book : queryResult.getSearchresult()) {
System.out.println("書名:"+book.getName()+"\n描述:"+book.getDescription()+"\n出版日期:"+book.getPublicationDate());
System.out.println("----------------------------------------------------------");
}
}
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:21,
示例4: search
點讚 3
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
@RequestMapping("/search")
public ModelAndView search(@RequestParam(value="keyword")String keyword,@RequestParam(value="start")int start,@RequestParam(value="pagesize")int pagesize){
QueryResult queryResult= null;
try {
keyword=keyword==null?"":keyword.trim();
//keyword=new String(keyword.getBytes("iso-8859-1"),"utf-8");
if(!"".equals(keyword)){
queryResult = bookService.query(keyword, start, pagesize, new PaodingAnalyzer());
}
} catch (Exception e) {
e.printStackTrace();
}
ModelAndView modelAndView = new ModelAndView("list");
modelAndView.addObject("queryResult", queryResult);
modelAndView.addObject("keyword", keyword);
return modelAndView;
}
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:18,
示例5: initDir
點讚 3
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
public static IndexWriter initDir (Directory dir, boolean create) {
Analyzer analyzer = new PaodingAnalyzer(); // create analyzer
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_35, analyzer);
if (create) {
// Create a new index in the directory, removing any previously
// indexed documents:
iwc.setOpenMode(OpenMode.CREATE);
} else {
// Add new documents to an existing index:
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
}
// TODO: iwc optimization
IndexWriter writer = null;
try {
writer = new IndexWriter(dir, iwc);
writer.commit();
} catch (Exception e) {
logger.error("initial dir error. " + e.getMessage());
}
return writer;
}
開發者ID:lulyon,項目名稱:RealTimeIndexer,代碼行數:24,
示例6: main
點讚 2
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
public static void main(String[] args) throws Exception{
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory sessionFactory = applicationContext.getBean("hibernate4sessionFactory",SessionFactory.class);
FullTextSession fullTextSession = Search.getFullTextSession(sessionFactory.openSession());
//使用Hibernate Search api查詢 從多個字段匹配 name、description、authors.name
//QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Book.class ).get();
//Query luceneQuery = qb.keyword().onFields("name","description","authors.name").matching("移動互聯網").createQuery();
//使用lucene api查詢 從多個字段匹配 name、description、authors.name
//使用庖丁分詞器
MultiFieldQueryParser queryParser=new MultiFieldQueryParser(Version.LUCENE_36, new String[]{"name","description","authors.name"}, new PaodingAnalyzer());
Query luceneQuery=queryParser.parse("實戰");
FullTextQuery fullTextQuery =fullTextSession.createFullTextQuery(luceneQuery, Book.class);
//設置每頁顯示多少條
fullTextQuery.setMaxResults(5);
//設置當前頁
fullTextQuery.setFirstResult(0);
//高亮設置
SimpleHTMLFormatter formatter=new SimpleHTMLFormatter("", "");
QueryScorer queryScorer=new QueryScorer(luceneQuery);
Highlighter highlighter=new Highlighter(formatter, queryScorer);
@SuppressWarnings("unchecked")
List resultList = fullTextQuery.list();
System.out.println("共查找到["+resultList.size()+"]條記錄");
for (Book book : resultList) {
String highlighterString=null;
Analyzer analyzer=new PaodingAnalyzer();
try {
//高亮name
highlighterString=highlighter.getBestFragment(analyzer, "name", book.getName());
if(highlighterString!=null){
book.setName(highlighterString);
}
//高亮authors.name
Set authors = book.getAuthors();
for (Author author : authors) {
highlighterString=highlighter.getBestFragment(analyzer, "authors.name", author.getName());
if(highlighterString!=null){
author.setName(highlighterString);
}
}
//高亮description
highlighterString=highlighter.getBestFragment(analyzer, "description", book.getDescription());
if(highlighterString!=null){
book.setDescription(highlighterString);
}
} catch (Exception e) {
}
System.out.println("書名:"+book.getName()+"\n描述:"+book.getDescription()+"\n出版日期:"+book.getPublicationDate());
System.out.println("----------------------------------------------------------");
}
fullTextSession.close();
sessionFactory.close();
}
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:62,
示例7: main
點讚 2
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
public static void main(String[] args) throws Exception{
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
EntityManagerFactory entityManagerFactory = applicationContext.getBean("entityManagerFactory",EntityManagerFactory.class);
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManagerFactory.createEntityManager());
//使用Hibernate Search api查詢 從多個字段匹配 name、description、authors.name
//QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Book.class ).get();
//Query luceneQuery = qb.keyword().onFields("name","description","authors.name").matching("移動互聯網").createQuery();
//使用lucene api查詢 從多個字段匹配 name、description、authors.name
//使用庖丁分詞器
MultiFieldQueryParser queryParser=new MultiFieldQueryParser(Version.LUCENE_36, new String[]{"name","description","authors.name"}, new PaodingAnalyzer());
Query luceneQuery=queryParser.parse("實戰");
FullTextQuery fullTextQuery =fullTextEntityManager.createFullTextQuery(luceneQuery, Book.class);
//設置每頁顯示多少條
fullTextQuery.setMaxResults(5);
//設置當前頁
fullTextQuery.setFirstResult(0);
//高亮設置
SimpleHTMLFormatter formatter=new SimpleHTMLFormatter("", "");
QueryScorer queryScorer=new QueryScorer(luceneQuery);
Highlighter highlighter=new Highlighter(formatter, queryScorer);
@SuppressWarnings("unchecked")
List resultList = fullTextQuery.getResultList();
for (Book book : resultList) {
String highlighterString=null;
Analyzer analyzer=new PaodingAnalyzer();
try {
//高亮name
highlighterString=highlighter.getBestFragment(analyzer, "name", book.getName());
if(highlighterString!=null){
book.setName(highlighterString);
}
//高亮authors.name
Set authors = book.getAuthors();
for (Author author : authors) {
highlighterString=highlighter.getBestFragment(analyzer, "authors.name", author.getName());
if(highlighterString!=null){
author.setName(highlighterString);
}
}
//高亮description
highlighterString=highlighter.getBestFragment(analyzer, "description", book.getDescription());
if(highlighterString!=null){
book.setDescription(highlighterString);
}
} catch (Exception e) {
}
}
fullTextEntityManager.close();
entityManagerFactory.close();
}
開發者ID:v5developer,項目名稱:maven-framework-project,代碼行數:60,
示例8: main
點讚 2
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
if (args.length != 0) {
QUERY = args[0];
}
// 將庖丁封裝成符合Lucene要求的Analyzer規範
Analyzer analyzer = new PaodingAnalyzer();
//讀取本類目錄下的text.txt文件
String content = ContentReader.readText(English.class);
//接下來是標準的Lucene建立索引和檢索的代碼
Directory ramDir = new RAMDirectory();
IndexWriter writer = new IndexWriter(ramDir, analyzer);
Document doc = new Document();
Field fd = new Field(FIELD_NAME, content, Field.Store.YES,
Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
doc.add(fd);
writer.addDocument(doc);
writer.optimize();
writer.close();
IndexReader reader = IndexReader.open(ramDir);
String queryString = QUERY;
QueryParser parser = new QueryParser(FIELD_NAME, analyzer);
Query query = parser.parse(queryString);
Searcher searcher = new IndexSearcher(ramDir);
query = query.rewrite(reader);
System.out.println("Searching for: " + query.toString(FIELD_NAME));
Hits hits = searcher.search(query);
BoldFormatter formatter = new BoldFormatter();
Highlighter highlighter = new Highlighter(formatter, new QueryScorer(
query));
highlighter.setTextFragmenter(new SimpleFragmenter(50));
for (int i = 0; i < hits.length(); i++) {
String text = hits.doc(i).get(FIELD_NAME);
int maxNumFragmentsRequired = 5;
String fragmentSeparator = "...";
TermPositionVector tpv = (TermPositionVector) reader
.getTermFreqVector(hits.id(i), FIELD_NAME);
TokenStream tokenStream = TokenSources.getTokenStream(tpv);
String result = highlighter.getBestFragments(tokenStream, text,
maxNumFragmentsRequired, fragmentSeparator);
System.out.println("\n" + result);
}
reader.close();
}
開發者ID:no8899,項目名稱:paoding-for-lucene-2.4,代碼行數:48,
示例9: main
點讚 2
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
if (args.length != 0) {
QUERY = args[0];
}
// 將庖丁封裝成符合Lucene要求的Analyzer規範
Analyzer analyzer = new PaodingAnalyzer();
//讀取本類目錄下的text.txt文件
String content = ContentReader.readText(Chinese.class);
//接下來是標準的Lucene建立索引和檢索的代碼
Directory ramDir = new RAMDirectory();
IndexWriter writer = new IndexWriter(ramDir, analyzer);
Document doc = new Document();
Field fd = new Field(FIELD_NAME, content, Field.Store.YES,
Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
doc.add(fd);
writer.addDocument(doc);
writer.optimize();
writer.close();
IndexReader reader = IndexReader.open(ramDir);
String queryString = QUERY;
QueryParser parser = new QueryParser(FIELD_NAME, analyzer);
Query query = parser.parse(queryString);
Searcher searcher = new IndexSearcher(ramDir);
query = query.rewrite(reader);
System.out.println("Searching for: " + query.toString(FIELD_NAME));
Hits hits = searcher.search(query);
BoldFormatter formatter = new BoldFormatter();
Highlighter highlighter = new Highlighter(formatter, new QueryScorer(
query));
highlighter.setTextFragmenter(new SimpleFragmenter(50));
for (int i = 0; i < hits.length(); i++) {
String text = hits.doc(i).get(FIELD_NAME);
int maxNumFragmentsRequired = 5;
String fragmentSeparator = "...";
TermPositionVector tpv = (TermPositionVector) reader
.getTermFreqVector(hits.id(i), FIELD_NAME);
TokenStream tokenStream = TokenSources.getTokenStream(tpv);
String result = highlighter.getBestFragments(tokenStream, text,
maxNumFragmentsRequired, fragmentSeparator);
System.out.println("\n" + result);
}
reader.close();
}
開發者ID:no8899,項目名稱:paoding-for-lucene-2.4,代碼行數:48,
示例10: testIndex
點讚 2
import net.paoding.analysis.analyzer.PaodingAnalyzer; //導入依賴的package包/類
public static void testIndex() throws Exception{
// Files will be indexed.
File fileDir = new File("D:\\luceneweb\\docs");
// Files will store the index of 'fileDir'.
File indexDir = new File("D:\\luceneweb\\index");
// Create Index writer object
Analyzer paodingAnalyzer = new PaodingAnalyzer();
Directory FSDir = FSDirectory.open(indexDir);
IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, paodingAnalyzer); // new StandardAnalyzer(Version.LUCENE_35)
IndexWriter indexWriter = new IndexWriter(FSDir, conf);
File[] textFiles = fileDir.listFiles();
long startTime = new Date().getTime();
try {
System.out.println("Indexing to directory '" + indexDir.getName() + "'...");
// Add document to index
for(int i = 0; i < textFiles.length; i++){
if(textFiles[i].isFile() && textFiles[i].getName().endsWith(".txt")){
System.out.println("File " + textFiles[i].getCanonicalPath().substring(18) + " ���ڱ�����...");
String tmp = FileReaderAll(textFiles[i].getCanonicalPath(), "GBK");
Document document = new Document();
System.out.println("--" + (i + 1) + "-- " + textFiles[i].getPath().substring(18));
Field FieldPath = new Field("path", textFiles[i].getPath(),
Field.Store.YES, Field.Index.NO);
// System.out.println("--" + (i + 1) + "-- " + tmp);
Field FieldBody = new Field("body", tmp, Field.Store.YES,
Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
// Construct document object
document.add(FieldPath);
document.add(FieldBody);
// Add into the index dir
indexWriter.addDocument(document);
} // if
} // for
// Optimize of the index
indexWriter.optimize();
indexWriter.close();
// Test the time
long endTime = new Date().getTime();
System.out.println("�⻨���� " + (endTime - startTime)
+ " ���������ļ����ӵ�������ȥ! " + fileDir.getPath());
}catch(Exception e) {
e.printStackTrace();
}
}
開發者ID:YinYanfei,項目名稱:CadalWorkspace,代碼行數:57,
注:本文中的net.paoding.analysis.analyzer.PaodingAnalyzer類示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。