Hello everyone.. I'm new to using Xapian. I'm having some troubles getting the php querying to work. Apologies, but I have a few different questions to ask and I'm not sure in which way to order them. I'm using php 4.3.9. For starters, does anyone know of some good example php scripts that will do some more advanced querying than is given in the sample "simplesearch.php"? Through some testing and poking around it seems like the easiest solution to get going is to use the QueryParser class.. It seems like the default feature flags it uses are FLAG_BOOLEAN, FLAG_PHRASE and FLAG_LOVEHATE, but you have to specify if you want to use FLAG_BOOLEAN_ANY_CASE or FLAG_WILDCARD. Is that correct? So, the flags I've listed as the default ones all work well, except that all searches only work if I use the stemmed version of the words. Like if I want to search for "discover", I need to use "discov" instead. After finding out the stem I can do combinations with + and -, quotes, AND and OR and it works well. So, my next questions are, why do I have to use the stemmed words instead of their originals when I use QueryParser? Do I need to use the STEM_ALL strategy in order for the QueryParser to convert each word into its stem? I can't get wildcard searching to work, and I'm assuming that's because I need to set FLAG_WILDCARD in the call to parse_query. If that is the case, will I need to set all the previous default flags as well as this one? And now my next problem, which is actually the root of much of my troubles and why I can't test all these ideas out for myself at the time.. This is a two part problem. First, I can't seem to get any of the enum constants to work in my php calls, like STEM_ALL and FLAG_WILDCARD when using QueryParser or OP_AND when using Query. When using the Query class, I have tried using both OP_OR and Query_OP_OR, neither of which work. When using both of these methods, I get the error "No matching function for overloaded 'new_XapianQuery'". Here is the code for that: version 1: $query = new XapianQuery(OP_OR, $terms); version 2: $query = new XapianQuery(Query_OP_OR, $terms); I also tried using the old non-OO method that is distributed in the simplesearch.php script, and that doesn't work at all. I get the message "Call to undefined function: new_query()" for this line of code: $query = new_Query(Query_OP_OR, $terms); So, I'm assuming that v0.9.9 only supports the OO style and not the original function call style new_Query? I can't get any of those functions to work, such as new_Database, new_Enquire and new_Stem... I also tried applying the following patch and recompiling, and I got the same error as before: http://www.oligarchy.co.uk/xapian/patches/xapian-php5-query-ctor-overload-fix.patch Thanks for any assistance.. Sorry for the long post, but all my issues seem all kind of related and I thought it necessary to explain in full... - Matt
This works $op_or = XapianQuery::OP_OR; $query = new XapianQuery($op_or,$query1,$query2); Andrey
some testing codes which is working $db = new XapianDatabase("x/xxx_flint", DB_OPEN); $op_or = XapianQuery::OP_OR; $query1=new XapianQuery(array("term1","term2","term3")); << forgot if correct $query2=new XapianQuery("heavy_term",10); $query = new XapianQuery($op_or,$query1,$query2); $enq = new XapianEnquire($db); $enq->set_query($query); $enq->set_docid_order("Enquire_ASCENDING"); $mset = $enq->get_mset($start, $num_result_per_page); $mseti = $mset->begin(); while (!$mseti->equals($mset->end())) { $result[$i]['terms'] = join(" ", $enq->get_matching_terms($mseti)); $result[$i]['id'] = $mseti->get_docid(); $result[$i]['percent'] =$mseti->get_percent(); $odoc = $mseti->get_document(); $result[$i]['data'] = $odoc->get_data(); $mseti->next(); $i++; }
Matt Barnicle
2007-Feb-08 04:40 UTC
[Xapian-discuss] Re: PHP searches - not figuring it out
I just realized, I posted this with the wrong email address. Not sure if it made it through the list, apologies if it's a duplicate message...> This works > > $op_or = XapianQuery::OP_OR; > $query = new XapianQuery($op_or,$query1,$query2); > > AndreyHi Andrey. Thanks for the example code, I will file it away.. I tried the above also, and it doesn't work. Here is my code: $op_or = XapianQuery::OP_OR; And the error: parse error, unexpected ';', expecting '(' Is this because I'm using PHP 4 and not 5? I thought 4 supported this syntax.. I know it does for method calls, but maybe not for static vars? So otherwise what could be the problem? Compilation? I followed the installation instructions on the site. First installed xapian-core-0.9.9, then xapian-bindings-0.9.9, then omega-0.9.9. In each case, I ran "./configure; make; make install". Everything went fine, no warnings or errors... My compiler details: [gatto@chi01-051-06 software]$ gcc -v Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux Thread model: posix [gatto@chi01-051-06 software]$ g++ -v Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux Thread model: posix gcc version 3.4.6 20060404 (Red Hat 3.4.6-3) - Matt