Page MenuHomePhabricator

Create generic technical approach to Augment search result
Closed, ResolvedPublic3 Estimated Story Points



In Order to implement T245674 and T245673, it should be possible to extend the rest search results with the additional fields.

Main requitements:

  • Every field should be optional
  • The value should be filled by extensions if any
  • If no relevant extension loaded, the value should be null

Additional requirements:

  • Reuse of current code (TextExtracts, PageImages) etc, is preferable.
  • List of additional fields should be flexibly pre-defined.

Expected Result

The technical requirements and basic steps should be filed as separate ticket.

Event Timeline


First, don't think that extending SearchEngine with hook is a good idea right now:

  1. SearchEngine is quite complicated and I'm afraid of getting unexpected side effects there.
  2. Different strategies for searching are used. Say SearchHandler combines titles and texts into one array, like below:
	$titleSearch = $searchEngine->searchTitle( $query );
	$textSearch = $searchEngine->searchText( $query );
	$titleSearchResults = $this->getSearchResultsOrThrow( $titleSearch );
	$textSearchResults = $this->getSearchResultsOrThrow( $textSearch );

	$mergedResults = array_merge( $titleSearchResults, $textSearchResults );
	return $this->buildOutputFromSearchResults( $mergedResults );
  1. We have to take into consideration the fact that searchText is used in many places

So we'll need to extend class with functionality that is needed for a few of its clients only. Moreover, having this very generic hook we don't control changes it might perform. Say, unclear how to make sure that they add 'thumbnail' and 'description' fields.

I offer the following instead:

  1. Add additional configuration for SearchHandler that introduces additional possible fields. like $additioanFields = ['description', 'thumbnail'].
  2. Dynamically introduce hooks with names like 'RestSearchResultAugmentDescription', 'RestSearchResultAugmentThumbnail'.
  3. Use the naming convention above to be possible to use
$results = $this->doSearch(...);
foreach( $additioanFields as $field ) {
	$pageIds = $this->getEmptyIds(); // creates an array of [ pageId => null ]
	Hooks::run( 'RestSearchResultAugment' . ucfirst($field), [ &$pageIds ] ); // Proccess hooks. Note that extension will handle hook for the specific field olnly
	$this->augmentResults($results, $field, $pageIds); If nobody handles the hood we simply add $field => null, so it's present in result anyway. 
  1. Implement given hooks in certain extension (TextExtras, PageImage). They're pretty similar to how extensions work now so it will be possible to resue the code without significant dangarous changes.
Peter.ovchyn renamed this task from Create technical approach to Augment search result to Create generic technical approach to Augment search result .Apr 14 2020, 9:40 AM
Peter.ovchyn set the point value for this task to 3.

After call with @daniel we agreed on:
Core changes:

  1. Add 2 hooks (naming TBD on gerrit review): "provideThumbnailsForPages" and "provideDescriptionForPages".
  2. Contract for hooks the following: [ &$pageIds ], where $pageIds is an array of pageId=>null. Provided should amend it setting a value for a certain pageId instead of null.
  3. provideThumbnailsForPages should provide objects of type ThumbnalInfo (exact type or name of class, or whatever it is TBD)
  4. provideDescriptionForPages should provide objects of type string
  5. SearchHandler (or some class in the 'core') should serialize the info provided by hooks in a proper way and augment the proper fields if the results with it.

Extension changes:

  1. Create an implementation of provideThumbnailsForPages in one of the following extensions: PageImages, ...
  2. Create an implementation of provideThumbnailsForPages in one of the following extensions: ShortDescription, TextExtracts etc...
Peter.ovchyn reopened this task as Open.
Peter.ovchyn triaged this task as Medium priority.