[Xapian-discuss] Wildcard search?

Olly Betts olly at survex.com
Mon Jul 4 16:03:00 BST 2005

On Mon, Jul 04, 2005 at 02:34:17PM +0200, roki roki wrote:
> is it possible to implement wildcard (at right side) search in xapian?

Yes - create a TermIterator using Database::allterms_begin(), skip_to()
the prefix, then read terms which match the prefix and OR them together
like so:

    TermIterator t = db.allterms_begin();
    Query q;
    while (t != db.allterms_end() && (*t).substr(0, name.size()) == name) {
        if (q.empty()) {
            q = Query(*t, 1, pos);
        } else {
            q = Query(Query::OP_OR, q, Query(*t, 1, pos));

I've just checked this in for the QueryParser class.  Disabled by default
since not everyone will want to allow it - pass
Xapian::QueryParser::FLAG_WILDCARD in the new bitmask parameter to parse_query
to turn it on.


More information about the Xapian-discuss mailing list