Skip to content

Commit de40bc0

Browse files
author
epriestley
committedOct 27, 2014
Allow standard custom fields to be indexed in global fulltext search
Summary: Fixes T6399. This allows you to use global search to find projects by searching for text in their descriptions. Test Plan: Added a unique word to a project description, reindexed it, searched, got a hit. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6399 Differential Revision: https://secure.phabricator.com/D10748
1 parent 6410d8f commit de40bc0

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed
 

‎src/applications/project/customfield/PhabricatorProjectDescriptionField.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function createFields($object) {
1111
'name' => pht('Description'),
1212
'type' => 'remarkup',
1313
'description' => pht('Short project description.'),
14+
'fulltext' => PhabricatorSearchField::FIELD_BODY,
1415
),
1516
));
1617
}

‎src/docs/user/configuration/custom_fields.diviner

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ When defining custom fields using a configuration option like
102102
defaults to `true`). (Note: Empty fields are not shown.)
103103
- **search**: Show this field on the application's search interface, allowing
104104
users to filter objects by the field value.
105+
- **fulltext**: Index the text in this field as part of the object's global
106+
full-text index. This allows users to find the object by searching for
107+
the field's contents using global search.
105108
- **caption**: A caption to display underneath the field (optional).
106109
- **required**: True if the user should be required to provide a value.
107110
- **options**: If type is set to **select**, provide options for the dropdown

‎src/infrastructure/customfield/field/PhabricatorCustomFieldList.php

-2
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ public function updateAbstractDocument(
339339
}
340340
$field->updateAbstractDocument($document);
341341
}
342-
343-
return $document;
344342
}
345343

346344

‎src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php

+21
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,25 @@ public function getFieldControlID($key = null) {
402402
return 'std:control:'.$key;
403403
}
404404

405+
public function shouldAppearInGlobalSearch() {
406+
return $this->getFieldConfigValue('fulltext', false);
407+
}
408+
409+
public function updateAbstractDocument(
410+
PhabricatorSearchAbstractDocument $document) {
411+
412+
$field_key = $this->getFieldConfigValue('fulltext');
413+
414+
// If the caller or configuration didn't specify a valid field key,
415+
// generate one automatically from the field index.
416+
if (!is_string($field_key) || (strlen($field_key) != 4)) {
417+
$field_key = '!'.substr($this->getFieldIndex(), 0, 3);
418+
}
419+
420+
$field_value = $this->getFieldValue();
421+
if (strlen($field_value)) {
422+
$document->addField($field_key, $field_value);
423+
}
424+
}
425+
405426
}

0 commit comments

Comments
 (0)
Failed to load comments.