Benny Chan
2007-Jul-25 17:39 UTC
[Xapian-discuss] Searching Within A Specific Field (eg. "title:reading") in PHP
Hello,
I am trying to make my database searchable within a specific field, namely
the title or subject field. Here's how my scriptindex input looks like:
document_id: field=ref unique=Q boolean=Q
document_title: field=title weight=10 unhtml index=S
landing_page: field=landing_page
document_text: field=document_text unhtml index
abstract: field=abstract
category: field=category boolean=XC
Heres what my PHP code looks like;
$query_parser = new_queryparser();
//set the stemmer and turn on the stemming strategy
queryparser_set_stemmer($query_parser, $stemmer);
queryparser_set_stemming_strategy($query_parser, 1);
//set the database
queryparser_set_database($query_parser, $db);
//set prefix so you can search by category
queryparser_add_boolean_prefix($query_parser, "category",
"XC");
//add prefix so you can search within titles
queryparser_add_prefix($query_parser, "title", "S");
$query = queryparser_parse_query($query_parser,
strtolower($_REQUEST["search"]) . $append);
This however returns 0 results when I try something like
"title:reading" I
have also tried replacing
"index=S"
with
"index=XTITLE"
and
queryparser_add_prefix($query_parser, "title",
"S");
with
queryparser_add_prefix($query_parser, "title",
"XTITLE");
but have not made it work. Anyone know what I'm messing up? Thanks for
reading.
Benny
Olly Betts
2007-Sep-04 03:08 UTC
[Xapian-discuss] Searching Within A Specific Field (eg. "title:reading") in PHP
On Wed, Jul 25, 2007 at 12:39:15PM -0400, Benny Chan wrote:> Heres what my PHP code looks like; > > $query_parser = new_queryparser(); > > //set the stemmer and turn on the stemming strategy > queryparser_set_stemmer($query_parser, $stemmer); > queryparser_set_stemming_strategy($query_parser, 1);The flat function interface is deprecated. Also, use symbolic constants rather than the numbers that happen to currently be equivalent. So instead write: $query_parser = new queryparser(); //set the stemmer and turn on the stemming strategy $query_parser->set_stemmer($stemmer); $query_parser->set_stemming_strategy(QueryParser_STEM_SOME);> $query = queryparser_parse_query($query_parser, > strtolower($_REQUEST["search"]) . $append);What's $append? It's almost inevitably a mistake to attempt to manipulate the user's input before feeding it to the QueryParser. If you want to add filters, etc then construct a new Query object from the Query object that the QueryParser builds.> Anyone know what I'm messing up?Not from the information given - everything looks plausible. Try adding this to see what $query is: echo $query->get_description()."\n"; If that looks OK, then use "delve" to see what terms are actually in the database. Cheers, Olly