1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Create a virtual "core" field in the Ferret engine for "title and body together"

Summary: See PHI46. The `core:` function means "find results in either the title or body, but not other auxiliary fields like comments".

Test Plan: Searched for text present in the title (yes), body (yes), and comments (no) with the `core:...` prefix.

Reviewers: chad

Reviewed By: chad

Differential Revision: https://secure.phabricator.com/D18514
This commit is contained in:
epriestley 2017-09-01 09:27:43 -07:00
parent f4f73e0a7e
commit 577d498033
3 changed files with 23 additions and 1 deletions

View file

@ -6,5 +6,6 @@ final class PhabricatorSearchDocumentFieldType extends Phobject {
const FIELD_BODY = 'body';
const FIELD_COMMENT = 'cmnt';
const FIELD_ALL = 'full';
const FIELD_CORE = 'core';
}

View file

@ -32,6 +32,25 @@ final class PhabricatorFerretFulltextEngineExtension
$stemmer = new PhutilSearchStemmer();
$ngram_engine = id(new PhabricatorNgramEngine());
// Copy all of the "title" and "body" fields to create new "core" fields.
// This allows users to search "in title or body" with the "core:" prefix.
$document_fields = $document->getFieldData();
$virtual_fields = array();
foreach ($document_fields as $field) {
$virtual_fields[] = $field;
list($key, $raw_corpus) = $field;
switch ($key) {
case PhabricatorSearchDocumentFieldType::FIELD_TITLE:
case PhabricatorSearchDocumentFieldType::FIELD_BODY:
$virtual_fields[] = array(
PhabricatorSearchDocumentFieldType::FIELD_CORE,
$raw_corpus,
);
break;
}
}
$key_all = PhabricatorSearchDocumentFieldType::FIELD_ALL;
$empty_template = array(
@ -44,7 +63,7 @@ final class PhabricatorFerretFulltextEngineExtension
$key_all => $empty_template,
);
foreach ($document->getFieldData() as $field) {
foreach ($virtual_fields as $field) {
list($key, $raw_corpus) = $field;
if (!strlen($raw_corpus)) {
continue;

View file

@ -1406,6 +1406,8 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$function_map = array(
'all' => PhabricatorSearchDocumentFieldType::FIELD_ALL,
'title' => PhabricatorSearchDocumentFieldType::FIELD_TITLE,
'body' => PhabricatorSearchDocumentFieldType::FIELD_BODY,
'core' => PhabricatorSearchDocumentFieldType::FIELD_CORE,
);
$current_function = 'all';