Branch data Line data Source code
1 : : /** @file flint_spellingwordslist.cc
2 : : * @brief Iterator for the spelling correction words in a flint database.
3 : : */
4 : : /* Copyright (C) 2004,2005,2006,2007,2008 Olly Betts
5 : : * Copyright (C) 2007 Lemur Consulting Ltd
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 : :
23 : : #include <config.h>
24 : : #include "flint_spellingwordslist.h"
25 : :
26 : : #include "xapian/error.h"
27 : : #include "xapian/types.h"
28 : :
29 : : #include "debuglog.h"
30 : : #include "flint_utils.h"
31 : : #include "stringutils.h"
32 : :
33 : 5 : FlintSpellingWordsList::~FlintSpellingWordsList()
34 : : {
35 : : LOGCALL_DTOR(DB, "~FlintSpellingWordsList");
36 [ + - ][ # # ]: 5 : delete cursor;
[ # # ]
37 [ + - ][ # # ]: 5 : }
[ # # ]
38 : :
39 : : string
40 : 8 : FlintSpellingWordsList::get_termname() const
41 : : {
42 : : LOGCALL(DB, string, "FlintSpellingWordsList::get_termname", NO_ARGS);
43 : : Assert(cursor);
44 : : Assert(!at_end());
45 : : Assert(!cursor->current_key.empty());
46 : : Assert(cursor->current_key[0] == 'W');
47 : 8 : RETURN(cursor->current_key.substr(1));
48 : : }
49 : :
50 : : Xapian::doccount
51 : 8 : FlintSpellingWordsList::get_termfreq() const
52 : : {
53 : : LOGCALL(DB, string, "FlintSpellingWordsList::get_termfreq", NO_ARGS);
54 : : Assert(cursor);
55 : : Assert(!at_end());
56 : : Assert(!cursor->current_key.empty());
57 : : Assert(cursor->current_key[0] == 'W');
58 : 8 : cursor->read_tag();
59 : :
60 : : Xapian::termcount freq;
61 : 8 : const char *p = cursor->current_tag.data();
62 [ - + ]: 8 : if (!F_unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
63 : 0 : throw Xapian::DatabaseCorruptError("Bad spelling word freq");
64 : : }
65 : 8 : return freq;
66 : : }
67 : :
68 : : Xapian::termcount
69 : 0 : FlintSpellingWordsList::get_collection_freq() const
70 : : {
71 : 0 : throw Xapian::InvalidOperationError("FlintSpellingWordsList::get_collection_freq() not meaningful");
72 : : }
73 : :
74 : : TermList *
75 : 13 : FlintSpellingWordsList::next()
76 : : {
77 : : LOGCALL(DB, TermList *, "FlintSpellingWordsList::next", NO_ARGS);
78 : : Assert(!at_end());
79 : :
80 : 13 : cursor->next();
81 [ + + - + ]: 13 : if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
[ - + ]
82 : : // We've reached the end of the prefixed terms.
83 : 0 : cursor->to_end();
84 : : }
85 : :
86 : 13 : RETURN(NULL);
87 : : }
88 : :
89 : : TermList *
90 : 0 : FlintSpellingWordsList::skip_to(const string &tname)
91 : : {
92 : : LOGCALL(DB, TermList *, "FlintSpellingWordsList::skip_to", tname);
93 : : Assert(!at_end());
94 : :
95 [ # # ]: 0 : if (!cursor->find_entry_ge("W" + tname)) {
96 : : // The exact term we asked for isn't there, so check if the next
97 : : // term after it also has a W prefix.
98 [ # # ][ # # ]: 0 : if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
[ # # ]
99 : : // We've reached the end of the prefixed terms.
100 : 0 : cursor->to_end();
101 : : }
102 : : }
103 : 0 : RETURN(NULL);
104 : : }
105 : :
106 : : bool
107 : 13 : FlintSpellingWordsList::at_end() const
108 : : {
109 : : LOGCALL(DB, bool, "FlintSpellingWordsList::at_end", NO_ARGS);
110 : 13 : RETURN(cursor->after_end());
111 : : }
|