File: msetpostlist.cc

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 (168 lines) | stat: -rw-r--r-- 4,845 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/** @file msetpostlist.cc
 *  @brief PostList returning entries from an MSet
 */
/* Copyright (C) 2006,2007,2009,2010,2011,2015 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
 */

#include <config.h>

#include "msetpostlist.h"

#include "debuglog.h"
#include "omassert.h"

#include "xapian/error.h"

using namespace std;

Xapian::doccount
MSetPostList::get_termfreq_min() const
{
    LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_min", NO_ARGS);
    RETURN(mset_internal->matches_lower_bound);
}

Xapian::doccount
MSetPostList::get_termfreq_est() const
{
    LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_est", NO_ARGS);
    RETURN(mset_internal->matches_estimated);
}

Xapian::doccount
MSetPostList::get_termfreq_max() const
{
    LOGCALL(MATCH, Xapian::doccount, "MSetPostList::get_termfreq_max", NO_ARGS);
    RETURN(mset_internal->matches_upper_bound);
}

double
MSetPostList::get_maxweight() const
{
    LOGCALL(MATCH, double, "MSetPostList::get_maxweight", NO_ARGS);
    // If we've not started, return max_possible from our MSet so that this
    // value gets used to set max_possible in the combined MSet.
    if (cursor == -1) RETURN(mset_internal->max_possible);

    // If the MSet is sorted in descending weight order, then the maxweight we
    // can return from now on is the weight of the current item.
    if (decreasing_relevance) {
	// FIXME: This is actually a reduction in the maxweight...
	if (at_end()) RETURN(0);
	RETURN(mset_internal->items[cursor].wt);
    }

    // Otherwise max_attained is the best answer we can give.
    RETURN(mset_internal->max_attained);
}

Xapian::docid
MSetPostList::get_docid() const
{
    LOGCALL(MATCH, Xapian::docid, "MSetPostList::get_docid", NO_ARGS);
    Assert(cursor != -1);
    RETURN(mset_internal->items[cursor].did);
}

double
MSetPostList::get_weight() const
{
    LOGCALL(MATCH, double, "MSetPostList::get_weight", NO_ARGS);
    Assert(cursor != -1);
    RETURN(mset_internal->items[cursor].wt);
}

const string *
MSetPostList::get_sort_key() const
{
    LOGCALL(MATCH, const string *, "MSetPostList::get_sort_key", NO_ARGS);
    Assert(cursor != -1);
    RETURN(&mset_internal->items[cursor].sort_key);
}

const string *
MSetPostList::get_collapse_key() const
{
    LOGCALL(MATCH, const string *, "MSetPostList::get_collapse_key", NO_ARGS);
    Assert(cursor != -1);
    RETURN(&mset_internal->items[cursor].collapse_key);
}

Xapian::termcount
MSetPostList::get_doclength() const
{
    throw Xapian::UnimplementedError("MSetPostList::get_doclength() unimplemented");
}

Xapian::termcount
MSetPostList::get_unique_terms() const
{
    throw Xapian::UnimplementedError("MSetPostList::get_unique_terms() unimplemented");
}

double
MSetPostList::recalc_maxweight()
{
    LOGCALL(MATCH, double, "MSetPostList::recalc_maxweight", NO_ARGS);
    RETURN(MSetPostList::get_maxweight());
}

PostList *
MSetPostList::next(double w_min)
{
    LOGCALL(MATCH, PostList *, "MSetPostList::next", w_min);
    Assert(cursor == -1 || !at_end());
    ++cursor;
    if (decreasing_relevance) {
	// MSet items are in decreasing weight order, so if the current item
	// doesn't have enough weight, none of the remaining items will, so
	// skip straight to the end.
	if (!at_end() && mset_internal->items[cursor].wt < w_min)
	    cursor = mset_internal->items.size();
    } else {
	// Otherwise, skip to the next entry with enough weight.
	while (!at_end() && mset_internal->items[cursor].wt < w_min)
	    ++cursor;
    }
    RETURN(NULL);
}

PostList *
MSetPostList::skip_to(Xapian::docid, double)
{
    // The usual semantics of skip_to don't make sense since MSetPostList
    // returns documents in MSet order rather than docid order like other
    // PostLists do.
    throw Xapian::InvalidOperationError("MSetPostList::skip_to not meaningful");
}

bool
MSetPostList::at_end() const
{
    LOGCALL(MATCH, bool, "MSetPostList::at_end", NO_ARGS);
    Assert(cursor != -1);
    RETURN(size_t(cursor) >= mset_internal->items.size());
}

string
MSetPostList::get_description() const
{
    string desc("(MSet ");
    desc += mset_internal->get_description();
    desc += ')';
    return desc;
}