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

           Branch data     Line data    Source code
       1                 :            : /** @file matcher.h
       2                 :            :  * @brief Matcher class
       3                 :            :  */
       4                 :            : /* Copyright (C) 2017,2018 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifndef XAPIAN_INCLUDED_MATCHER_H
      22                 :            : #define XAPIAN_INCLUDED_MATCHER_H
      23                 :            : 
      24                 :            : #ifndef PACKAGE
      25                 :            : # error config.h must be included first in each C++ source file
      26                 :            : #endif
      27                 :            : 
      28                 :            : #include "api/enquireinternal.h"
      29                 :            : #include "localsubmatch.h"
      30                 :            : #include "remotesubmatch.h"
      31                 :            : #include "weight/weightinternal.h"
      32                 :            : 
      33                 :            : #include "xapian/database.h"
      34                 :            : #include "xapian/query.h"
      35                 :            : 
      36                 :            : #include <memory>
      37                 :            : #include <vector>
      38                 :            : 
      39                 :            : namespace Xapian {
      40                 :            :     class KeyMaker;
      41                 :            :     class MatchDecider;
      42                 :            :     class MSet;
      43                 :            :     class Weight;
      44                 :            : }
      45                 :            : 
      46                 :     321456 : class Matcher {
      47                 :            :     typedef Xapian::Internal::opt_intrusive_ptr<Xapian::MatchSpy> opt_ptr_spy;
      48                 :            : 
      49                 :            :     Xapian::Database db;
      50                 :            : 
      51                 :            :     Xapian::Query query;
      52                 :            : 
      53                 :            :     /** LocalSubMatch objects for local databases.
      54                 :            :      *
      55                 :            :      *  The entries are at the same index as the corresponding shard in the
      56                 :            :      *  Database object, with NULL entries for any remote shards.
      57                 :            :      */
      58                 :            :     std::vector<std::unique_ptr<LocalSubMatch>> locals;
      59                 :            : 
      60                 :            : #ifdef XAPIAN_HAS_REMOTE_BACKEND
      61                 :            :     /** RemoteSubMatch objects for remote databases.
      62                 :            :      *
      63                 :            :      *  Unlike @a locals, this *only* contains entries for remote shards, and
      64                 :            :      *  each RemoteSubMatch object knows its shard index.
      65                 :            :      *
      66                 :            :      *  If poll() isn't available so that select() has to be used to
      67                 :            :      *  wait for fds to become ready to read, objects with an fd < FD_SETSIZE
      68                 :            :      *  come first, and those with an fd >= FD_SETSIZE are put at the end with
      69                 :            :      *  @a first_oversize recording the partition point.
      70                 :            :      */
      71                 :            :     std::vector<std::unique_ptr<RemoteSubMatch>> remotes;
      72                 :            : 
      73                 :            : # ifndef HAVE_POLL
      74                 :            :     /** Partition point in @a remotes for fds < FD_SETSIZE.
      75                 :            :      *
      76                 :            :      *  remotes[i]->get_read_fd() < FD_SETSIZE for i < first_oversize,
      77                 :            :      *  remotes[i]->get_read_fd() >= FD_SETSIZE for i >= first_oversize.
      78                 :            :      */
      79                 :            :     std::size_t first_oversize;
      80                 :            : # endif
      81                 :            : #endif
      82                 :            : 
      83                 :            :     bool full_db_has_positions;
      84                 :            : 
      85                 :            :     Matcher(const Matcher&) = delete;
      86                 :            : 
      87                 :            :     Matcher& operator=(const Matcher&) = delete;
      88                 :            : 
      89                 :            :     Xapian::MSet get_local_mset(Xapian::doccount first,
      90                 :            :                                 Xapian::doccount maxitems,
      91                 :            :                                 Xapian::doccount check_at_least,
      92                 :            :                                 const Xapian::Weight& wtscheme,
      93                 :            :                                 const Xapian::MatchDecider* mdecider,
      94                 :            :                                 const Xapian::KeyMaker* sorter,
      95                 :            :                                 Xapian::valueno collapse_key,
      96                 :            :                                 Xapian::doccount collapse_max,
      97                 :            :                                 int percent_threshold,
      98                 :            :                                 double percent_threshold_factor,
      99                 :            :                                 double weight_threshold,
     100                 :            :                                 Xapian::Enquire::docid_order order,
     101                 :            :                                 Xapian::valueno sort_key,
     102                 :            :                                 Xapian::Enquire::Internal::sort_setting sort_by,
     103                 :            :                                 bool sort_val_reverse,
     104                 :            :                                 double time_limit,
     105                 :            :                                 const std::vector<opt_ptr_spy>& matchspies);
     106                 :            : 
     107                 :            :     /// Perform action on remotes as they become ready using poll() or select().
     108                 :            :     template<typename Action> void for_all_remotes(Action action);
     109                 :            : 
     110                 :            :   public:
     111                 :            :     /** Constructor.
     112                 :            :      *
     113                 :            :      *  @param db_              Database to search
     114                 :            :      *  @param full_db_has_positions_   Does the full database has positions?
     115                 :            :      *  @param query            Query object
     116                 :            :      *  @param query_length     Query length
     117                 :            :      *  @param rset             Relevance set (NULL for none)
     118                 :            :      *  @param stats            Object to collate stats into
     119                 :            :      *  @param wtscheme         Weight object to use as factory
     120                 :            :      *  @param have_sorter      KeyMaker in use for sort keys?
     121                 :            :      *  @param have_mdecider    MatchDecider specified?
     122                 :            :      *  @param collapse_key     value slot to collapse on (Xapian::BAD_VALUENO
     123                 :            :      *                          which means no collapsing)
     124                 :            :      *  @param collapse_max     Maximum number of documents with the same key
     125                 :            :      *                          to allow
     126                 :            :      *  @param percent_threshold Lower bound on percentage score
     127                 :            :      *  @param weight_threshold Lower bound on weight
     128                 :            :      *  @param order            Xapian::docid sort order
     129                 :            :      *  @param sort_key         Value slot to sort on
     130                 :            :      *  @param sort_by          What to sort results on
     131                 :            :      *  @param sort_val_reverse Reverse direction keys sort in?
     132                 :            :      *  @param time_limit       time in seconds after which to disable
     133                 :            :      *                          check_at_least (0.0 means don't).
     134                 :            :      *  @param matchspies       MatchSpy objects to use
     135                 :            :      */
     136                 :            :     Matcher(const Xapian::Database& db_,
     137                 :            :             bool full_db_has_positions_,
     138                 :            :             const Xapian::Query& query,
     139                 :            :             Xapian::termcount query_length,
     140                 :            :             const Xapian::RSet* rset,
     141                 :            :             Xapian::Weight::Internal& stats,
     142                 :            :             const Xapian::Weight& wtscheme,
     143                 :            :             bool have_sorter,
     144                 :            :             bool have_mdecider,
     145                 :            :             Xapian::valueno collapse_key,
     146                 :            :             Xapian::doccount collapse_max,
     147                 :            :             int percent_threshold,
     148                 :            :             double weight_threshold,
     149                 :            :             Xapian::Enquire::docid_order order,
     150                 :            :             Xapian::valueno sort_key,
     151                 :            :             Xapian::Enquire::Internal::sort_setting sort_by,
     152                 :            :             bool sort_val_reverse,
     153                 :            :             double time_limit,
     154                 :            :             const std::vector<opt_ptr_spy>& matchspies);
     155                 :            : 
     156                 :            :     /** Run the match and produce an MSet object.
     157                 :            :      *
     158                 :            :      *  @param first            Zero-based index of the first result to return
     159                 :            :      *                          (which supports retrieving pages of results).
     160                 :            :      *  @param maxitems         The maximum number of documents to return.
     161                 :            :      *  @param checkatleast     Check at least this many documents.  By default
     162                 :            :      *                          Xapian will avoiding considering documents
     163                 :            :      *                          which it can prove can't match, which is faster
     164                 :            :      *                          but can result in a loose bounds on and a poor
     165                 :            :      *                          estimate of the total number of matches -
     166                 :            :      *                          setting checkatleast higher allows trading off
     167                 :            :      *                          speed for tighter bounds and a more accurate
     168                 :            :      *                          estimate.
     169                 :            :      *  @param mset             MSet object to full in
     170                 :            :      *  @param stats            Collated stats
     171                 :            :      *  @param wtscheme         Weight object to use as factory
     172                 :            :      *  @param mdecider         MatchDecider to use (NULL for none)
     173                 :            :      *  @param sorter           KeyMaker for sort keys (NULL for none)
     174                 :            :      *  @param collapse_key     value slot to collapse on (Xapian::BAD_VALUENO
     175                 :            :      *                          which means no collapsing)
     176                 :            :      *  @param collapse_max     Maximum number of documents with the same key
     177                 :            :      *                          to allow
     178                 :            :      *  @param collapse_key     value slot to collapse on (Xapian::BAD_VALUENO
     179                 :            :      *                          which means no collapsing)
     180                 :            :      *  @param collapse_max     Maximum number of documents with the same key
     181                 :            :      *                          to allow
     182                 :            :      *  @param percent_threshold Lower bound on percentage score
     183                 :            :      *  @param weight_threshold Lower bound on weight
     184                 :            :      *  @param order            Xapian::docid sort order
     185                 :            :      *  @param sort_key         Value slot to sort on
     186                 :            :      *  @param sort_by          What to sort results on
     187                 :            :      *  @param sort_val_reverse Reverse direction keys sort in?
     188                 :            :      *  @param time_limit       time in seconds after which to disable
     189                 :            :      *                          check_at_least (0.0 means don't).
     190                 :            :      *  @param matchspies       MatchSpy objects to use
     191                 :            :      */
     192                 :            :     Xapian::MSet get_mset(Xapian::doccount first,
     193                 :            :                           Xapian::doccount maxitems,
     194                 :            :                           Xapian::doccount check_at_least,
     195                 :            :                           Xapian::Weight::Internal& stats,
     196                 :            :                           const Xapian::Weight& wtscheme,
     197                 :            :                           const Xapian::MatchDecider* mdecider,
     198                 :            :                           const Xapian::KeyMaker* sorter,
     199                 :            :                           Xapian::valueno collapse_key,
     200                 :            :                           Xapian::doccount collapse_max,
     201                 :            :                           int percent_threshold,
     202                 :            :                           double weight_threshold,
     203                 :            :                           Xapian::Enquire::docid_order order,
     204                 :            :                           Xapian::valueno sort_key,
     205                 :            :                           Xapian::Enquire::Internal::sort_setting sort_by,
     206                 :            :                           bool sort_val_reverse,
     207                 :            :                           double time_limit,
     208                 :            :                           const std::vector<opt_ptr_spy>& matchspies);
     209                 :            : };
     210                 :            : 
     211                 :            : #endif // XAPIAN_INCLUDED_MATCHER_H

Generated by: LCOV version 1.11