Opened 16 years ago
Closed 16 years ago
#407 closed defect (fixed)
Explicit "~" does not look for synonym when using FLAG_PARTIAL
| Reported by: | olinux | Owned by: | Olly Betts |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0.17 |
| Component: | QueryParser | Version: | 1.0.16 |
| Severity: | normal | Keywords: | |
| Cc: | Blocked By: | ||
| Blocking: | Operating System: | All |
Description
Query parser does not look for synonyms when FLAG_PARTIAL is combined with FLAG_AUTO_SYNONYMS or FLAG_SYNONYM
Example queries
- hello
- ~hello
- hello world
- ~hello world
- world ~hello
Example
Create database, add synonyms and parse above queries
Problems are indicated by "PROBLEM" in comments below.
// create database
$xapianDatabasePath = '/tmp/xapianSynonymTest';
$db = new XapianWritableDatabase($xapianDatabasePath, Xapian::DB_CREATE_OR_OVERWRITE);
$db->add_synonym('hello', 'hi');
$db->add_synonym('hello', 'howdy');
$db = null;
// run some queries
$db = new XapianDatabase($xapianDatabasePath);
$enquire = new XapianEnquire($db);
$qp = new XapianQueryParser();
$stemmer = new XapianStem('english');
$qp->set_stemmer($stemmer);
$qp->set_database($db);
$xapianFlags = XapianQueryParser::FLAG_BOOLEAN | XapianQueryParser::FLAG_AUTO_SYNONYMS;
echo $xapianFlags . '<br>';
// works as expected
// Xapian::Query((hello:(pos=1) OR hi:(pos=1) OR howdy:(pos=1)))
$query = $qp->parse_query('hello', $xapianFlags);
echo $query->get_description() . '<br>';
// works as expected
// Xapian::Query((hello:(pos=1) OR hi:(pos=1) OR howdy:(pos=1)))
$query = $qp->parse_query('~hello', $xapianFlags);
echo $query->get_description() . '<br>';
// works as expected
// Xapian::Query((hello:(pos=1) OR hi:(pos=1) OR howdy:(pos=1) OR world:(pos=2)))
$query = $qp->parse_query('hello world', $xapianFlags);
echo $query->get_description() . '<br>';
// works as expected
// Xapian::Query((hello:(pos=1) OR hi:(pos=1) OR howdy:(pos=1) OR world:(pos=2)))
$query = $qp->parse_query('~hello world', $xapianFlags);
echo $query->get_description() . '<br>';
$xapianFlags = XapianQueryParser::FLAG_BOOLEAN | XapianQueryParser::FLAG_PARTIAL | XapianQueryParser::FLAG_AUTO_SYNONYMS;
echo $xapianFlags . '<br>';
// works as expected
// Xapian::Query(hello:(pos=1))
$query = $qp->parse_query('hello', $xapianFlags);
echo $query->get_description() . '<br>';
// PROBLEM - EXPLICIT "~" SHOULD FORCE LOOK FOR A SYNONYM
// Xapian::Query(hello:(pos=1))
$query = $qp->parse_query('~hello', $xapianFlags);
echo $query->get_description() . '<br>';
// works as expected
// Xapian::Query((hello:(pos=1) OR hi:(pos=1) OR howdy:(pos=1) OR world:(pos=2)))
$query = $qp->parse_query('hello world', $xapianFlags);
echo $query->get_description() . '<br>';
// works as expected
// Xapian::Query((hello:(pos=1) OR hi:(pos=1) OR howdy:(pos=1) OR world:(pos=2)))
$query = $qp->parse_query('~hello world', $xapianFlags);
echo $query->get_description() . '<br>';
// PROBLEM - EXPLICIT "~" SHOULD FORCE LOOK FOR A SYNONYM
// Xapian::Query((hello:(pos=1) OR hi:(pos=1) OR howdy:(pos=1) OR world:(pos=2)))
$query = $qp->parse_query('world ~hello', $xapianFlags);
echo $query->get_description() . '<br>';
$xapianFlags = XapianQueryParser::FLAG_BOOLEAN | XapianQueryParser::FLAG_PARTIAL | XapianQueryParser::FLAG_SYNONYM;
echo $xapianFlags . '<br>';
// works as expected
// Xapian::Query(hello:(pos=1))
$query = $qp->parse_query('hello', $xapianFlags);
echo $query->get_description() . '<br>';
// PROBLEM - EXPLICIT "~" SHOULD FORCE LOOK FOR A SYNONYM
// Xapian::Query(hello:(pos=1))
$query = $qp->parse_query('~hello', $xapianFlags);
echo $query->get_description() . '<br>';
// works as expected
// Xapian::Query((hello:(pos=1) OR world:(pos=2)))
$query = $qp->parse_query('hello world', $xapianFlags);
echo $query->get_description() . '<br>';
// works as expected
// Xapian::Query((hello:(pos=1) OR hi:(pos=1) OR howdy:(pos=1) OR world:(pos=2)))
$query = $qp->parse_query('~hello world', $xapianFlags);
echo $query->get_description() . '<br>';
Change History (3)
comment:1 by , 16 years ago
| Milestone: | → 1.1.3 |
|---|---|
| Status: | new → assigned |
| Version: | → 1.0.16 |
comment:2 by , 16 years ago
| Milestone: | 1.1.3 → 1.0.17 |
|---|
comment:3 by , 16 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Backported for 1.1.17 in r13613.
Note:
See TracTickets
for help on using tickets.

Under: FLAG_BOOLEAN | FLAG_PARTIAL | FLAG_AUTO_SYNONYMS
// PROBLEM - EXPLICIT "~" SHOULD FORCE LOOK FOR A SYNONYM // Xapian::Query(hello:(pos=1)) $query = $qp->parse_query('~hello', $xapianFlags);I'm not sure I agree here. You didn't pass FLAG_SYNONYM, so the "~" synonym operator isn't enabled, and the "~" is ignored as a spurious character (like "%" would be in "%hello", for example). So this case is handled just as
'hello'is.If you want "~" to be recognised as meaning "synonym this explicitly", I think you should be passing FLAG_SYNONYM. FLAG_AUTO_SYNONYMS could imply FLAG_SYNONYM, but then we lose the flexibility of not having "~" recognised specially.
Similar arguments apply to:
world ~helloThe other cases are fixed in trunk r13611.
Marking for backport to 1.1.17.