RegexQuery正则表达式源代码

前端之家收集整理的这篇文章主要介绍了RegexQuery正则表达式源代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
package query; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.Hits; import org.apache.lucene.search.IndexSearcher; public class RegexQuery { public static void main(String[] args) { // TODO 自动生成方法存根 IndexWriter writer = new IndexWriter(INDEX_STORE_PATH,new StandardAnalyzer(),true); writer.setUseCompoundFile(false); //创建8个文档 Document doc1 = new Document(); Document doc2 = new Document(); Document doc3 = new Document(); Field f1 = new Field("content","word",Field.Store.YES,Field.Index.TOKENIZED); Field f2 = new Field("content","work",Field.Index.TOKENIZED); Field f3 = new Field("content","world",Field.Index.TOKENIZED); doc1.add(f1); doc2.add(f2); doc3.add(f3); writer.addDocument(doc1); writer.addDocument(doc2); writer.addDocument(doc3); writer.close(); IndexSearcher searcher = new IndexSearcher(INDEX_STORE_PATH); //构建1个个正则表达式,用于匹配所有域名abc.com的地址 String regex = "http://[a-z]{1,3}\\.abc\\.com/.*"; //构成term Term t = new Term("url",regex); //创建正则查询 RegexQuery query = new RegexQuery(t); //打印查询结果 Hits hits = searcher.search(query); for(int i = 0; i < hits.length(); i++){ System.out.println(hits.doc(i)); } } }

猜你在找的正则表达式相关文章