searchengine/oss/cl/clucene/src/clucene/search/multisearcher.h
changeset 0 671dee74050a
child 15 cf5c74390b98
child 24 65456528cac2
equal deleted inserted replaced
-1:000000000000 0:671dee74050a
       
     1 /*------------------------------------------------------------------------------
       
     2 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
       
     3 * 
       
     4 * Distributable under the terms of either the Apache License (Version 2.0) or 
       
     5 * the GNU Lesser General Public License, as specified in the COPYING file.
       
     6 ------------------------------------------------------------------------------*/
       
     7 #ifndef _lucene_search_multisearcher
       
     8 #define _lucene_search_multisearcher
       
     9 
       
    10 #if defined(_LUCENE_PRAGMA_ONCE)
       
    11 # pragma once
       
    12 #endif
       
    13 
       
    14 #include "clucene/search/searchheader.h"
       
    15 #include "clucene/document/document.h"
       
    16 #include "clucene/index/term.h"
       
    17 
       
    18 CL_NS_DEF(search)
       
    19     
       
    20     class MultiHitCollector: public HitCollector{
       
    21     private:
       
    22       HitCollector* results;
       
    23       int32_t start;
       
    24     public: 
       
    25       MultiHitCollector(HitCollector* _results, int32_t _start);
       
    26       void collect(const int32_t doc, const float_t score) ;
       
    27     };
       
    28     
       
    29     
       
    30  /** Implements search over a set of <code>Searchables</code>.
       
    31 	*
       
    32 	* <p>Applications usually need only call the inherited {@link #search(Query)}
       
    33 	* or {@link #search(Query,Filter)} methods.
       
    34 	*/
       
    35 	class MultiSearcher: public Searcher {
       
    36   private:
       
    37     Searchable** searchables;
       
    38 		int32_t searchablesLen;
       
    39     int32_t* starts;
       
    40     int32_t _maxDoc;
       
    41 	protected:
       
    42 		int32_t* getStarts() {
       
    43   			return starts;
       
    44 		}
       
    45 
       
    46   public:
       
    47       /** Creates a searcher which searches <i>Searchables</i>. */
       
    48       MultiSearcher(Searchable** searchables);
       
    49       
       
    50       ~MultiSearcher();
       
    51 
       
    52       /** Frees resources associated with this <code>Searcher</code>. */
       
    53       void close() ;
       
    54 
       
    55 	  int32_t docFreq(const CL_NS(index)::Term* term) const ;
       
    56 
       
    57       /** For use by {@link HitCollector} implementations. */
       
    58 	  bool doc(int32_t n, CL_NS(document)::Document* document);
       
    59 
       
    60       /** For use by {@link HitCollector} implementations to identify the
       
    61        * index of the sub-searcher that a particular hit came from. */
       
    62       int32_t searcherIndex(int32_t n) const;
       
    63 
       
    64 	  int32_t subSearcher(int32_t n) const;
       
    65 
       
    66 	  int32_t subDoc(int32_t n) const;
       
    67 
       
    68       int32_t maxDoc() const;
       
    69     
       
    70       TopDocs* _search(Query* query, Filter* filter, const int32_t nDocs) ;
       
    71       
       
    72       TopFieldDocs* _search (Query* query, Filter* filter, const int32_t n, const Sort* sort);
       
    73      
       
    74       /** Lower-level search API.
       
    75        *
       
    76        * <p>{@link HitCollector#collect(int32_t,float_t)} is called for every non-zero
       
    77        * scoring document.
       
    78        *
       
    79        * <p>Applications should only use this if they need <i>all</i> of the
       
    80        * matching documents.  The high-level search API ({@link
       
    81        * Searcher#search(Query)}) is usually more efficient, as it skips
       
    82        * non-high-scoring hits.
       
    83        *
       
    84        * @param query to match documents
       
    85        * @param filter if non-null, a bitset used to eliminate some documents
       
    86        * @param results to receive hits
       
    87        */
       
    88         void _search(Query* query, Filter* filter, HitCollector* results);
       
    89 
       
    90 		Query* rewrite(Query* original);
       
    91 		void explain(Query* query, int32_t doc, Explanation* ret);
       
    92     };
       
    93 
       
    94 CL_NS_END
       
    95 #endif