• Lucene的基本用法


    创建lucene索引

    View Code
     1 //1. path
     2 string indexPath=@"/ui/index/";
     3 
     4 //2. StandarAnalyzer
     5 Lucene.Net.Analysis.Standard.StandarAnalyzer sa=new StandarAnalyzer();
     6 
     7 //3. IndexWriter
     8 IndexWriter iw=new IndexWriter(mapPath(indexPath),sa,true);
     9 
    10 //4. Document
    11 Document doc=new Document();
    12 
    13 //5. Field 
    14 Field f=newFiled("id",val,Field.Store.Yes,field.index.UN_TOKENIZED);
    15 
    16 doc.Add(f);
    17 iw.addDocument(doc);

    读取lucene索引数据

    View Code
    1. //Path,IndexReader,field_key
    IndexReader reader=IndexReader.Open(MapPath(indexPath);
    string field="id";
    // Searcher
    2.Search se=new IndexSearcher(reader);
    
    //Analyzer 
    3.Analyzer an=new StandarAnalyzer();
    
    //QueryParser
    4.QueryParser  p=new QueryParser(field,an);
                             p2=new QueryParser(field2,an);
    
    //BooleanQuery
    5.BooleanQuery b=new BooleanQuery();
    //Query Term
        //Term t=new Term("id",filed);
          q=new WildcardQuery(t);
         Query q=p.parse(filed);
                q2=p2.parse(filed2);
    b.add(q,booleanClause.Occur.Must/Should);
    
    
    //Hit
    6. Hits myhit=se.search(b);
    for循环{
    Docment doc=myHit.Doc(i);
    doc.Get("id").tostring();
    }
  • 相关阅读:
    错误提示窗口-“操作系统当前的配置不能运行此应用程序”
    打印机无法打印的10种解决方法
    开发进度三
    人月神话阅读笔记二
    开发进度二
    开发进度1
    人月神话阅读笔记一
    库存物资管理系统
    四则运算
    动手动脑5
  • 原文地址:https://www.cnblogs.com/ruanyifeng/p/2590335.html
Copyright © 2020-2023  润新知