lucene2 0中主要類的介紹

2021-04-18 18:59:22 字數 3843 閱讀 9460

document 類中一些方法:  public final void add(field field)  新增field  public final void removefield(string name)     刪除乙個field  public final void removefields(string name) 刪除多個field  public final field getfield(string name) 根據乙個名字獲得field的例項  public final string get(string name) 取出field的值,也就是資料來源的值  public final enumeration fields() 得到乙個所有field的列舉  public final field getfields(string name) 根據名稱得到乙個field的陣列  public final string getvalues(string name) 根據名稱得到乙個feild的值的陣列

field類  構造方法:5個   field(string name, byte value, field.store store)   field(string name, reader reader)   field(string name, reader reader, field.termvector termvector)   field (string name, string value, field.store store, field.index index)   field (string name, string value, field.store store, field.index index, field.termvector termvector)   name引數:field的名稱。為field新增值的具體方式3種:字串,reader和二進位制byte傳入。   termvector屬性是用語表明對field的詞條向量如何進行儲存。      indexwriter類  構造方法:3個   indexwriter(string path,analyzer a,boolean create)   indexwriter(file f,analyzer a,boolean create)   indexwriter(directory d,analyzer a,boolean create)   第乙個引數是要索引建立在哪個目錄裡           第二個引數是新建乙個文字分析器,這裡用的是標準的大家也可以自己寫乙個           第三個引數是否刪除已有的索引  方法:public void adddocument(document doc)    public void adddocument(document doc,analyzer analyzer)    public void setmaxfieldlength(int maxfieldlength)    indexsearcher類  構造方法:indexsearcher(string path)      indexsearcher(directory directory)    indexsearcher(indexreader r)   方法:seach(query query)    seach(query query,sort sort)    void close()    int docfreq(term term) throws ioexception  -計算索引中包含有指定乙個term資訊的文件量    int docfreq(term term) throws ioexception -計算索引中有多少文件包含指定一組term資訊    int maxdoc() throws ioexception 返回索引中最大可能具有的document的數量(再加1)    document doc(int i) throws ioexception 取出索引中id號為i的文件    query rewrite(query query) throws ioexception  對查詢進行rewrite,使之成為原子查詢  query類:表示乙個查詢請求 hits:表示查詢結果。  方法:public final int length()    public fianl document doc(int n) throws ioexcepiton 取得當前結果集中第n個document    public fianl float score(int n) throws ioexcepiton  取得當前結果集中第n個document的得分    public fianl int id(int n) throws ioexcepiton  取得當前結果集中第n個document的索引內部id值    public iterator iterator()   取得對hits集合 的遍歷物件 filter:表示對索引中文件集合的過濾器 sort:對索引的結果進行排序的工具 hitcollector:對檢索結果進行選擇的乙個工具,並將選擇後的結果儲存在其中 weight:就是『權重』,表示一次查詢時,索引中的某個文件的重要性 termquery詞條搜尋  public termquery(term) booleanquery 布林搜尋 -就是乙個由多個字句和字句的布林邏輯所組成的查詢。  例:term t1 =new term("bookname","女"); term t2 =new term("bookname","狗");     termquery q1=new termquery(t1);    termquery q2=new termquery(t2);     booleanquery query=new booleanquery();     query.add(q1,booleanclause.occur.must);     query.add(q2,booleanclause.occur.must);

booleanclause.occur 類只要有3種表示:   booleanclause.occur.must、booleanclause.occur.must_not 和booleanclause.occur.should   rangequery 範圍搜尋  例:term begin =new term("booknumber","0001");term end =new term("booknumber","0005");   rangequery query=new rangequery(begin,end,false);    prefixquery 字首搜尋  例:term prefix =new term("booknumber","剛");   prefixquery query =new prefixquery(prefix); phrasequery 短語搜尋  例: phrasequery query=new phrasequery();   query.add(new term("bookname","鋼"));   query.add(new term("bookname","鐵"));   query.setslop(1); multiphrasequery 多短語搜尋  例:multiphrasequery query=new multiphrasequery();     query.add(new term("bookname","鋼"));-字首     term t1 =new term("bookname","鐵");-字尾     term t2 =new term("bookname","和");-字尾     term t3 =new term("bookname","要");-字尾     query.add(new term)

fuzzyquery 模糊搜尋  構造方法:   public fuzzyquery(term term,flot minimumsimilarity) throws illegalargumentexception   public fuzzyquery(term term,flot minimumsimilarity,int prefixlength) throws illegalargumentexception   minimumsimilarity:相似度   prefixlength:字首匹配個數  例:term t=new term("content","work");   fuzzyquery query = new fuzzyquery(t,0.1f,1);

Lucene2 0與lucene1 4的比較

前陣子說看了ajax lucene之後就寫讀後的體會的,但是事情多,一直拖到了現在。簡單就寫一點2.0與1.4之間最常用的地方的改變 1.4中doc.add field.text 之類的寫法,是往document中加feild的時候,直接呼叫filed的static方法 由以下幾種 field.te...

Lucene搜尋引擎API的主要類介紹

lucene搜尋的api的類主要有4個 indexsearcher query 包括子類 queryparser,hits 一 indexsearcher是搜尋的入口,他的search方法提供了搜尋功能 最普通的termquery termquery最普通,用term t new term cont...

Lucene的Query類介紹

把lucene的查詢當成sql的查詢,也許會籠統的明白些query的真相了。查詢分為大致兩類,1 精準查詢。2,模糊查詢。建立測試資料。private directory directory private indexreader reader private string ids private ...