Hi all,
I am using xapian to search a products database of a website (currently 382
000 products). I am able to build an index and query it. I was also able
to index separate fields, but I can't find how to combine different parsed
query strings in PHP:
// construct query
$fields = array ('title', 'publisher', 'category',
'subcategory',
'subsubcategory');
$query = array();
foreach ($fields as $field_name) {
$parser = new XapianQueryParser ();
$parser->set_stemmer ($stemmer);
$parser->set_database ($database);
$parser->set_stemming_strategy (XapianQueryParser::STEM_ALL, null,
'X'.strtoupper($field_name));
$query[] = '('.$parser->parse_query ($form[$field_name], null,
'X'.strtoupper($field_name)).')';
}
$query = implode (' AND ', $query);
I have different fields which have each a label, for example XTITLE for the
field 'title'. I use $parser->set_stemming_strategy() to use the
correct
labels for these fields, but I seem to make a mistake with the second
argument for this function. How do I set this FLAG in PHP? Can I set
multiple? Do I have to set a flag? Can I set all flags?
I looked at the API, but I don't seem to find the answer.
Can somebody help me with this?
Thanks,
James Cauwelier
On Fri, Jun 20, 2008 at 03:22:32PM +0200, james cauwelier wrote:> I am using xapian to search a products database of a website (currently 382 > 000 products). I am able to build an index and query it. I was also able > to index separate fields, but I can't find how to combine different parsed > query strings in PHP: > > // construct query > $fields = array ('title', 'publisher', 'category', 'subcategory', > 'subsubcategory'); > $query = array(); > foreach ($fields as $field_name) { > $parser = new XapianQueryParser (); > $parser->set_stemmer ($stemmer); > $parser->set_database ($database); > $parser->set_stemming_strategy (XapianQueryParser::STEM_ALL, null, > 'X'.strtoupper($field_name)); > $query[] = '('.$parser->parse_query ($form[$field_name], null, > 'X'.strtoupper($field_name)).')'; > } > $query = implode (' AND ', $query); > > I have different fields which have each a label, for example XTITLE for the > field 'title'. I use $parser->set_stemming_strategy() to use the correct > labels for these fields, but I seem to make a mistake with the second > argument for this function. How do I set this FLAG in PHP? Can I set > multiple? Do I have to set a flag? Can I set all flags? > I looked at the API, but I don't seem to find the answer.You shouldn't try to configure prefixes using flags and set_stemming_strategy(); instead, use add_prefix(prefix_in_query_string, prefix_in_database): <http://tinyurl.com/6c87fs>. (I believe there is no second argument for set_stemming_strategy(); if the error message you get isn't clear that this is the problem, then please let us know.) J -- /--------------------------------------------------------------------------\ James Aylett xapian.org james at tartarus.org uncertaintydivision.org
On Fri, Jun 20, 2008 at 03:22:32PM +0200, james cauwelier wrote:> $parser->set_stemming_strategy (XapianQueryParser::STEM_ALL, null, > 'X'.strtoupper($field_name));As James says, this only takes one parameter.> $query[] = '('.$parser->parse_query ($form[$field_name], null, > 'X'.strtoupper($field_name)).')';And parse_query()'s second parameter is meant to be a bitmask of flags - `null' isn't a sensible thing to pass there.> $query = implode (' AND ', $query);Umm, XapianQueryParser::parse_query() returns a XapianQuery object, which you can't (usefully) concatenate with a string. To combine XapianQuery objects, stick them all in the array $query, and then: $query = new XapianQuery(XapianQuery::OP_AND, $query); Cheers, Olly