matcher/queryoptimiser.h

Go to the documentation of this file.
00001 
00004 /* Copyright (C) 2007,2008 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
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

Documentation for Xapian (version 1.0.20).
Generated on 28 Apr 2010 by Doxygen 1.5.2.