diff --git a/src/applications/search/constants/PhabricatorSearchDocumentFieldType.php b/src/applications/search/constants/PhabricatorSearchDocumentFieldType.php index 4dd49e8c92..42fc2738f3 100644 --- a/src/applications/search/constants/PhabricatorSearchDocumentFieldType.php +++ b/src/applications/search/constants/PhabricatorSearchDocumentFieldType.php @@ -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'; } diff --git a/src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php b/src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php index 77599b9d5d..1c9efeba9d 100644 --- a/src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php +++ b/src/applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php @@ -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; diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php index 9e6da1ec00..03d56bc1d2 100644 --- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php +++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php @@ -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';