[Xapian-discuss] some problems and prefixes

Rafi webdeveloper at poczta.onet.pl
Sat Jun 20 08:55:43 BST 2009


Hello Olly,

Thank for your reply.

Friday, June 19, 2009, 9:17:57 AM, you wrote:

OB> On Fri, Jun 19, 2009 at 12:03:46AM +0200, Rafi wrote:
>> $database = new XapianWritableDatabase(XAPIAN_DB_FILE, Xapian::DB_CREATE_OR_OVERWRITE );
OB> Um, what's XAPIAN_DB_FILE?
this is defined path do database (its should sound XAPIAN_DB_PATH :))

OB> Sounds very odd, but I've no idea what's going on.  I think you'll need
OB> to show us a self-contained example which demonstrates this behaviour.

ok, this is how Im doing (this is only a general example for testing
purposes):

    $database = new XapianWritableDatabase(XAPIAN_DB_FILE, Xapian::DB_CREATE_OR_OPEN);
    $o_Magazyn->getProductForIndexer($database);
//    $database->flush();
    $database = null;

and function  getProductForIndexer looks like:

function getProductForIndexer($xapian_db, $limit=100, $offset=0) {

        $q = "SELECT * FROM $this->product WHERE deleted=? ORDER BY p.id LIMIT ! OFFSET !";
        $res = $this->dbh->getAll($q, array('f', $limit, $offset));
        errorSql($res);

        $indexer = new XapianTermGenerator();
        $stemmer = new XapianStem("none");
        $indexer->set_stemmer($stemmer);

        $iID = 0;
        $iTITLE = 1;
        $iOPIS = 2;

        if (!empty($res)) {
            foreach ($res as $value) {
                $opis = strip_tags($value['opis']);
                $opis = preg_replace('/(\s+)/', ' ', strtolower($opis));

                $doc = new XapianDocument();
                $doc->set_data($opis);
                $indexer->set_document($doc);
                $indexer->index_text($value['shopid'], 2, 'shopid');
                $indexer->index_text($opis);
                $doc->add_term('XC'.$value['pid']);

                $doc->add_value($iID, $value['pid']);
                $doc->add_value($iTITLE, $value['name_long']);
                $doc->add_value($iOPIS, $opis);
                $did = $xapian_db->add_document($doc);

            }
            $this->getProductForIndexer($xapian_db, $limit, $offset+100);
        } else {
            return true;
        }
    }

OB> On Fri, Jun 19, 2009 at 01:56:36AM +0200, Rafi wrote:
>> creatign term eg: XC:category

OB> Or just XCcategory...

>> quering for: XC:category
>> add_prefix('shopid', 'XC');
>> 
>> and then users can search by typing:
>> 
>> shopid:23 just like in google site:host.com :)

OB> Yes, though for a filter term like this add_boolean_prefix() makes more
OB> sense than add_prefix() - the latter is for "free text" prefixes.

Do you mean, that add_prefix() I should use for example II in my
previous post and add_boolean prefix for example I?



-- 
Best regards,
 Rafi                            mailto:webdeveloper at poczta.onet.pl




More information about the Xapian-discuss mailing list