1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

In Ferret, allow documents with no title to match query terms by using LEFT JOIN on the "title" ranking field

Summary:
Fixes T13345. See D20650. Currently, `PhabricatorCursorPagedPolicyAwareQuery` does a JOIN against the "title" field so it can apply additional ranking/ordering conditions to the query.

This means that documents with no title (which don't have this field) are always excluded from the result set.

We'd prefer to include them, just not give them any bonus ranking/relevance boost. Use a LEFT JOIN so they get included.

Test Plan:
  - Applied D20650 (diff 1), made it use raw `getTitle()` as the document title, indexed a paste with no title.
  - Searched for a term in the paste body.
  - Before change: no results.
  - After change: found result.

{F6601159}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13345

Differential Revision: https://secure.phabricator.com/D20660
This commit is contained in:
epriestley 2019-07-18 10:19:03 -07:00
parent 17caecdda3
commit cb4add3116

View file

@ -1825,6 +1825,11 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$table_map['rank'] = array(
'alias' => 'ft_rank',
'key' => PhabricatorSearchDocumentFieldType::FIELD_TITLE,
// See T13345. Not every document has a title, so we want to LEFT JOIN
// this table to avoid excluding documents with no title that match
// the query in other fields.
'optional' => true,
);
$this->ferretTables = $table_map;
@ -2103,10 +2108,17 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
foreach ($this->ferretTables as $table) {
$alias = $table['alias'];
if (empty($table['optional'])) {
$join_type = qsprintf($conn, 'JOIN');
} else {
$join_type = qsprintf($conn, 'LEFT JOIN');
}
$joins[] = qsprintf(
$conn,
'JOIN %T %T ON ft_doc.id = %T.documentID
'%Q %T %T ON ft_doc.id = %T.documentID
AND %T.fieldKey = %s',
$join_type,
$field_table,
$alias,
$alias,