Hi all, I have an implementation question, I have an indexed database, I'm currently using scriptindex and dbi2omega to index and thats working well. However, in the same xapian database, I have various categories for content, can I query the database to ensure that it only returns results of a specific category. i.e. Categories might be: car, bike and bicycle. The user may want to search: "bmw london" and select the car category or "nottingham" and select all categories Is that something that is easy to implement through the Xapian query interface? Or should I be using different xapian databases per category type? Ross
On Wednesday 21 Feb 2007, Ross Lawley wrote:> i.e. Categories might be: car, bike and bicycle. > > The user may want to search: > > "bmw london" and select the car category > or > "nottingham" and select all categories > > Is that something that is easy to implement through the Xapian query > interface? Or should I be using different xapian databases per category > type?I've done something similar by storing metadata as "key:value" terms without any position information, added to the "real" terms from the document; these terms cannot appear as part of real data because of the way I split the data to index. You'd add "category:car" or whatever. Another way is the "add_prefix" and "add_boolean_prefix" QueryParser methods.> Ross-- http://www.lost.eu/175db
On Wed, Feb 21, 2007 at 10:33:10AM +0000, Ross Lawley wrote:> i.e. Categories might be: car, bike and bicycle. > > The user may want to search: > > "bmw london" and select the car category > or > "nottingham" and select all categories > > Is that something that is easy to implement through the Xapian query > interface?Yes, see docs/termprefixes.txt in the Omega documentation for details. Essentially, if the scriptindex input file has a field called "category" your index script would have: category : lowercase boolean=XCAT Then if you're using Omega, you can pass a "B=XCATcar" as a parameter, which you can allow the user to specify in an HTML form with a "<select>" or radio buttons or whatever. You can also set up the QueryParser to allow "category:car" in the query string. Cheers, Olly
Hi all,
I'm still getting there! I've added more indexes for things like the
title
and the description, however, I'm struggling to get a function
boolean_prefix working. I'm using dbi2omega and scriptindex to index the
content and I'm writing a custom PHP class to do the search logic.
My PHP looks something like:
<code>
$xapian_stemmer = new XapianStem("english");
$xapian_query_parser = new XapianQueryParser;
$xapian_query_parser->set_stemmer($xapian_stemmer);
$xapian_query_parser->set_stemming_strategy (0);
$xapian_query_parser->add_prefix("title", "S");
$xapian_query_parser->add_prefix("description", "XDESC");
$xapian_query_parser->add_boolean_prefix("type",
"XTYPE");
$xapian_query_parser->set_database($db);
$xapian_query_parser->set_default_op(XapianQuery::OP_OR);
// Force searching of type:11
// $query = queryparser_parse_query ($xapian_query_parser, 'type:11');
$xapian_query = $xapian_query_parser->parse_query('type:11');
$xapian_enquire->set_query($xapian_query);
$xapian_matchset = $xapian_enquire->get_mset($page, $count);
</code>
My content.index looks like
<code>
id : field=id
title: index=S field=title
type: field=type_id boolean=XTYPE
description: truncate=200 index=XDESC field=content
</code>
However, with that query I never return any results - yet I know there are
items indexed with the XTYPE value of 11. What am I missing? Or more likely
what should I be doing as well?
Also, I'm looping the search terms and expanding them so that a search for
"zulu" would become "title:zulu OR description:zulu" Should
I be doing
that, searching for just "zulu" doesn't return any results.
Also on a side note is there any way to add more weighting to results that
match the title over the description?
Once again many thanks for your help - I'm getting there just need to be
able to use the boolean correctly and I'm away!
Ross