Jdouglas has uploaded a new change for review. https://gerrit.wikimedia.org/r/201350
Change subject: Improve highlighting for phrase_prefix queries ...................................................................... Improve highlighting for phrase_prefix queries This partially addresses https://phabricator.wikimedia.org/T93014 to enable highlighting in the title, etc., as well as for compound searches including things other than phrase_prefix queries: * Use full text search fields rather than just `all.plain` * Use a highlight_query whenever making a phrase_prefix query Change-Id: I80cbd3c7daacad8680f2a32ab91fac12d915a7ed --- M includes/Searcher.php 1 file changed, 16 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/50/201350/1 diff --git a/includes/Searcher.php b/includes/Searcher.php index 2c0ba8a..7b9a3af 100644 --- a/includes/Searcher.php +++ b/includes/Searcher.php @@ -575,9 +575,10 @@ if ( !$negate && !isset( $matches[ 'fuzzy' ] ) && !isset( $matches[ 'slop' ] ) && preg_match( '/^"([^"*]+)[*]"/', $main, $matches ) ) { - $phraseMatch = new Elastica\Query\Match( ); - $phraseMatch->setFieldQuery( "all.plain", $matches[1] ); - $phraseMatch->setFieldType( "all.plain", "phrase_prefix" ); + $phraseMatch = new Elastica\Query\MultiMatch( ); + $phraseMatch->setQuery( $matches[1] ); + $phraseMatch->setFields( $this->buildFullTextSearchFields( 1, '.plain', false ) ); + $phraseMatch->setType( 'phrase_prefix' ); $this->nonTextQueries[] = $phraseMatch; return array( ); } @@ -960,6 +961,18 @@ return $field[ 'type' ] !== 'plain'; }); } + if ( sizeof( $this->nonTextQueries ) > 0 ) { + // We have some phrase_prefix queries, so let's include them in the + // generated highlight_query. + $bool = new \Elastica\Query\Bool(); + if ( $this->highlightQuery ) { + $bool->addShould( $this->highlightQuery ); + } + foreach ( $this->nonTextQueries as $nonTextQuery ) { + $bool->addShould( $nonTextQuery ); + } + $this->highlightQuery = $bool; + } if ( $this->highlightQuery ) { $highlight[ 'highlight_query' ] = $this->highlightQuery->toArray(); } -- To view, visit https://gerrit.wikimedia.org/r/201350 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I80cbd3c7daacad8680f2a32ab91fac12d915a7ed Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: Jdouglas <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
