root / tags / 1.0.8 / xapian-core / backends / flint / flint_spellingwordslist.cc

Revision 9463, 3.4 kB (checked in by olly, 15 months ago)

common/omassert.h: Rewritten from scratch. The new version only
includes headers if assertions are enabled, which should help
to speed up non-assertion builds by reducing unnecessary header
inclusion. Also, float.h and math.h are never now pulled in -
instead we use the new within_DBL_EPSILON() function. AssertNe?()
and AssertNeParanoid?() are never actually used, so replace them with
AssertRel?() and AssertRelParanoid? which allow the user to assert any
binary relation, not just inequality. Also, we now use rare() to
give branch prediction hints for assertion tests (since the failure
branch should never be taken).
common/omdebug.h,common/stringutils.h,tests/harness/testsuite.h:
Replace several definitions of the STRINGIZE macro with a single
version in common/stringutils.h.
backends/flint/,backends/inmemory/inmemory_database.cc,
backends/multi/multi_postlist.cc,backends/quartz/,
backends/remote/remote-database.cc,bin/quartzcheck.cc,
bin/xapian-compact.cc,common/stringutils.h,expand/expandweight.cc,
expand/ortermlist.cc,matcher/phrasepostlist.cc,
matcher/scaleweightpostlist.cc,net/remoteconnection.cc,
net/tcpserver.cc: Explicitly include headers which were previously
being pulled in implicitly by omassert.h.
HACKING: Update the documentation for assertion calls, and document
CompileTimeAssert?() (which previously wasn't documented here).

  • Property svn:eol-style set to native
Line 
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 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
25#include <xapian/error.h>
26#include <xapian/types.h>
27
28#include "flint_spellingwordslist.h"
29#include "flint_utils.h"
30#include "stringutils.h"
31
32FlintSpellingWordsList::~FlintSpellingWordsList()
33{
34    DEBUGCALL(DB, void, "~FlintSpellingWordsList", "");
35    delete cursor;
36}
37
38Xapian::termcount
39FlintSpellingWordsList::get_approx_size() const
40{
41    DEBUGCALL(DB, Xapian::termcount, "FlintSpellingWordsList::get_approx_size", "");
42    throw Xapian::UnimplementedError("FlintSpellingWordsList::get_approx_size() not implemented");
43}
44
45string
46FlintSpellingWordsList::get_termname() const
47{
48    DEBUGCALL(DB, string, "FlintSpellingWordsList::get_termname", "");
49    Assert(cursor);
50    Assert(!at_end());
51    Assert(!cursor->current_key.empty());
52    Assert(cursor->current_key[0] == 'W');
53    RETURN(cursor->current_key.substr(1));
54}
55
56Xapian::doccount
57FlintSpellingWordsList::get_termfreq() const
58{
59    DEBUGCALL(DB, string, "FlintSpellingWordsList::get_termfreq", "");
60    Assert(cursor);
61    Assert(!at_end());
62    Assert(!cursor->current_key.empty());
63    Assert(cursor->current_key[0] == 'W');
64    cursor->read_tag();
65
66    Xapian::termcount freq;
67    const char *p = cursor->current_tag.data();
68    if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
69        throw Xapian::DatabaseCorruptError("Bad spelling word freq");
70    }
71    return freq;
72}
73
74Xapian::termcount
75FlintSpellingWordsList::get_collection_freq() const
76{
77    throw Xapian::InvalidOperationError("FlintSpellingWordsList::get_collection_freq() not meaningful");
78}
79
80TermList *
81FlintSpellingWordsList::next()
82{
83    DEBUGCALL(DB, TermList *, "FlintSpellingWordsList::next", "");
84    Assert(!at_end());
85
86    cursor->next();
87    if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
88        // We've reached the end of the prefixed terms.
89        cursor->to_end();
90    }
91
92    RETURN(NULL);
93}
94
95TermList *
96FlintSpellingWordsList::skip_to(const string &tname)
97{
98    DEBUGCALL(DB, TermList *, "FlintSpellingWordsList::skip_to", tname);
99    Assert(!at_end());
100
101    if (!cursor->find_entry_ge("W" + tname)) {
102        // The exact term we asked for isn't there, so check if the next
103        // term after it also has a W prefix.
104        if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
105            // We've reached the end of the prefixed terms.
106            cursor->to_end();
107        }
108    }
109    RETURN(NULL);
110}
111
112bool
113FlintSpellingWordsList::at_end() const
114{
115    DEBUGCALL(DB, bool, "FlintSpellingWordsList::at_end", "");
116    RETURN(cursor->after_end());
117}
Note: See TracBrowser for help on using the browser.