📄 indexreader.h
字号:
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
*
* Distributable under the terms of either the Apache License (Version 2.0) or
* the GNU Lesser General Public License, as specified in the COPYING file.
------------------------------------------------------------------------------*/
#ifndef _lucene_index_IndexReader_
#define _lucene_index_IndexReader_
#if defined(_LUCENE_PRAGMA_ONCE)
# pragma once
#endif
#include "CLucene/store/Directory.h"
#include "CLucene/store/FSDirectory.h"
#include "CLucene/store/Lock.h"
#include "CLucene/document/Document.h"
#include "CLucene/index/TermVector.h"
#include "SegmentInfos.h"
#include "Terms.h"
CL_NS_DEF(index)
/** IndexReader is an abstract class, providing an interface for accessing an
index. Search of an index is done entirely through this abstract interface,
so that any subclass which implements it is searchable.
<p> Concrete subclasses of IndexReader are usually constructed with a call to
the static method {@link #open}.
<p> For efficiency, in this API documents are often referred to via
<i>document numbers</i>, non-negative integers which each name a unique
document in the index. These document numbers are ephemeral--they may change
as documents are added to and deleted from an index. Clients should thus not
rely on a given document having the same number between sessions.
*/
class IndexReader :LUCENE_BASE{
public:
//Callback for classes that need to know if IndexReader is closing.
typedef void (*CloseCallback)(IndexReader*, void*);
class CloseCallbackCompare:public CL_NS(util)::Compare::_base{
public:
bool operator()( CloseCallback t1, CloseCallback t2 ) const{
return t1 > t2;
}
static void doDelete(CloseCallback dummy){
}
};
private:
CL_NS(store)::LuceneLock* writeLock;
bool directoryOwner;
bool stale;
bool hasChanges;
bool closeDirectory;
CL_NS(store)::Directory* directory;
typedef CL_NS(util)::CLSet<CloseCallback, void*,
CloseCallbackCompare,
CloseCallbackCompare> CloseCallbackMap;
CloseCallbackMap closeCallbacks;
/**
* Trys to acquire the WriteLock on this directory.
* this method is only valid if this IndexReader is directory owner.
*
* @throws IOException If WriteLock cannot be acquired.
*/
void aquireWriteLock();
protected:
/**
* Constructor used if IndexReader is not owner of its directory.
* This is used for IndexReaders that are used within other IndexReaders that take care or locking directories.
*
* @param directory Directory where IndexReader files reside.
*/
IndexReader(CL_NS(store)::Directory* dir);
/**
* Constructor used if IndexReader is owner of its directory.
* If IndexReader is owner of its directory, it locks its directory in case of write operations.
*
* @param directory Directory where IndexReader files reside.
* @param segmentInfos Used for write-l
* @param closeDirectory
*/
IndexReader(CL_NS(store)::Directory* directory, SegmentInfos* segmentInfos, bool closeDirectory);
/// Implements close.
virtual void doClose() = 0;
/** Implements setNorm in subclass.*/
virtual void doSetNorm(int32_t doc, const TCHAR* field, uint8_t value) = 0;
/** Implements actual undeleteAll() in subclass. */
virtual void doUndeleteAll() = 0;
/** Implements deletion of the document numbered <code>docNum</code>.
* Applications should call {@link #delete(int32_t)} or {@link #delete(Term)}.
*/
virtual void doDelete(const int32_t docNum) = 0;
public:
DEFINE_MUTEX(THIS_LOCK)
///Do not access this directly, only public so that MultiReader can access it
virtual void commit();
/** Undeletes all documents currently marked as deleted in this index.*/
void undeleteAll();
/**
* Returns a list of all unique field names that exist in the index pointed
* to by this IndexReader.
* @memory All memory must be cleaned by caller
* @return Collection of Strings indicating the names of the fields
* @throws IOException if there is a problem with accessing the index
*/
virtual TCHAR** getFieldNames() = 0;
/**
* Returns a list of all unique field names that exist in the index pointed
* to by this IndexReader. The boolean argument specifies whether the fields
* returned are indexed or not.
* @memory All memory must be cleaned by caller
* @param indexed <code>true</code> if only indexed fields should be returned;
* <code>false</code> if only unindexed fields should be returned.
* @return Collection of Strings indicating the names of the fields
* @throws IOException if there is a problem with accessing the index
*/
virtual TCHAR** getFieldNames(bool indexed) = 0;
/**
*
* @memory All memory must be cleaned by caller
* @param storedTermVector if true, returns only Indexed fields that have term vector info,
* else only indexed fields without term vector info
* @return Collection of Strings indicating the names of the fields
*/
virtual TCHAR** getIndexedFieldNames(bool storedTermVector) = 0;
/** Returns the byte-encoded normalization factor for the named field of
* every document. This is used by the search code to score documents.
*
* The number of bytes returned is the size of the IndexReader->maxDoc()
* MEMORY: The values are cached, so don't delete the returned byte array.
* @see Field#setBoost(float_t)
*/
virtual uint8_t* norms(const TCHAR* field) = 0;
/** Reads the byte-encoded normalization factor for the named field of every
* document. This is used by the search code to score documents.
*
* @see Field#setBoost(float_t)
*/
virtual void norms(const TCHAR* field, uint8_t* bytes) = 0;
/** Expert: Resets the normalization factor for the named field of the named
* document.
*
* @see #norms(String)
* @see Similarity#decodeNorm(byte)
*/
void setNorm(int32_t doc, const TCHAR* field, float_t value);
/** Expert: Resets the normalization factor for the named field of the named
* document. The norm represents the product of the field's {@link
* Field#setBoost(float_t) boost} and its {@link Similarity#lengthNorm(String,
* int32_t) length normalization}. Thus, to preserve the length normalization
* values when resetting this, one should base the new value upon the old.
*
* @see #norms(String)
* @see Similarity#decodeNorm(byte)
*/
void setNorm(int32_t doc, const TCHAR* field, uint8_t value);
/// Release the write lock, if needed.
virtual ~IndexReader();
/// Returns an IndexReader reading the index in an FSDirectory in the named path.
static IndexReader* open(const char* path);
/// Returns an IndexReader reading the index in the given Directory.
static IndexReader* open( CL_NS(store)::Directory* directory, bool closeDirectory=false);
/**
* Returns the time the index in the named directory was last modified.
*
* <p>Synchronization of IndexReader and IndexWriter instances is
* no longer done via time stamps of the segments file since the time resolution
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -