I've managed to use a single filter on xapian with php, but how can I add extra filters? For instance. I have these values for the indexscript: tid : unique=Q boolean=Q field=id title : unhtml weight=10 field=title index=S index category_id : indexnopos=G field=category_id starter_name: unhtml indexnopos=A field=author starter_id: index=XAUTHORID field=authorid last_poster_name: unhtml indexnopos=XLASTAUTHOR field=last_poster_name last_poster_id: field=last_poster_id modtime : field=modtime url : field=url state : field=state ------------------------- When I make a query with 1 filtering, it works fine. This will show all urls with the search term in the category 68: $query_string = $_POST['terms']; $query = $qp->parse_query($query_string); $queryarr[] = new XapianQuery(XapianQuery_OP_FILTER,$query, new XapianQuery('G68')); $query = new XapianQuery(XapianQuery_OP_AND,$query); print "Parsed query is: " . $query->get_description(). "<br/>"; Parsed query is: Xapian::Query((Zandi:(pos=1) FILTER G68)) --------------------------- But what I want is to make a query filtering author, and category_id. 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 XapianQuery('G68')); $queryarr[] = new XapianQuery(XapianQuery_OP_FILTER,$query, new XapianQuery('XAUTHORID5')); $query = new XapianQuery(XapianQuery_OP_AND,$queryarr); print "Parsed query is: " . $query->get_description(). "<br/>"; However, I get no result. Anyone got a clue? ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
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 XapianQuery('G68')); > $queryarr[] = new XapianQuery(XapianQuery_OP_FILTER,$query, new XapianQuery('XAUTHORID5')); > $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.) J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james@tartarus.org uncertaintydivision.org
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@tartarus.org> To: xapian-discuss@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 withauthor 5.> > $query_string = $_POST['terms']; > $query = $qp->parse_query($query_string); > $queryarr[] = new XapianQuery(XapianQuery_OP_FILTER,$query, newXapianQuery('G68'));> $queryarr[] = new XapianQuery(XapianQuery_OP_FILTER,$query, newXapianQuery('XAUTHORID5'));> $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.) J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james@tartarus.org uncertaintydivision.org _______________________________________________ Xapian-discuss mailing list Xapian-discuss@lists.xapian.org http://lists.xapian.org/mailman/listinfo/xapian-discuss ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping
Yes there are documents matching both boolean terms: Using filter G68 gives me 219 results Parsed query is: Xapian::Query((Zandi:(pos=1) FILTER G68)) Using filter XAUTHORID5 gives me 19 results Parsed query is: Xapian::Query((Zandi:(pos=1) FILTER XAUTHORID5)) But on a different subject: If I want to filter at datetime and string, how should I do that? author = "the author" $qarray[] = new XapianQuery('Athe author'); Won't give anything As well: startdate = ">01-01-2008" ----- Original Message ---- From: James Aylett <james-xapian@tartarus.org> To: xapian-discuss@lists.xapian.org Sent: Tuesday, January 8, 2008 10:07:39 PM Subject: Re: [Xapian-discuss] Multiple filters with PHP? How to? On Tue, Jan 08, 2008 at 12:23:59PM -0800, athlon athlonf wrote:> However, I'm not getting any results from the filtering as youdescribed.> This is how the query is eventually parsed (when searching for"andy):> Parsed query is: Xapian::Query((Zandi:(pos=1) FILTER (G68 ANDXAUTHORID5)))> > 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.Do you have documents that match both those boolean terms? Try just searching for the terms directly without the rest of the query.> 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);That looks believable, yes - I just can't remember which options PHP supports :-) J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james@tartarus.org uncertaintydivision.org _______________________________________________ Xapian-discuss mailing list Xapian-discuss@lists.xapian.org http://lists.xapian.org/mailman/listinfo/xapian-discuss ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
Ah, a re-index fixed the filterthing. I guess there was something wrong with my testdata. Now trying to figure out range-filtering. I guess I should write an article about this quest... ----- Original Message ---- From: James Aylett <james-xapian@tartarus.org> To: xapian-discuss@lists.xapian.org Sent: Tuesday, January 8, 2008 10:46:06 PM Subject: Re: [Xapian-discuss] Multiple filters with PHP? How to? On Tue, Jan 08, 2008 at 01:25:15PM -0800, athlon athlonf wrote:> Parsed query is: Xapian::Query((Zandi:(pos=1) FILTER G68)) > Parsed query is: Xapian::Query((Zandi:(pos=1) FILTER XAUTHORID5))What about Xapian::Query(G68 AND XAUTHORID5)?> author = "the author" > $qarray[] = new XapianQuery('Athe author'); > Won't give anythingUmm, you probably want (Athe AND Aauthor)?> As well: startdate = ">01-01-2008"To look at date range selects, see <http://www.xapian.org/docs/valueranges.html>. J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james@tartarus.org uncertaintydivision.org _______________________________________________ Xapian-discuss mailing list Xapian-discuss@lists.xapian.org http://lists.xapian.org/mailman/listinfo/xapian-discuss ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>> author = "the author">This line isn't not valid PHP...Yes, i know. I was actually asking for the xapian equivalent for such a where clause if it were SQL. (select * from documents where author="the author") -> $qarray[] = new XapianQuery('Athe author');>> $qarray[] = new XapianQuery('Athe author'); >> Won't give anything>That creates a query for the *single term* 'Athe author'. > >I'm guessing you want to parse it as a user-entered query? If so, then >use the XapianQueryParser class, like so:>$qp = new XapianQueryParser(); >$qp->add_prefix('author', 'A'); >$qarray[] = $qp->parse_query('author:(the author)');>You can also pass 'A' as the third parameter of parse_query() to setthe>default prefix to 'A' if you have an author text field in your user >interface.Thanks, that is indeed easier. I have a pretty hard time to use the more advanced of xapian due to the lack of examples. I'll write an article about the setup once I've figured more things out. ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ