LCOV - code coverage report
Current view: top level - matcher - queryoptimiser.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core c2b6f1024d3a Lines: 23 23 100.0 %
Date: 2019-05-16 09:13:18 Functions: 11 11 100.0 %
Branches: 6 8 75.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file queryoptimiser.h
       2                 :            :  * @brief Details passed around while building PostList tree from Query tree
       3                 :            :  */
       4                 :            : /* Copyright (C) 2007,2008,2009,2010,2011,2013,2014,2015,2016,2018 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 "backends/databaseinternal.h"
      26                 :            : #include "localsubmatch.h"
      27                 :            : #include "api/postlist.h"
      28                 :            : 
      29                 :            : class LeafPostList;
      30                 :            : class PostListTree;
      31                 :            : 
      32                 :            : namespace Xapian {
      33                 :            : namespace Internal {
      34                 :            : 
      35                 :            : class QueryOptimiser {
      36                 :            :     /// Prevent assignment.
      37                 :            :     void operator=(const QueryOptimiser &);
      38                 :            : 
      39                 :            :     /// Prevent copying.
      40                 :            :     QueryOptimiser(const QueryOptimiser &);
      41                 :            : 
      42                 :            :     LocalSubMatch & localsubmatch;
      43                 :            : 
      44                 :            :     /** How many weighted leaf subqueries there are.
      45                 :            :      *
      46                 :            :      *  Used for scaling percentages when the highest weighted document doesn't
      47                 :            :      *  "match all terms".
      48                 :            :      */
      49                 :            :     Xapian::termcount total_subqs;
      50                 :            : 
      51                 :            :     LeafPostList * hint;
      52                 :            : 
      53                 :            :     bool hint_owned;
      54                 :            : 
      55                 :            :   public:
      56                 :            :     bool need_positions;
      57                 :            : 
      58                 :            :     bool in_synonym;
      59                 :            : 
      60                 :            :     bool full_db_has_positions;
      61                 :            : 
      62                 :            :     const Xapian::Database::Internal & db;
      63                 :            : 
      64                 :            :     Xapian::doccount db_size;
      65                 :            : 
      66                 :            :     PostListTree * matcher;
      67                 :            : 
      68                 :     178254 :     QueryOptimiser(const Xapian::Database::Internal & db_,
      69                 :            :                    LocalSubMatch & localsubmatch_,
      70                 :            :                    PostListTree * matcher_,
      71                 :            :                    bool full_db_has_positions_)
      72                 :            :         : localsubmatch(localsubmatch_), total_subqs(0),
      73                 :            :           hint(0), hint_owned(false),
      74                 :            :           need_positions(false), in_synonym(false),
      75                 :            :           full_db_has_positions(full_db_has_positions_),
      76                 :     178254 :           db(db_), db_size(db.get_doccount()),
      77                 :     356508 :           matcher(matcher_) { }
      78                 :            : 
      79                 :     178254 :     ~QueryOptimiser() {
      80 [ +  + ][ +  - ]:     178254 :         if (hint_owned) delete hint;
      81                 :     178254 :     }
      82                 :            : 
      83                 :     323991 :     void inc_total_subqs() { ++total_subqs; }
      84                 :            : 
      85                 :     357740 :     Xapian::termcount get_total_subqs() const { return total_subqs; }
      86                 :            : 
      87                 :        668 :     void set_total_subqs(Xapian::termcount n) { total_subqs = n; }
      88                 :            : 
      89                 :     312613 :     PostList * open_post_list(const std::string& term,
      90                 :            :                               Xapian::termcount wqf,
      91                 :            :                               double factor) {
      92                 :            :         return localsubmatch.open_post_list(term, wqf, factor, need_positions,
      93                 :     312613 :                                             in_synonym, this, false);
      94                 :            :     }
      95                 :            : 
      96                 :       1224 :     PostList * open_lazy_post_list(const std::string& term,
      97                 :            :                                    Xapian::termcount wqf,
      98                 :            :                                    double factor) {
      99                 :            :         return localsubmatch.open_post_list(term, wqf, factor, need_positions,
     100                 :       1224 :                                             in_synonym, this, true);
     101                 :            :     }
     102                 :            : 
     103                 :        821 :     PostList * make_synonym_postlist(PostList * pl,
     104                 :            :                                      double factor,
     105                 :            :                                      bool wdf_disjoint) {
     106                 :            :         return localsubmatch.make_synonym_postlist(matcher, pl, factor,
     107                 :        821 :                                                    wdf_disjoint);
     108                 :            :     }
     109                 :            : 
     110                 :     627846 :     const LeafPostList * get_hint_postlist() const { return hint; }
     111                 :            : 
     112                 :     313629 :     void set_hint_postlist(LeafPostList * new_hint) {
     113         [ +  + ]:     313629 :         if (hint_owned) {
     114                 :         16 :             hint_owned = false;
     115         [ +  - ]:         16 :             delete hint;
     116                 :            :         }
     117                 :     313629 :         hint = new_hint;
     118                 :     313629 :     }
     119                 :            : 
     120                 :        168 :     void take_hint_ownership() { hint_owned = true; }
     121                 :            : };
     122                 :            : 
     123                 :            : }
     124                 :            : }
     125                 :            : 
     126                 :            : using Xapian::Internal::QueryOptimiser;
     127                 :            : 
     128                 :            : #endif // XAPIAN_INCLUDED_QUERYOPTIMISER_H

Generated by: LCOV version 1.11