Lucene使用正则表达式查询
2010-06-22 16:40
316 查看
//导入类包import org.apache.lucene.search.regex.*; public static void regexQuery(String path) throws IOException { IndexWriter writer = new IndexWriter(path, new StandardAnalyzer(), true); writer.setUseCompoundFile(false); Document doc1 = new Document(); Document doc2 = new Document(); Document doc3 = new Document(); Field f1 = new Field("url", "http://www.abc.com/product?typeid=1&category=10&item=34", Field.Store.YES, Field.Index.TOKENIZED); Field f2 = new Field("url", "http://www.def.com/product/show?typeid=3&catagory=10&item=23", Field.Store.YES, Field.Index.TOKENIZED); Field f3 = new Field( "url", "http://www.ghi.com/product/list?catagory=4&typeid=19&order=32", Field.Store.YES, 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(path); // 创建一个正则表达式,用于匹配域名为abc.com的地址 String regex = "http://[a-z]{1,3}\.abc\.com/.*"; Term t = new Term("url", regex); RegexQuery query = new RegexQuery(t); Query q = new TermQuery(new Term("url", "http")); Hits hits = searcher.search(query); for (int i = 0; i < hits.length(); i++) { System.out.println(hits.doc(i)); } searcher.close(); }
相关文章推荐
- Oracle SQL使用笛卡尔连接、正则表达式和层次查询、union all、unpiovt 解决多列值筛选、列转行问题
- mysql 使用正则表达式查询
- [sqlite3]_[初级]_[使用正则表达式REGEXP查询]
- Oracle中使用正则表达式过滤查询结果
- mysql中使用正则表达式查询
- Oracle SQL多行字符串拆分使用层次查询(connect by)、正则表达式
- mysql中使用正则表达式查询
- mysql中如何使用正则表达式查询
- MySQL中使用正则表达式查询
- 使用正则表达式获取Sql查询语句各项(表名、字段、条件、排序)
- MySql中使用正则表达式查询的方法
- Lucene正则表达式查询RegenxQuery
- SQL模糊查询及扩展正则表达式的使用
- vs 查询 替换 正则表达式使用
- mysql中如何使用正则表达式查询
- Java源码-使用正则表达式查询匹配记录
- mysql中如何使用正则表达式查询
- 使用MySQL正则表达式查询
- T_SQL中使用正则表达式匹配查询结果
- Eclipse中的查询支持使用正则表达式