[Xapian-discuss] Searching Within A Specific Field (eg. "title:reading") in PHP

Benny Chan misterchan at gmail.com
Wed Jul 25 17:39:15 BST 2007


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


More information about the Xapian-discuss mailing list