00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _TEXTQUERYRETMETHOD_HPP
00013 #define _TEXTQUERYRETMETHOD_HPP
00014
00015
00016 #include "RetrievalMethod.hpp"
00017 #include "TextQueryRep.hpp"
00018 #include "DocumentRep.hpp"
00019 #include "ScoreFunction.hpp"
00020 #include "ScoreAccumulator.hpp"
00021 #include "FreqVector.hpp"
00022 #include "Param.hpp"
00023
00024
00025
00026
00074 class TextQueryRetMethod : public RetrievalMethod {
00075 public:
00078 TextQueryRetMethod(Index &ind, ScoreAccumulator & accumulator) :
00079 RetrievalMethod(ind), scAcc(accumulator) {
00080 cacheDocReps = (ParamGetInt("cacheDocReps", 1) == 1);
00081 if (cacheDocReps) {
00082 docRepsSize = ind.docCount() + 1;
00083 docReps = new DocumentRep *[docRepsSize];
00084 for (int i = 0; i <= ind.docCount(); i++) docReps[i] = NULL;
00085 }
00086 }
00089 virtual ~TextQueryRetMethod() {
00090 if (cacheDocReps) {
00091 for (int i = 0; i < docRepsSize; i++) delete(docReps[i]);
00092 delete[](docReps);
00093 }
00094 }
00095
00097 virtual TextQueryRep *computeTextQueryRep(TextQuery &qry)=0;
00099 virtual TextQueryRep *computeTextQueryRep(int docid){
00100 return NULL;
00101 }
00103
00104
00106 virtual double scoreDoc(QueryRep &qry, int docID);
00108 virtual void scoreCollection(QueryRep &qry, IndexedRealVector &results);
00110 virtual void scoreCollection(int docid, IndexedRealVector &results);
00111
00113 virtual DocumentRep *computeDocRep(int docID) =0;
00115 virtual ScoreFunction *scoreFunc() = 0;
00117 virtual void updateQuery(QueryRep &qryRep, DocIDSet &relDocs) {
00118 updateTextQuery(*((TextQueryRep *)(&qryRep)), relDocs);
00119 }
00120
00122 virtual void updateTextQuery(TextQueryRep &qryRep, DocIDSet &relDocs)=0;
00123
00125
00128 virtual void scoreInvertedIndex(QueryRep &qryRep, IndexedRealVector &scores, bool scoreAll=false);
00129
00130 virtual double scoreDocVector(TextQueryRep &qry, int docID, FreqVector &docVector);
00131
00132 protected:
00133 ScoreAccumulator &scAcc;
00135 DocumentRep **docReps;
00137 bool cacheDocReps;
00139 int docRepsSize;
00140 };
00141
00142
00143
00144
00145 inline QueryRep *TextQueryRetMethod::computeQueryRep(Query &qry) {
00146 TextQuery *q = static_cast<TextQuery *>(&qry);
00147 return (computeTextQueryRep(*q));
00148 }
00149
00150 #endif
00151
00152
00153
00154