LCOV - code coverage report
Current view: top level - matcher - synonympostlist.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 2 2 100.0 %
Date: 2019-06-30 05:20:33 Functions: 1 1 100.0 %
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file synonympostlist.h
       2                 :            :  * @brief Combine subqueries, weighting as if they are synonyms
       3                 :            :  */
       4                 :            : /* Copyright 2007,2009 Lemur Consulting Ltd
       5                 :            :  * Copyright 2009,2011,2014,2017,2018 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2 of the License, or
      10                 :            :  * (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_SYNONYMPOSTLIST_H
      23                 :            : #define XAPIAN_INCLUDED_SYNONYMPOSTLIST_H
      24                 :            : 
      25                 :            : #include "wrapperpostlist.h"
      26                 :            : 
      27                 :            : #include "backends/databaseinternal.h"
      28                 :            : 
      29                 :            : class PostListTree;
      30                 :            : 
      31                 :            : /** A postlist comprising several postlists SYNONYMed together.
      32                 :            :  *
      33                 :            :  *  This postlist returns all postings in the OR of the sub postlists, but
      34                 :            :  *  returns weights as if they represented a single term.  The term frequency
      35                 :            :  *  portion of the weight is approximated.
      36                 :            :  *
      37                 :            :  *  The wrapped postlist starts as an OR of all the sub-postlists being
      38                 :            :  *  joined with Synonym, but may decay into something else.
      39                 :            :  */
      40                 :            : class SynonymPostList : public WrapperPostList {
      41                 :            :     /// Weighting object used for calculating the synonym weights.
      42                 :            :     const Xapian::Weight * wt;
      43                 :            : 
      44                 :            :     /// Flag indicating whether the weighting object needs the wdf.
      45                 :            :     bool want_wdf;
      46                 :            : 
      47                 :            :     /** Are the subquery's wdf contributions disjoint?
      48                 :            :      *
      49                 :            :      *  This is true is each wdf from the document contributes at most itself
      50                 :            :      *  to the wdf of the subquery.  That means that the wdf of the subquery
      51                 :            :      *  can't possibly ever exceed the document length, so we can avoid the
      52                 :            :      *  need to check and clamp wdf to be <= document length.
      53                 :            :      */
      54                 :            :     bool wdf_disjoint;
      55                 :            : 
      56                 :            :     PostListTree* pltree;
      57                 :            : 
      58                 :            :     /// Lower bound on doclength in the subdatabase we're working over.
      59                 :            :     Xapian::termcount doclen_lower_bound;
      60                 :            : 
      61                 :            :   public:
      62                 :        816 :     SynonymPostList(PostList * subtree,
      63                 :            :                     const Xapian::Database::Internal* db,
      64                 :            :                     PostListTree* pltree_,
      65                 :            :                     bool wdf_disjoint_)
      66                 :            :         : WrapperPostList(subtree), wt(NULL), want_wdf(false),
      67                 :            :           wdf_disjoint(wdf_disjoint_),
      68                 :            :           pltree(pltree_),
      69         [ +  - ]:        816 :           doclen_lower_bound(db->get_doclength_lower_bound()) { }
      70                 :            : 
      71                 :            :     ~SynonymPostList();
      72                 :            : 
      73                 :            :     /** Set the weight object to be used for the synonym postlist.
      74                 :            :      *
      75                 :            :      *  Ownership of the weight object passes to the synonym postlist - the
      76                 :            :      *  caller must not delete it after use.
      77                 :            :      */
      78                 :            :     void set_weight(const Xapian::Weight * wt_);
      79                 :            : 
      80                 :            :     PostList *next(double w_min);
      81                 :            :     PostList *skip_to(Xapian::docid did, double w_min);
      82                 :            : 
      83                 :            :     double get_weight(Xapian::termcount doclen,
      84                 :            :                       Xapian::termcount unique_terms) const;
      85                 :            :     double recalc_maxweight();
      86                 :            : 
      87                 :            :     // Note - we don't need to implement get_termfreq_est_using_stats()
      88                 :            :     // because a synonym when used as a child of a synonym will be optimised
      89                 :            :     // to an OR.
      90                 :            : 
      91                 :            :     Xapian::termcount count_matching_subqs() const;
      92                 :            : 
      93                 :            :     std::string get_description() const;
      94                 :            : };
      95                 :            : 
      96                 :            : #endif /* XAPIAN_INCLUDED_SYNONYMPOSTLIST_H */

Generated by: LCOV version 1.11