searchengine/oss/cl/clucene/src/clucene/search/indexsearcher.cpp
changeset 21 2c484ac32ef0
parent 18 3e1f76dd2722
equal deleted inserted replaced
18:3e1f76dd2722 21:2c484ac32ef0
    14 #include "clucene/document/document.h"
    14 #include "clucene/document/document.h"
    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 
       
    20 #include "CLucene/highlighter/QueryTermExtractor.h"
       
    21 #include "CLucene/highlighter/QueryScorer.h"
       
    22 #include "CLucene/highlighter/Highlighter.h"
       
    23 #include "CLucene/highlighter/SimpleHTMLFormatter.h"
       
    24 #include "CLucene/analysis/standard/StandardAnalyzer.h"
       
    25 #include "CLucene/queryParser/QueryParser.h"
       
    26 //#endif
       
    27 CL_NS_USE(index)
    19 CL_NS_USE(index)
    28 CL_NS_USE(util)
    20 CL_NS_USE(util)
    29 CL_NS_USE(document)
    21 CL_NS_USE(document)
    30 
    22 
    31 CL_NS_DEF(search)
    23 CL_NS_DEF(search)
   117 
   109 
   118       CND_PRECONDITION(path != NULL, "path is NULL");
   110       CND_PRECONDITION(path != NULL, "path is NULL");
   119 
   111 
   120       reader = IndexReader::open(path);
   112       reader = IndexReader::open(path);
   121       readerOwner = true;
   113       readerOwner = true;
   122 //#ifdef USE_HIGHLIGHTER
   114      
   123       fistlnHLQuery = NULL;
       
   124       excerptrwQuery = NULL;
       
   125 //#endif      
       
   126      
   115      
   127   }
   116   }
   128   
   117   
   129   IndexSearcher::IndexSearcher(CL_NS(store)::Directory* directory){
   118   IndexSearcher::IndexSearcher(CL_NS(store)::Directory* directory){
   130   //Func - Constructor
   119   //Func - Constructor
   134 
   123 
   135       CND_PRECONDITION(directory != NULL, "directory is NULL");
   124       CND_PRECONDITION(directory != NULL, "directory is NULL");
   136 
   125 
   137       reader = IndexReader::open(directory);
   126       reader = IndexReader::open(directory);
   138       readerOwner = true;
   127       readerOwner = true;
   139 //#ifdef USE_HIGHLIGHTER
   128      
   140       fistlnHLQuery = NULL;
       
   141       excerptrwQuery = NULL;
       
   142 //#endif      
       
   143       
   129       
   144   }
   130   }
   145 
   131 
   146   IndexSearcher::IndexSearcher(IndexReader* r){
   132   IndexSearcher::IndexSearcher(IndexReader* r){
   147   //Func - Constructor
   133   //Func - Constructor
   149   //Pre  - path != NULL
   135   //Pre  - path != NULL
   150   //Post - The instance has been created
   136   //Post - The instance has been created
   151 
   137 
   152       reader      = r;
   138       reader      = r;
   153       readerOwner = false;
   139       readerOwner = false;
   154 //#ifdef USE_HIGHLIGHTER
   140      
   155       fistlnHLQuery = NULL;
       
   156       excerptrwQuery = NULL;
       
   157 //#endif     
       
   158   }
   141   }
   159 
   142 
   160   IndexSearcher::~IndexSearcher(){
   143   IndexSearcher::~IndexSearcher(){
   161   //Func - Destructor
   144   //Func - Destructor
   162   //Pre  - true
   145   //Pre  - true
   221   //Func -
   204   //Func -
   222   //Pre  - reader != NULL
   205   //Pre  - reader != NULL
   223   //Post -
   206   //Post -
   224       CND_PRECONDITION(reader != NULL, "reader is NULL");
   207       CND_PRECONDITION(reader != NULL, "reader is NULL");
   225       CND_PRECONDITION(query != NULL, "query is NULL");
   208       CND_PRECONDITION(query != NULL, "query is NULL");
   226 //#ifdef USE_HIGHLIGHTER     
   209       
   227 	if(!excerptrwQuery || !fistlnHLQuery)
   210   
   228 		{                          
       
   229   			excerptrwQuery = query->rewrite(reader); 
       
   230   		}           
       
   231 //#endif 
       
   232 
   211 
   233 	  Weight* weight = query->weight(this);
   212 	  Weight* weight = query->weight(this);
   234       Scorer* scorer = weight->scorer(reader);
   213       Scorer* scorer = weight->scorer(reader);
   235 	  if (scorer == NULL){
   214 	  if (scorer == NULL){
   236           return _CLNEW TopDocs(0, NULL, 0);
   215           return _CLNEW TopDocs(0, NULL, 0);
   275          const Sort* sort) {
   254          const Sort* sort) {
   276 
   255 
   277 
   256 
   278       CND_PRECONDITION(reader != NULL, "reader is NULL");
   257       CND_PRECONDITION(reader != NULL, "reader is NULL");
   279       CND_PRECONDITION(query != NULL, "query is NULL");
   258       CND_PRECONDITION(query != NULL, "query is NULL");
   280 
   259       
   281 //#ifdef USE_HIGHLIGHTER     
   260 
   282 	if(!excerptrwQuery || !fistlnHLQuery)
       
   283 		{                          
       
   284   			excerptrwQuery = query->rewrite(reader); 
       
   285   		}           
       
   286 //#endif
       
   287 
   261 
   288     Weight* weight = query->weight(this);
   262     Weight* weight = query->weight(this);
   289     Scorer* scorer = weight->scorer(reader);
   263     Scorer* scorer = weight->scorer(reader);
   290     if (scorer == NULL){
   264     if (scorer == NULL){
   291 		return _CLNEW TopFieldDocs(0, NULL, 0, NULL );
   265 		return _CLNEW TopFieldDocs(0, NULL, 0, NULL );
   331   //Post - filter if non-NULL, a bitset used to eliminate some documents
   305   //Post - filter if non-NULL, a bitset used to eliminate some documents
   332      
   306      
   333       CND_PRECONDITION(reader != NULL, "reader is NULL");
   307       CND_PRECONDITION(reader != NULL, "reader is NULL");
   334       CND_PRECONDITION(query != NULL, "query is NULL");
   308       CND_PRECONDITION(query != NULL, "query is NULL");
   335      
   309      
   336 //#ifdef USE_HIGHLIGHTER     
   310 
   337 	if(!excerptrwQuery || !fistlnHLQuery)
       
   338 		{                          
       
   339   			excerptrwQuery = query->rewrite(reader); 
       
   340   		}           
       
   341 //#endif
       
   342 
   311 
   343 
   312 
   344       BitSet* bits = NULL;
   313       BitSet* bits = NULL;
   345       SimpleFilteredCollector* fc = NULL; 
   314       SimpleFilteredCollector* fc = NULL; 
   346 
   315 
   378 			}
   347 			}
   379 			last = query;
   348 			last = query;
   380         }
   349         }
   381         return query;
   350         return query;
   382     }
   351     }
   383 //#ifdef USE_HIGHLIGHTER
   352 
   384 void IndexSearcher::getrewritten(int32_t n, Query* original, Query* rwQuery[]) 
       
   385           {
       
   386             rwQuery[0] = fistlnHLQuery;
       
   387             rwQuery[1] = excerptrwQuery;
       
   388           }
       
   389 //#endif
       
   390     void IndexSearcher::explain(Query* query, int32_t doc, Explanation* ret){
   353     void IndexSearcher::explain(Query* query, int32_t doc, Explanation* ret){
   391         Weight* weight = query->weight(this);
   354         Weight* weight = query->weight(this);
   392         weight->explain(reader, doc, ret);
   355         weight->explain(reader, doc, ret);
   393 
   356 
   394         Query* wq = weight->getQuery();
   357         Query* wq = weight->getQuery();