Sebastian
2007-Sep-26 18:32 UTC
[Xapian-discuss] Segmentation fault using XapianDateValueRangeProcessor with php-bindings
Hello !! I'm having a little trouble with Xapian 1.0.2, with php-bindings. I've built two scripts, the indexer with <opened_data> and <closed_date> with YYYYMMDD format: $objDatabase = new XapianWritableDatabase( './test', DB_CREATE_OR_OVERWRITE ); $objDocument = new XapianDocument(); $objDocument->add_value( 1, <opened_date> ); $objDocument->add_value( 1, <closed_date> ); $objDocument->add_posting( <doc_word1>, <word_pos1> ); $objDocument->add_posting( <doc_word2>, <word_pos2> ); ... $objDocument->set_data( <doc_data> ); $objDatabase->add_document( $objDocument ) and the enquirer: $objDatabase = new XapianDatabase( './test' ); $objStemmer = new XapianStem( 'spanish' ); $objEnquire = new XapianEnquire( $objDatabase ); $objParser = new XapianQueryParser(); $objParser->set_database( $objIndexDB ); $objParser->set_stemmer( $objStemmer ); $objParser->add_valuerangeprocessor( new XapianDateValueRangeProcessor(1) ); $objParser->set_default_op( OP_AND ); $objQuery = $objParser->parse_query( <query>, XapianQueryParser::FLAG_BOOLEAN_ANY_CASE ); $objEnquire->set_query( $objQuery ); $objEnquire->set_sort_by_value_then_relevance( 3, False ); $objMatches = $objEnquire->get_mset( 0, 10 ); ... The enquirer scripts hits a 'Segmentation fault' when issuing $objParser->parse_query(), with <query> 'example 20010101..20070101'. It runs OK any query with other words or phrases except a range... When I remove $objParser->add_valuerangeprocessor( ... ) it goes flawless. Any clue ?? Thanks in advance. Sebastian
Olly Betts
2007-Sep-26 23:34 UTC
[Xapian-discuss] Segmentation fault using XapianDateValueRangeProcessor with php-bindings
On Wed, Sep 26, 2007 at 02:32:24PM -0300, Sebastian wrote:> $objParser->add_valuerangeprocessor( new XapianDateValueRangeProcessor(1) );Rewrite this as: $vrp = new XapianDateValueRangeProcessor(1); $objParser->add_valuerangeprocessor( $vrp );> The enquirer scripts hits a 'Segmentation fault' when issuing > $objParser->parse_query(), with <query> 'example 20010101..20070101'. > It runs OK any query with other words or phrases except a range... > When I remove $objParser->add_valuerangeprocessor( ... ) it goes > flawless.The issue is with the object lifetime. With your original code, the PHP XapianDateValueRangeProcessor object is garbage collected after the call to add_valuerangeprocessor, and the underlying C++ object deleted. It's arguably a bug in the bindings, but I'd like to address it in the C++ API because it's annoying there too. We need to come up with a different reference counting approach though, as the one we use for most Xapian classes doesn't allow them to be subclassed by the user. Cheers, Olly