Lucene:基于Java的全文检索引擎简介

<!--[if !supportLists]-->5.   <!--[endif]-->Lucene代码分析
应用情景分析
 
Query query = parser.parse(queries[j]);
 获得布尔查询
 
hits = searcher.search(query);
 
 
 return new Hits(this, query, filter);
 
  getMoreDocs(50)
 
    TopDocs topDocs = searcher.search(query, filter, n)
 
      IndexSearcher:public TopDocs search(Query query, Filter filter, final int nDocs)

<!--[if !supportLists]-->²         <!--[endif]-->IndexSearcher 开始时已经打开了该目录

<!--[if !supportLists]-->²         <!--[endif]-->IndexSearcher 中初始化了IndexReader

<!--[if !supportLists]-->²         <!--[endif]-->IndexReader中读取了SegmentInfos

<!--[if !supportLists]-->²         <!--[endif]-->IndexReader = SegmentReader

<!--[if !supportLists]-->²         <!--[endif]-->SegmentReader ::initialize(SegmentInfo si)

<!--[if !supportLists]-->n          <!--[endif]-->1。读入域信息,只有域的名字

<!--[if !supportLists]-->n          <!--[endif]-->2. 打开保存域、保存域索引的文件
 
       Scorer scorer = query.weight(this).scorer(reader)

<!--[if !supportLists]-->u        <!--[endif]-->这里query = PhraseQuery

<!--[if !supportLists]-->u        <!--[endif]-->query.weight(this) 获得PhraseWeight(IndexSearcher)

<!--[if !supportLists]-->u        <!--[endif]-->PhraseWeight::scorer(IndexReader reader)

<!--[if !supportLists]-->u        <!--[endif]-->PhraseQuery::TermPositions p = reader.termPositions((Term)terms.elementAt(i));

<!--[if !supportLists]-->u        <!--[endif]-->public TermPositions termPositions(Term term) throws IOException {

IndexReader::TermPositions termPositions = termPositions();

SegmentTermDocs::SegmentTermDocs(SegmentReader parent)

          throws IOException {

    this.parent = parent;

    this.freqStream = (InputStream) parent.freqStream.clone();//频率文件
    this.deletedDocs = parent.deletedDocs;

    this.skipInterval = parent.tis.getSkipInterval();

  }

SegmentTermPositions::SegmentTermPositions(SegmentReader p) throws IOException {

    super(p);

    this.proxStream = (InputStream)parent.proxStream.clone();//位置文件

  }
 

IndexReader  = SegmentReader, IndexSearcher
termPositions.seek(term);

 
SegmentTermDocs::public void seek(Term term) throws IOException {

TermInfo ti = parent.tis.get(term);// parent =SegmentReader

// tis =TermInfosReader

// 在初始化SegmentTermDocs的时候读取文件并创建了

//  tis = new TermInfosReader(cfsDir, segment, fieldInfos);
/**

   * 1。从.tis文件中读取相关的信息 到 项的迭代对象

   * 2。得到项的迭代对象

   * 3。该项读取器 的 size = 该项迭代对象的 size

   * 4。读取索引,初始化了 索引指针,索引

   * */
    seek(ti);

  }
 

 
 
return termPositions;

<!--[if !supportLists]-->²         <!--[endif]-->SegmentReader. termPositions()::return SegmentTermPositions(this)`
 
 
 
 
<p>一个权重由query创建,并给查询器({@link Query#createWeight(Searcher)})使用,方法 {@link #sumOfSquaredWeights()},然后被最高级的查询api调用

用来计算查询规范化因子 (@link Similarity#queryNorm(float)}),然后该因子传给{@link #normalize(float)} 然后被{@link #scorer(IndexReader)}调用
 

 

你可能感兴趣的:(java,filter,Lucene,query,全文检索,代码分析)