LCOV - code coverage report
Current view: top level - matcher - queryoptimiser.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 6 6 100.0 %
Date: 2011-08-21 Functions: 3 3 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /** @file queryoptimiser.h
       2                 :            :  * @brief Convert a Xapian::Query::Internal tree into an optimal PostList tree.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009,2010 Olly Betts
       5                 :            :  * Copyright (C) 2008 Lemur Consulting Ltd
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef XAPIAN_INCLUDED_QUERYOPTIMISER_H
      23                 :            : #define XAPIAN_INCLUDED_QUERYOPTIMISER_H
      24                 :            : 
      25                 :            : #include "xapian/query.h"
      26                 :            : 
      27                 :            : #include "database.h"
      28                 :            : #include "localsubmatch.h"
      29                 :            : #include "omenquireinternal.h"
      30                 :            : #include "postlist.h"
      31                 :            : 
      32                 :            : #include <list>
      33                 :            : #include <vector>
      34                 :            : 
      35                 :            : class MultiMatch;
      36                 :            : struct PosFilter;
      37                 :            : 
      38                 :            : class QueryOptimiser {
      39                 :            :     const Xapian::Database::Internal & db;
      40                 :            : 
      41                 :            :     Xapian::doccount db_size;
      42                 :            : 
      43                 :            :     LocalSubMatch & localsubmatch;
      44                 :            : 
      45                 :            :     MultiMatch * matcher;
      46                 :            : 
      47                 :            :     /** How many leaf subqueries there are.
      48                 :            :      *
      49                 :            :      *  Used for scaling percentages when the highest weighted document doesn't
      50                 :            :      *  "match all terms".
      51                 :            :      */
      52                 :            :     Xapian::termcount total_subqs;
      53                 :            : 
      54                 :            :     /** Optimise a Xapian::Query::Internal subtree into a PostList subtree.
      55                 :            :      *
      56                 :            :      *  @param query    The subtree to optimise.
      57                 :            :      *  @param factor   How much to scale weights for this subtree by.
      58                 :            :      *
      59                 :            :      *  @return         A PostList subtree.
      60                 :            :      */
      61                 :            :     PostList * do_subquery(const Xapian::Query::Internal * query,
      62                 :            :                            double factor);
      63                 :            : 
      64                 :            :     /** Optimise an AND-like Xapian::Query::Internal subtree into a PostList
      65                 :            :      *  subtree.
      66                 :            :      *
      67                 :            :      *  @param query    The subtree to optimise.
      68                 :            :      *  @param factor   How much to scale weights for this subtree by.
      69                 :            :      *
      70                 :            :      *  @return         A PostList subtree.
      71                 :            :      */
      72                 :            :     PostList * do_and_like(const Xapian::Query::Internal *query, double factor);
      73                 :            : 
      74                 :            :     /** Optimise an AND-like Xapian::Query::Internal subtree into a PostList
      75                 :            :      *  subtree.
      76                 :            :      *
      77                 :            :      *  @param query        The subtree to optimise.
      78                 :            :      *  @param factor       How much to scale weights for this subtree by.
      79                 :            :      *  @param and_plists   Append new PostList subtrees to be combined with
      80                 :            :      *                      AND to this vector.
      81                 :            :      *  @param pos_filters  Append any positional filters to be applied to the
      82                 :            :      *                      tree to this list.
      83                 :            :      */
      84                 :            :     void do_and_like(const Xapian::Query::Internal *query, double factor,
      85                 :            :                      std::vector<PostList *> & and_plists,
      86                 :            :                      std::list<PosFilter> & pos_filters);
      87                 :            : 
      88                 :            :     /** Optimise an OR-like Xapian::Query::Internal subtree into a PostList
      89                 :            :      *  subtree.
      90                 :            :      *
      91                 :            :      *  @param query    The subtree to optimise.
      92                 :            :      *  @param factor   How much to scale weights for this subtree by.
      93                 :            :      *
      94                 :            :      *  @return         A PostList subtree.
      95                 :            :      */
      96                 :            :     PostList * do_or_like(const Xapian::Query::Internal *query, double factor);
      97                 :            : 
      98                 :            :     /** Optimise a synonym Xapian::Query::Internal subtree into a PostList
      99                 :            :      *
     100                 :            :      *  @param query    The subtree to optimise.
     101                 :            :      *  @param factor   How much to scale weights for this subtree by.
     102                 :            :      *
     103                 :            :      *  @return         A PostList subtree.
     104                 :            :      */
     105                 :            :     PostList * do_synonym(const Xapian::Query::Internal *query, double factor);
     106                 :            : 
     107                 :            :   public:
     108                 :     246352 :     QueryOptimiser(const Xapian::Database::Internal & db_,
     109                 :            :                    LocalSubMatch & localsubmatch_,
     110                 :            :                    MultiMatch * matcher_)
     111                 :     246352 :         : db(db_), db_size(db.get_doccount()), localsubmatch(localsubmatch_),
     112                 :     246352 :           matcher(matcher_), total_subqs(0) { }
     113                 :            : 
     114                 :     246352 :     PostList * optimise_query(const Xapian::Query::Internal * query) {
     115                 :     246352 :         return do_subquery(query, 1.0);
     116                 :            :     }
     117                 :            : 
     118                 :     246352 :     Xapian::termcount get_total_subqueries() const { return total_subqs; }
     119                 :            : };
     120                 :            : 
     121                 :            : #endif // XAPIAN_INCLUDED_QUERYOPTIMISER_H

Generated by: LCOV version 1.8