1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
/** @file
* @brief Abstract base class for termlists.
*/
/* Copyright (C) 2007,2010,2013,2020,2024 Olly Betts
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see
* <https://www.gnu.org/licenses/>.
*/
#ifndef XAPIAN_INCLUDED_TERMLIST_H
#define XAPIAN_INCLUDED_TERMLIST_H
#include "api/smallvector.h"
#include "backends/positionlist.h"
#include <string>
#include <string_view>
#include "xapian/intrusive_ptr.h"
#include <xapian/types.h>
#include <xapian/termiterator.h>
namespace Xapian {
namespace Internal {
class ExpandStats;
}
}
/// Abstract base class for termlists.
class Xapian::TermIterator::Internal : public Xapian::Internal::intrusive_base {
/// Don't allow assignment.
void operator=(const Internal &) = delete;
/// Don't allow copying.
Internal(const Internal &) = delete;
protected:
/// Only constructable as a base class for derived classes.
Internal() { }
/// The current term.
std::string current_term;
public:
/** We have virtual methods and want to be able to delete derived classes
* using a pointer to the base class, so we need a virtual destructor.
*/
virtual ~Internal();
/// Return approximate size of this termlist.
virtual Xapian::termcount get_approx_size() const = 0;
/// Collate weighting information for the current term.
virtual void accumulate_stats(Xapian::Internal::ExpandStats & stats) const;
/// Return the termname at the current position.
const std::string& get_termname() const {
return current_term;
}
/// Return the wdf for the term at the current position.
virtual Xapian::termcount get_wdf() const = 0;
/// Return the term frequency for the term at the current position.
virtual Xapian::doccount get_termfreq() const = 0;
/** Advance the current position to the next term in the termlist.
*
* The list starts before the first term in the list, so next(), skip_to()
* or check() must be called before any methods which need the context of
* the current position.
*
* @return Normally returns NULL to indicate success. If the end has been
* reached, returns this; if another non-NULL pointer is
* returned then the caller should substitute the returned pointer
* for its pointer to us, and then delete us. This "pruning" can
* only happen for a non-leaf subclass of this class.
*/
virtual Internal * next() = 0;
/** Skip forward to the specified term.
*
* If the specified term isn't in the list, position ourselves on the
* first term after term.
*
* @return Normally returns NULL to indicate success. If no terms after
* term exist, returns this; if another non-NULL pointer is
* returned then the caller should substitute the returned pointer
* for its pointer to us, and then delete us. This "pruning" can
* only happen for a non-leaf subclass of this class.
*/
virtual Internal* skip_to(std::string_view term) = 0;
/// Return the length of the position list for the current position.
virtual Xapian::termcount positionlist_count() const = 0;
/** Get pointer to VecCOW<termpos> if that's the internal representation.
*
* This avoids unnecessary copying of positions in the common cases - the
* case it doesn't help with is adding a document back with unmodified
* positions *AND* a different docid, which is an unusual thing to do.
*
* @return Pointer to VecCOW<termpos> or NULL.
*/
virtual const Xapian::VecCOW<Xapian::termpos> * get_vec_termpos() const;
/// Return PositionList for the current position.
virtual PositionList* positionlist_begin() const = 0;
/** Which shard of a multidatabase this is from.
*
* Used by Enquire::get_eset().
*/
size_t shard_index = 0;
};
// In the external API headers, this class is Xapian::TermIterator::Internal,
// but in the library code it's still known as "TermList" in most places.
typedef Xapian::TermIterator::Internal TermList;
#endif // XAPIAN_INCLUDED_TERMLIST_H
|