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 <vector>
00034
00035 class MultiMatch;
00036 struct PosFilter;
00037
00038 class QueryOptimiser {
00039 const Xapian::Database::Internal & db;
00040
00041 Xapian::doccount db_size;
00042
00043 LocalSubMatch & localsubmatch;
00044
00045 MultiMatch * matcher;
00046
00054 PostList * do_subquery(const Xapian::Query::Internal * query,
00055 double factor);
00056
00064 PostList * do_leaf(const Xapian::Query::Internal * query, double factor) {
00065 if (query->tname.empty()) factor = 0.0;
00066 return localsubmatch.postlist_from_op_leaf_query(query, factor);
00067 }
00068
00077 PostList * do_and_like(const Xapian::Query::Internal *query, double factor);
00078
00089 void do_and_like(const Xapian::Query::Internal *query, double factor,
00090 std::vector<PostList *> & and_plists,
00091 std::list<PosFilter> & pos_filters);
00092
00101 PostList * do_or_like(const Xapian::Query::Internal *query, double factor);
00102
00103 public:
00104 QueryOptimiser(const Xapian::Database::Internal & db_,
00105 LocalSubMatch & localsubmatch_,
00106 MultiMatch * matcher_)
00107 : db(db_), db_size(db.get_doccount()), localsubmatch(localsubmatch_),
00108 matcher(matcher_) { }
00109
00110 PostList * optimise_query(Xapian::Query::Internal * query) {
00111 return do_subquery(query, 1.0);
00112 }
00113 };
00114
00115 #endif // XAPIAN_INCLUDED_QUERYOPTIMISER_H