📄 searchheader.h
字号:
*/
virtual void _search(Query* query, Filter* filter, HitCollector* results) = 0;
/** Frees resources associated with this Searcher.
* Be careful not to call this method while you are still using objects
* like {@link Hits}.
*/
virtual void close() = 0;
/** Expert: Returns the number of documents containing <code>term</code>.
* Called by search code to compute term weights.
* @see IndexReader#docFreq(Term).
*/
virtual int32_t docFreq(const CL_NS(index)::Term* term) const = 0;
/** Expert: Returns one greater than the largest possible document number.
* Called by search code to compute term weights.
* @see IndexReader#maxDoc().
*/
virtual int32_t maxDoc() const = 0;
/** Expert: Low-level search implementation. Finds the top <code>n</code>
* hits for <code>query</code>, applying <code>filter</code> if non-null.
*
* <p>Called by {@link Hits}.
*
* <p>Applications should usually call {@link Searcher#search(Query)} or
* {@link Searcher#search(Query,Filter)} instead.
*/
virtual TopDocs* _search(Query* query, Filter* filter, const int32_t n) = 0;
/** Expert: Returns the stored fields of document <code>i</code>.
* Called by {@link HitCollector} implementations.
* @see IndexReader#document(int32_t).
*/
virtual CL_NS(document)::Document* doc(const int32_t i) = 0;
/** Expert: called to re-write queries into primitive queries. */
virtual Query* rewrite(Query* query) = 0;
/** Returns an Explanation that describes how <code>doc</code> scored against
* <code>query</code>.
*
* <p>This is intended to be used in developing Similarity implementations,
* and, for good performance, should not be displayed with every hit.
* Computing an explanation is as expensive as executing the query over the
* entire index.
*/
virtual Explanation* explain(Query* query, int32_t doc) = 0;
/** Expert: Low-level search implementation with arbitrary sorting. Finds
* the top <code>n</code> hits for <code>query</code>, applying
* <code>filter</code> if non-null, and sorting the hits by the criteria in
* <code>sort</code>.
*
* <p>Applications should usually call {@link
* Searcher#search(Query,Filter,Sort)} instead.
*/
virtual TopFieldDocs* _search(Query* query, Filter* filter, const int32_t n, const Sort* sort) = 0;
};
/** An abstract base class for search implementations.
* Implements some common utility methods.
*/
class Searcher:public Searchable {
private:
/** The Similarity implementation used by this searcher. */
Similarity* similarity;
public:
Searcher(){
similarity = Similarity::getDefault();
}
virtual ~Searcher(){
}
// Returns the documents matching <code>query</code>.
Hits* search(Query* query) {
return search(query, (Filter*)NULL );
}
// Returns the documents matching <code>query</code> and
// <code>filter</code>.
Hits* search(Query* query, Filter* filter) {
return _CLNEW Hits(this, query, filter);
}
/** Returns documents matching <code>query</code> sorted by
* <code>sort</code>.
*/
Hits* search(Query* query, const Sort* sort){
return _CLNEW Hits(this, query, NULL, sort);
}
/** Returns documents matching <code>query</code> and <code>filter</code>,
* sorted by <code>sort</code>.
*/
Hits* search(Query* query, Filter* filter, const Sort* sort){
return _CLNEW Hits(this, query, filter, sort);
}
/** Lower-level search API.
*
* <p>{@link HitCollector#collect(int32_t ,float_t)} is called for every non-zero
* scoring document.
*
* <p>Applications should only use this if they need <i>all</i> of the
* matching documents. The high-level search API ({@link
* Searcher#search(Query)}) is usually more efficient, as it skips
* non-high-scoring hits.
* <p>Note: The <code>score</code> passed to this method is a raw score.
* In other words, the score will not necessarily be a float whose value is
* between 0 and 1.
*/
void _search(Query* query, HitCollector* results) {
Searchable::_search(query, NULL, results);
}
/** Expert: Set the Similarity implementation used by this Searcher.
*
* @see Similarity#setDefault(Similarity)
*/
void setSimilarity(Similarity* similarity) {
this->similarity = similarity;
}
/** Expert: Return the Similarity implementation used by this Searcher.
*
* <p>This defaults to the current value of {@link Similarity#getDefault()}.
*/
Similarity* getSimilarity(){
return this->similarity;
}
};
/** The abstract base class for queries.
<p>Instantiable subclasses are:
<ul>
<li> {@link TermQuery}
<li> {@link MultiTermQuery}
<li> {@link BooleanQuery}
<li> {@link WildcardQuery}
<li> {@link PhraseQuery}
<li> {@link PrefixQuery}
<li> {@link PhrasePrefixQuery}
<li> {@link FuzzyQuery}
<li> {@link RangeQuery}
<li> {@link spans.SpanQuery}
</ul>
<p>A parser for queries is contained in:
<ul>
<li>{@link queryParser.QueryParser QueryParser}
</ul>
*/
class Query :LUCENE_BASE {
private:
// query boost factor
float_t boost;
protected:
Query(const Query& clone);
public:
Query();
virtual ~Query();
/** Sets the boost for this query clause to <code>b</code>. Documents
* matching this clause will (in addition to the normal weightings) have
* their score multiplied by <code>b</code>.
*/
void setBoost(float_t b);
/** Gets the boost for this clause. Documents matching
* this clause will (in addition to the normal weightings) have their score
* multiplied by <code>b</code>. The boost is 1.0 by default.
*/
float_t getBoost() const;
/** Expert: Constructs an appropriate Weight implementation for this query.
*
* <p>Only implemented by primitive queries, which re-write to themselves.
* <i>Internal, should be protected</i>
*
* todo: this should actually be protected...
*/
virtual Weight* createWeight(Searcher* searcher);
/** Expert: Constructs an initializes a Weight for a top-level query. */
Weight* weight(Searcher* searcher);
/** Expert: called to re-write queries into primitive queries. */
virtual Query* rewrite(CL_NS(index)::IndexReader* reader);
/** Expert: called when re-writing queries under MultiSearcher.
*
* <p>Only implemented by derived queries, with no
* {@link #createWeight(Searcher)} implementatation.
*/
virtual Query* combine(Query** queries);
/** Expert: merges the clauses of a set of BooleanQuery's into a single
* BooleanQuery.
*
*<p>A utility for use by {@link #combine(Query[])} implementations.
*/
static Query* mergeBooleanQueries(Query** queries);
/** Expert: Returns the Similarity implementation to be used for this query.
* Subclasses may override this method to specify their own Similarity
* implementation, perhaps one that delegates through that of the Searcher.
* By default the Searcher's Similarity implementation is returned.*/
Similarity* getSimilarity(Searcher* searcher);
/** Returns a clone of this query. */
virtual Query* clone() const = 0;
virtual const TCHAR* getQueryName() const = 0;
bool instanceOf(const TCHAR* other) const;
/** Prints a query to a string, with <code>field</code> as the default field
* for terms. <p>The representation used is one that is readable by
* {@link queryParser.QueryParser QueryParser}
* (although, if the query was created by the parser, the printed
* representation may not be exactly what was parsed).
*/
virtual TCHAR* toString(const TCHAR* field) const = 0;
virtual bool equals(Query* other) const = 0;
virtual size_t hashCode() const = 0;
/** Prints a query to a string. */
TCHAR* toString() const;
};
CL_NS_END
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -