searchengine/oss/cl/clucene/src/clucene/search/indexsearcher.cpp
changeset 18 3e1f76dd2722
parent 15 cf5c74390b98
child 21 2c484ac32ef0
equal deleted inserted replaced
15:cf5c74390b98 18:3e1f76dd2722
    15 #include "clucene/index/indexreader.h"
    15 #include "clucene/index/indexreader.h"
    16 #include "clucene/index/term.h"
    16 #include "clucene/index/term.h"
    17 #include "clucene/util/bitset.h"
    17 #include "clucene/util/bitset.h"
    18 #include "fieldsortedhitqueue.h"
    18 #include "fieldsortedhitqueue.h"
    19 //#ifdef USE_HIGHLIGHTER 
    19 //#ifdef USE_HIGHLIGHTER 
    20 //#include "CLucene/highlighter/QueryTermExtractor.h"
    20 #include "CLucene/highlighter/QueryTermExtractor.h"
    21 //#include "CLucene/highlighter/QueryScorer.h"
    21 #include "CLucene/highlighter/QueryScorer.h"
    22 //#include "CLucene/highlighter/Highlighter.h"
    22 #include "CLucene/highlighter/Highlighter.h"
    23 //#include "CLucene/highlighter/SimpleHTMLFormatter.h"
    23 #include "CLucene/highlighter/SimpleHTMLFormatter.h"
    24 //#include "CLucene/analysis/standard/StandardAnalyzer.h"
    24 #include "CLucene/analysis/standard/StandardAnalyzer.h"
    25 //#include "CLucene/queryParser/QueryParser.h"
    25 #include "CLucene/queryParser/QueryParser.h"
    26 //#endif
    26 //#endif
    27 CL_NS_USE(index)
    27 CL_NS_USE(index)
    28 CL_NS_USE(util)
    28 CL_NS_USE(util)
    29 CL_NS_USE(document)
    29 CL_NS_USE(document)
    30 
    30 
   118       CND_PRECONDITION(path != NULL, "path is NULL");
   118       CND_PRECONDITION(path != NULL, "path is NULL");
   119 
   119 
   120       reader = IndexReader::open(path);
   120       reader = IndexReader::open(path);
   121       readerOwner = true;
   121       readerOwner = true;
   122 //#ifdef USE_HIGHLIGHTER
   122 //#ifdef USE_HIGHLIGHTER
   123 //      rewrittenQuery = NULL;
   123       fistlnHLQuery = NULL;
       
   124       excerptrwQuery = NULL;
   124 //#endif      
   125 //#endif      
   125      
   126      
   126   }
   127   }
   127   
   128   
   128   IndexSearcher::IndexSearcher(CL_NS(store)::Directory* directory){
   129   IndexSearcher::IndexSearcher(CL_NS(store)::Directory* directory){
   134       CND_PRECONDITION(directory != NULL, "directory is NULL");
   135       CND_PRECONDITION(directory != NULL, "directory is NULL");
   135 
   136 
   136       reader = IndexReader::open(directory);
   137       reader = IndexReader::open(directory);
   137       readerOwner = true;
   138       readerOwner = true;
   138 //#ifdef USE_HIGHLIGHTER
   139 //#ifdef USE_HIGHLIGHTER
   139 //      rewrittenQuery = NULL;
   140       fistlnHLQuery = NULL;
       
   141       excerptrwQuery = NULL;
   140 //#endif      
   142 //#endif      
   141       
   143       
   142   }
   144   }
   143 
   145 
   144   IndexSearcher::IndexSearcher(IndexReader* r){
   146   IndexSearcher::IndexSearcher(IndexReader* r){
   148   //Post - The instance has been created
   150   //Post - The instance has been created
   149 
   151 
   150       reader      = r;
   152       reader      = r;
   151       readerOwner = false;
   153       readerOwner = false;
   152 //#ifdef USE_HIGHLIGHTER
   154 //#ifdef USE_HIGHLIGHTER
   153 //      rewrittenQuery = NULL;
   155       fistlnHLQuery = NULL;
       
   156       excerptrwQuery = NULL;
   154 //#endif     
   157 //#endif     
   155   }
   158   }
   156 
   159 
   157   IndexSearcher::~IndexSearcher(){
   160   IndexSearcher::~IndexSearcher(){
   158   //Func - Destructor
   161   //Func - Destructor
   216 
   219 
   217   TopDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs){
   220   TopDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs){
   218   //Func -
   221   //Func -
   219   //Pre  - reader != NULL
   222   //Pre  - reader != NULL
   220   //Post -
   223   //Post -
   221 //#ifdef USE_HIGHLIGHTER
       
   222 //      if(!rewrittenQuery)
       
   223 //         {
       
   224 //         rewrittenQuery = query->rewrite(reader);        
       
   225 //         }          
       
   226 //#endif        
       
   227           
       
   228       CND_PRECONDITION(reader != NULL, "reader is NULL");
   224       CND_PRECONDITION(reader != NULL, "reader is NULL");
   229       CND_PRECONDITION(query != NULL, "query is NULL");
   225       CND_PRECONDITION(query != NULL, "query is NULL");
       
   226 //#ifdef USE_HIGHLIGHTER     
       
   227 	if(!excerptrwQuery || !fistlnHLQuery)
       
   228 		{                          
       
   229   			excerptrwQuery = query->rewrite(reader); 
       
   230   		}           
       
   231 //#endif 
   230 
   232 
   231 	  Weight* weight = query->weight(this);
   233 	  Weight* weight = query->weight(this);
   232       Scorer* scorer = weight->scorer(reader);
   234       Scorer* scorer = weight->scorer(reader);
   233 	  if (scorer == NULL){
   235 	  if (scorer == NULL){
   234           return _CLNEW TopDocs(0, NULL, 0);
   236           return _CLNEW TopDocs(0, NULL, 0);
   269   }
   271   }
   270 
   272 
   271   // inherit javadoc
   273   // inherit javadoc
   272   TopFieldDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs,
   274   TopFieldDocs* IndexSearcher::_search(Query* query, Filter* filter, const int32_t nDocs,
   273          const Sort* sort) {
   275          const Sort* sort) {
   274 //#ifdef USE_HIGHLIGHTER
   276 
   275 //      if(!rewrittenQuery)
   277 
   276 //         {
       
   277 //         rewrittenQuery = query->rewrite(reader);        
       
   278 //         }          
       
   279 //#endif  
       
   280       CND_PRECONDITION(reader != NULL, "reader is NULL");
   278       CND_PRECONDITION(reader != NULL, "reader is NULL");
   281       CND_PRECONDITION(query != NULL, "query is NULL");
   279       CND_PRECONDITION(query != NULL, "query is NULL");
       
   280 
       
   281 //#ifdef USE_HIGHLIGHTER     
       
   282 	if(!excerptrwQuery || !fistlnHLQuery)
       
   283 		{                          
       
   284   			excerptrwQuery = query->rewrite(reader); 
       
   285   		}           
       
   286 //#endif
   282 
   287 
   283     Weight* weight = query->weight(this);
   288     Weight* weight = query->weight(this);
   284     Scorer* scorer = weight->scorer(reader);
   289     Scorer* scorer = weight->scorer(reader);
   285     if (scorer == NULL){
   290     if (scorer == NULL){
   286 		return _CLNEW TopFieldDocs(0, NULL, 0, NULL );
   291 		return _CLNEW TopFieldDocs(0, NULL, 0, NULL );
   322   //       as it skips non-high-scoring hits.
   327   //       as it skips non-high-scoring hits.
   323   //Pre  - query is a valid reference to a query
   328   //Pre  - query is a valid reference to a query
   324   //       filter may or may not be NULL
   329   //       filter may or may not be NULL
   325   //       results is a valid reference to a HitCollector and used to store the results
   330   //       results is a valid reference to a HitCollector and used to store the results
   326   //Post - filter if non-NULL, a bitset used to eliminate some documents
   331   //Post - filter if non-NULL, a bitset used to eliminate some documents
   327 //#ifdef USE_HIGHLIGHTER      
   332      
   328 //      if(!rewrittenQuery)
       
   329 //         {
       
   330 //         rewrittenQuery = query->rewrite(reader);        
       
   331 //         } 
       
   332 //#endif      
       
   333       CND_PRECONDITION(reader != NULL, "reader is NULL");
   333       CND_PRECONDITION(reader != NULL, "reader is NULL");
   334       CND_PRECONDITION(query != NULL, "query is NULL");
   334       CND_PRECONDITION(query != NULL, "query is NULL");
       
   335      
       
   336 //#ifdef USE_HIGHLIGHTER     
       
   337 	if(!excerptrwQuery || !fistlnHLQuery)
       
   338 		{                          
       
   339   			excerptrwQuery = query->rewrite(reader); 
       
   340   		}           
       
   341 //#endif
       
   342 
   335 
   343 
   336       BitSet* bits = NULL;
   344       BitSet* bits = NULL;
   337       SimpleFilteredCollector* fc = NULL; 
   345       SimpleFilteredCollector* fc = NULL; 
   338 
   346 
   339       if (filter != NULL){
   347       if (filter != NULL){
   371 			last = query;
   379 			last = query;
   372         }
   380         }
   373         return query;
   381         return query;
   374     }
   382     }
   375 //#ifdef USE_HIGHLIGHTER
   383 //#ifdef USE_HIGHLIGHTER
   376 //Query* IndexSearcher::getrewritten(int32_t n, Query* original) 
   384 void IndexSearcher::getrewritten(int32_t n, Query* original, Query* rwQuery[]) 
   377 //          {
   385           {
   378 //        if(!rewrittenQuery)
   386             rwQuery[0] = fistlnHLQuery;
   379 //           {
   387             rwQuery[1] = excerptrwQuery;
   380 //           rewrittenQuery = original->rewrite(reader);        
   388           }
   381 //           }
       
   382 //          return rewrittenQuery;
       
   383 //          }
       
   384 //#endif
   389 //#endif
   385     void IndexSearcher::explain(Query* query, int32_t doc, Explanation* ret){
   390     void IndexSearcher::explain(Query* query, int32_t doc, Explanation* ret){
   386         Weight* weight = query->weight(this);
   391         Weight* weight = query->weight(this);
   387         weight->explain(reader, doc, ret);
   392         weight->explain(reader, doc, ret);
   388 
   393