File: net_termlist.h

package info (click to toggle)
xapian-core 1.4.3-2%2Bdeb9u3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,412 kB
  • sloc: cpp: 113,868; ansic: 8,723; sh: 4,433; perl: 836; makefile: 566; tcl: 317; python: 40
file content (128 lines) | stat: -rw-r--r-- 3,871 bytes parent folder | download | duplicates (6)
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
/** @file net_termlist.h
 * @brief Termlist in a remote db
 */
/* Copyright 1999,2000,2001 BrightStation PLC
 * Copyright 2003,2006,2007,2009,2010,2011 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, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#ifndef OM_HGUARD_NET_TERMLIST_H
#define OM_HGUARD_NET_TERMLIST_H

#include <string>

#include <xapian/types.h>
#include <xapian/error.h>
#include "api/termlist.h"
#include "expand/expandweight.h"
#include "remote-database.h"

using namespace std;

/** An item in a NetworkTermList.
 */
class NetworkTermListItem {
    public:
	/** The "name" of this term.
	 */
	string tname;

	/** The term frequency.
	 *  This is the number of documents (in the network database)
	 *  indexed by the term.
	 */
	Xapian::doccount termfreq;

	/** The within-document-frequency of the term.
	 *
	 *  This information may not be available, in which case the field
	 *  should have a value of 0.
	 */
	Xapian::termcount wdf;
};

/** A term list for a database on the other side of a network connection.
 *  The termlist is serialised across the network, and rebuilt into this
 *  object on the client side.
 */
class NetworkTermList : public TermList {
    friend class RemoteDatabase;
    private:
	/** The list of items comprising the termlist.
	 */
	vector<NetworkTermListItem> items;

	/** The current position in the list.
	 */
	vector<NetworkTermListItem>::const_iterator current_position;

	/** Whether we have yet started iterating through the list.
	 */
	bool started;

	/** The length of the document for which this is the termlist.
	 *
	 *  Note that this is not a normalised document length.
	 */
	Xapian::termcount document_length;

	/** The number of documents in the database in which this
	 *  document resides.
	 *
	 *  Note that this may not be the number of documents in the combined
	 *  database when multiple databases are being searched.
	 */
	Xapian::doccount database_size;

	///  Keep a reference to our database
	Xapian::Internal::intrusive_ptr<const RemoteDatabase> this_db;

	/// The id of the document this termlist came from (or 0 if not applicable).
	Xapian::docid did;

	/** Standard constructor is private: NetworkTermLists are created
	 *  by RemoteDatabase object only, which is a friend.
	 *
	 *  @param document_length_ The (non-normalised) length of the document
	 *  @param database_size_   The number of documents in the database
	 *  @param this_db_	    The database
	 *  @param did_		    The document id
	 */
	NetworkTermList(Xapian::termcount document_length_,
			Xapian::doccount database_size_,
			Xapian::Internal::intrusive_ptr<const RemoteDatabase> this_db_,
			Xapian::docid did_);
    public:

	/** Get the number of terms in the termlist.
	 */
	Xapian::termcount get_approx_size() const;

	// Collate weighting information for the current term.
	void accumulate_stats(Xapian::Internal::ExpandStats &stats) const;
	string get_termname() const;
	Xapian::termcount get_wdf() const;
	Xapian::doccount get_termfreq() const;
	TermList * next();
	TermList * skip_to(const std::string &term);
	bool at_end() const;

	Xapian::termcount positionlist_count() const;
	Xapian::PositionIterator positionlist_begin() const;
};

#endif /* OM_HGUARD_NET_TERMLIST_H */