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 <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

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.