[Xapian-discuss] Searching using prefixes

Justin Finkelstein justin at redwiredesign.com
Wed Jul 27 13:01:18 BST 2011


Hi guys

I'm trying to figure out how I can use probabilistic searching on a
given field within a document; I've written to the list about this
before, but haven't quite figured out what's required and, following a
little research, I think I understand what I need to do but I'd like a
clarification on this.

    o We have a database of a number of documents, with fields: title,
subtitle, summary and table of contents
    o By default, we pass these fields into the
TermGenerator::index_text function to generate terms and add these to a
Xapian::Document, applying a weighting where required
    o We then search these fields using XapianQueryParser::parse_query 
    o This gives a result which searches all of the fields for the
required string

I'd like to add the ability to search JUST one on the fields (title, in
this case) so according to the API documentation, here's what I
understand I need to do:

    o When creating the index, call TermGenerator::index_text with the
prefix 'S' (i.e. index_text('some text', 150, 'S')
    o When querying the index, call QueryParser.add_prefix('', 'S')
before calling parse_query with the string I want to use

However, the documentation is a little unclear as to how this actually
works - specifically, how I do a search for multiple words in just the
title. For example, I have a title: "Research into Cheese in China".
With the changes I have made to the indexer, I will have terms for this
both without the S prefix and also WITH the S prefix to allow title-only
searching.

When it comes to searching, I want to be able to take the string "Cheese
in China" as user input and pass this into the QueryParser and have it
perform the search with the 'S' prefix added internally somehow. From
the documentation, it looks like I do this:

    Xapian::QueryParser qp;
    qp.add_prefix("", "S");
    Xapian::Query query = qp.parse_query("Cheese in China");

Is this correct?

Thanks,

Justin

-- 
Redwire Design Limited
 
54 Maltings Place
169 Tower Bridge Road
London SE1 3LJ
www.redwiredesign.com
 
[ 020 7403 1444 ] - voice
[ 020 7378 8711 ] - fax


More information about the Xapian-discuss mailing list