标签:Lucene os io 使用 ar cti sp on c
public Sort()
public Sort(String field)
public Sort(String field,Boolean reverse) //默认为false,降序排序
public Sort(String[] fields)
public Sort(SortField field)
public Sort(SortField[] fields)
Sort sort=new Sort(“bookname”);按照“bookname“这个Field值进行降序排序
Sort sort=new Sort(“bookname”,true) //升序排序
Sort sort=new Sort(new String[]{“bookNumber”,”bookname”,”publishdate”});按照三个Field进行排序,但无法指定升序排序,所以用SortField
public SortField(String field)
public SortField(String field,Boolean reverse)
public SortField(String field,int type) //type表示当前Field值的类型
public SortField(String field,int type,boolean reverse) //默认为false,升序
Field值的类型:SortField.STRING、SortField.INT、SortField.FLOAT
SortField sf1=new SortField(“bookNumber”,SortField.INT,false);
SortField sf2=new SortField(“bookname”,SortField.STRING,false);
Hits hits=searcher.search(query,Sort.RELEVANCE);
Hits hits=searcher.search(query, Sort.INDEXORDER);
Sort sort=new Sort();
SortField sf=new SortField(“bookNumber”,SortField.INT,false);
sort.setSort(sf);
Hits hits=searcher.search(query,sort);
Sort sort=new Sort();
SortField sf1=new SortField(“bookNumber”,SortField.INT,false);//升序
SortField sf2=new SortField(“publishdate”,SortField.STRING,true);//降序
sort.setSort(new SortField[]{sf1,sf2});
Hits hits=searcher.search(query,sort);
String str1=”我”; String str2=”你”;
Collator co1=Collator.getInstance(Locale.CHINA);
Collator co2=Collator.getInstance(Locale.JAPAN);
System.out.println(Locale.CHINA+”:”+co1.compare(str1,str2));
System.out.println(Locale.JAPAN+”:”+co2.compare(str1,str2));
输出结果为:
zh_CN:1
ja_JP:-1
所以
public SortField(String field,Locale locale)
public SortField(String field,Locale locale,boolean reverse)
使用public Hits search(Query query,Filter filter)
(1)简单过滤
Hits hits=searcher.search(query,new AdvancedSecurityFilter());//过滤掉securitylevel为0的结果
(2)范围过滤—RangeFilter
只显示中间的
RangeFilter filter=new RangeFilter(“publishdate”,”1970-01-01”,”1998-12-31”,true,true”);
Hits hits=searcher.search(query,filter);
无上边界
public static RangeFilter More(String fieldname,String lowerTerm)
无下边界
public static RangeFilter Less(String fieldname,String upperTerm)
(3)在结果中查询QueryFilter
RangeQuery q=new RangeQuery(new Term(“publicshdate”,”1970-01-01”),
new Term(“publishdate”,”1999-01-01”),true);
QueryFilter filter=new QueryFilter(q);
Hits hits=searcher.search(query,filter);
public StopFilter(TokenStream input,String [] stopWords)
public StopFilter(TokenStream in,String [] stopWords,boolean ignoreCase)
public StopFilter(TokenStream input,Set stopWords,boolean ignoreCase)
public StopFilter(TokenStream in, Set stopWords)
其中,参数TokenStream代表当前正在进行处理的流;String类型的数组代表一个用数组表示的忽略词集合;Set类型的参数与String一样,是用来表示忽略词集合的;boolean表示当与忽略词集合中的词进行匹配时,是否需要忽略大小写。
String str="str1 str2 str3";
StringReader reader=new StringReader(str);
Analyzer anlyzer=new WhitespaceAnalyzer();
TokenStream ts=anlyzer.tokenStream("", reader);
Token t=null;
while( (t=ts.next())!=null ){
System.out.println(t.termText());
}
import jeasy.analysis.MMAnalyzer;
IndexWriter writer = new IndexWriter(INDEX_STORE_PATH, new MMAnalyzer()
, true);
String str=" Lucene是一个全文检索引擎的架构,"+
"提供了完整的查询引擎和索引引擎。Lucene以其方便使用、快" +
"速实施以及灵活性受到广泛的关注。它可以方便地嵌入到各种应用" +
"中实现针对应用的全文索引、检索功能,本总结使用lucene--2.3.2。";
MMAnalyzer analyzer=new MMAnalyzer();
try{
System.out.println(analyzer.segment(str, "|"));
}
catch(Exception e)
{
e.printStackTrace();
}
输出结果:lucene|一个|全文|检索|引擎|架构|提供|完整|查询|。。。。
MMAnalyzer analyzer=new MMAnalyzer(4);
MMAnalyzer.addWord(String word);
MMAnalyzer.addDictionary(Reader reader);
MMAnalyzer analyzer=new MMAnalyzer();
MMAnalyzer.addWord("迈克尔雷第");
RAMDirectory RAMDir=new RAMDirectory();
IndexWriter writer = new IndexWriter(RAMDir, new StandardAnalyzer(), true);//删除原有索引
IndexWriter writer2=new IndexWriter(FSDirectory.getDirectory(path,true),
new StandardAnalyzer(), true);
writer.addDocument(doc1);
writer2.addDocument(doc2);
writer.close();
writer2.addIndexes(new Directory[]{RAMDir});
writer2.close();
注意:在合并前一定要先关闭要加的索引器。
标签:Lucene os io 使用 ar cti sp on c
原文地址:http://www.cnblogs.com/hhcblog/p/3951619.html