[Xapian-discuss] Wildcard Query Help

Colin Bell colinabell at gmail.com
Wed Mar 14 15:39:10 GMT 2007


Hi All

I've got a setting where I would like to do wildcard searches. I see  
that this can only be done with a Xapian::QueryParser and I am  
currently using Xapian::Query.

I tried to change my code over but when I change it to a  
Xapian::QueryParser it stops working. Now out of shear ignorance on  
my part, I've simply spaced my terms in a long string with spaces in  
between in the hopes that the QueryParser sorts them out. this might  
be my failure point. I have tried setting stemming to off etc.

	string matchField = "AUTHOR"; ( I have terms stored as  
"Xterm:AUTHOR:Terry Prachet"
	for (int j = 0; j != allMatchItems.size(); ++j) {
		fieldFilterMatchItems.push_back("Xterm:"+ matchField +":" +  
allMatchItems[j]);
		fieldFilterMatchItemsStr+= "Xterm:"+ matchField +":" + allMatchItems 
[j] + " ";
	}
			
	//THIS WORKS GREAT
	Xapian::Query fieldMatchFilter(Xapian::Query::OP_AND,  
fieldFilterMatchItems.begin(), fieldFilterMatchItems.end());
	if(query.empty()){query = fieldMatchFilter;}
	else{query = Xapian::Query(Xapian::Query::OP_AND, query,  
fieldMatchFilter);}

	//THIS FAILS TO GET ANY RESULTS
	QueryParser fieldTextQp;
	fieldTextQp.set_default_op(Xapian::Query::OP_AND);
	fieldTextQp.set_database(db);
	Xapian::Query fieldMatchFilter = fieldTextQp.parse_query 
(fieldFilterMatchItemsStr, Xapian::QueryParser::FLAG_WILDCARD);
	if(query.empty()){query = fieldMatchFilter;}
	else{query = Xapian::Query(Xapian::Query::OP_AND, query,  
fieldMatchFilter);}


I've also tried this which fails to to return any results

for (int j = 0; j != allMatchItems.size(); ++j) {
	QueryParser fieldTextQp;
	fieldTextQp.set_default_op(Xapian::Query::OP_AND);
	fieldTextQp.set_database(db);
	fieldTextQp.add_prefix(matchField, "Xterm:"+ matchField +":");
	Xapian::Query fieldMatchFilter = fieldTextQp.parse_query 
(allMatchItems[j], Xapian::QueryParser::FLAG_WILDCARD);
	if(query.empty()){query = fieldMatchFilter;}
	else{query = Xapian::Query(Xapian::Query::OP_AND, query,  
fieldMatchFilter);}
}

Any pointers would be appreciated

Thanks

Colin


More information about the Xapian-discuss mailing list