00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef XAPIAN_INCLUDED_QUERYOPTIMISER_H
00022 #define XAPIAN_INCLUDED_QUERYOPTIMISER_H
00023
00024 #include <xapian/query.h>
00025
00026 #include "database.h"
00027 #include "localmatch.h"
00028 #include "omenquireinternal.h"
00029 #include "postlist.h"
00030
00031 #include <list>
00032 #include <map>
00033 #include <string>
00034 #include <vector>
00035
00036 class MultiMatch;
00037 struct PosFilter;
00038
00039 class QueryOptimiser {
00040 const Xapian::Database::Internal & db;
00041
00042 Xapian::doccount db_size;
00043
00044 LocalSubMatch & localsubmatch;
00045
00046 MultiMatch * matcher;
00047
00055 PostList * do_subquery(const Xapian::Query::Internal * query,
00056 double factor);
00057
00065 PostList * do_leaf(const Xapian::Query::Internal * query, double factor) {
00066 if (query->tname.empty()) factor = 0.0;
00067 return localsubmatch.postlist_from_op_leaf_query(query, factor);
00068 }
00069
00078 PostList * do_and_like(const Xapian::Query::Internal *query, double factor);
00079
00090 void do_and_like(const Xapian::Query::Internal *query, double factor,
00091 std::vector<PostList *> & and_plists,
00092 std::list<PosFilter> & pos_filters);
00093
00102 PostList * do_or_like(const Xapian::Query::Internal *query, double factor);
00103
00104 public:
00105 QueryOptimiser(const Xapian::Database::Internal & db_,
00106 LocalSubMatch & localsubmatch_,
00107 MultiMatch * matcher_)
00108 : db(db_), db_size(db.get_doccount()), localsubmatch(localsubmatch_),
00109 matcher(matcher_) { }
00110
00111 PostList * optimise_query(Xapian::Query::Internal * query) {
00112 return do_subquery(query, 1.0);
00113 }
00114 };
00115
00116 #endif // XAPIAN_INCLUDED_QUERYOPTIMISER_H