📄 fieldfilter.java
字号:
package net.ijsp.news.search;/** * <p>Title:搜索 </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: ijsp.net</p> * @author ccjsmile * @version 1.0 */import java.util.BitSet;import java.io.IOException;import org.apache.lucene.index.Term;import org.apache.lucene.index.TermDocs;import org.apache.lucene.index.IndexReader;public class FieldFilter extends org.apache.lucene.search.Filter { private Term [] searchTerms; public FieldFilter(String field, String [] values) { searchTerms = new Term[values.length]; for (int i=0; i<values.length; i++) { searchTerms[i] = new Term(field, values[i]); } } public FieldFilter(String field, String value) { this(field, new String[] { value }); } public BitSet bits(IndexReader reader) throws IOException { //Create a new BitSet with a capacity equal to the size of the index. BitSet bits = new BitSet(reader.maxDoc()); //Match all search terms. for (int i=0; i < searchTerms.length; i++) { //Get an enumeration of all the documents that match the specified //field value. TermDocs matchingDocs = reader.termDocs(searchTerms[i]); try { if (matchingDocs != null) { while(matchingDocs.next()) { bits.set(matchingDocs.doc()); } } } finally { if (matchingDocs != null) { matchingDocs.close(); } } } return bits; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -