[Xapian-discuss] having trouble with prefixes

Olly Betts olly at survex.com
Mon Sep 2 11:09:27 BST 2013


On Sun, Sep 01, 2013 at 10:37:59PM -0400, Christopher Harvey wrote:
> I've got a small test database setup with one record.
> $ delve -r 1 -V /tmp/1/
> Values for record #1: 0:DD4F2162FFFF0E43741A4A1C2B8EC0E7 1:./Text_page_scan_2.jpg 2:jpg 3:.jpg
> Term List for record #1: E:.jpg P:./Text_page_scan_2.jpg Q:DD4F2162FFFF0E43741A4A1C2B8EC0E7 T:jpg
> 
> The terms were added with lines like this:
> 	doc.add_term(string("P:") + path);

Just add the prefix "P" here.

> Problem is, I can't seem to run a query that returns the document using
> any of the terms. Here is the outline of the code that runs the queries
> I'm trying to run:
> 
> 	Database db(db_path.string());
> 	QueryParser queryparser;
> 	Stem stemmer("english");
> 	//queryparser.set_stemmer(stemmer);
> 	queryparser.set_database(db);
> 	queryparser.add_prefix("type", "T");
> 	queryparser.add_prefix("md5sum", "Q");
> 	queryparser.add_prefix("path", "P");

Or if you really want that colon in there, add the prefix as "P:" here.

> 	queryparser.add_prefix("extension", "E");
> 	//maybe set stemming strategy here (in query parser)?
> 	queryparser.set_stemming_strategy(QueryParser::STEM_NONE);
> 	Query query(queryparser.parse_query(full_string));
> 	cout<<"Query is '"<<full_string<<"'"<<endl;

If you print out query.get_description() it should be clearer what's
going on.

Cheers,
    Olly



More information about the Xapian-discuss mailing list