[Xapian-discuss] Multiple filters with PHP? How to?

athlon athlonf athlonkmf at yahoo.com
Tue Jan 8 20:23:59 GMT 2008

Ah, thank you. That actually make sense.
However, I'm not getting any results from the filtering as you described.
This is how the query is eventually parsed (when searching for "andy):
Parsed query is: Xapian::Query((Zandi:(pos=1) FILTER (G68 AND XAUTHORID5)))

When simply using filter the filters indivdually I'd get hundreds of results, but when combined in an AND-clause they don't work anymore.

BTW. I've tried your hints a bit, I think that when I need to add more filters, this might should be the correct way? It does give the same parsed query.

$qarray[] = new XapianQuery('G68');
$qarray[] = new XapianQuery('XAUTHORID5');

$filter = new XapianQuery(XapianQuery_OP_AND, $qarray);
$query = new XapianQuery(XapianQuery_OP_FILTER, $probquery, $filter);

----- Original Message ----
From: James Aylett <james-xapian at tartarus.org>
To: xapian-discuss at lists.xapian.org
Sent: Tuesday, January 8, 2008 8:20:10 PM
Subject: Re: [Xapian-discuss] Multiple filters with PHP? How to?

On Tue, Jan 08, 2008 at 10:59:42AM -0800, athlon athlonf wrote:

> I tried this and expect to have the results on category 68 with
 author 5. 
> $query_string = $_POST['terms'];
> $query = $qp->parse_query($query_string);
> $queryarr[] = new XapianQuery(XapianQuery_OP_FILTER,$query, new
> $queryarr[] = new XapianQuery(XapianQuery_OP_FILTER,$query, new
> $query = new XapianQuery(XapianQuery_OP_AND,$queryarr);
> print "Parsed query is: " . $query->get_description(). "<br/>";

You don't really want to do it that way round; you've constructed a
query (or tried to) that has two sides ANDed together, each filtering
the initial query through one of your boolean terms. Instead, you want
to filter the query through an AND of your boolean terms. Something
like (forgive the probably inaccurate PHP):

$query_string = $_POST['terms'];
$probquery = $qp->parse_query($query_string);
$filter = new XapianQuery(XapianQuery_OP_AND, new XapianQuery('G68'),
new XapianQuery('XAUTHORID5'));
$query = new XapianQuery(XapianQuery_OP_FILTER, $probquery, $filter);
print "Parsed query is: " . $query->get_description(). "<br/>";

(There may be a way of doing that faster by constructing the $filter
without intemediate XapianQuery objects, but I can't remember what's
available in the PHP bindings.)


  James Aylett                                                
  james at tartarus.org                              

Xapian-discuss mailing list
Xapian-discuss at lists.xapian.org

Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping

More information about the Xapian-discuss mailing list