Skip to content

Commit

Permalink
Merge pull request #141 from thiemowmde/aliases
Browse files Browse the repository at this point in the history
Fix aliases output in wbsearchentities
  • Loading branch information
addshore committed Aug 26, 2015
2 parents 0102aee + 8c8c1d6 commit f8641a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/PropertySuggester/GetSuggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ private function querySearchApi( $resultSize, $search, $language ) {
'search' => $search,
'action' => 'wbsearchentities',
'language' => $language,
'uselang' => $language,
'type' => Property::ENTITY_TYPE
)
);
Expand Down
12 changes: 11 additions & 1 deletion src/PropertySuggester/ResultBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,14 @@ private function buildEntry( EntityId $id, array $clusteredTerms, Suggestion $su
break;
}
}
if ( !isset($entry['label'] ) ) {

if ( !isset( $entry['label'] ) ) {
$entry['label'] = $id->getSerialization();
} elseif ( preg_match( $this->searchPattern, $entry['label'] ) ) {
// No aliases needed in the output when the label already is a successful match.
unset( $entry['aliases'] );
}

return $entry;
}

Expand All @@ -141,6 +146,11 @@ private function clusterTerms( array $terms ) {
* @param TermIndexEntry $term
*/
private function checkAndSetAlias( array &$entry, TermIndexEntry $term ) {
// Do not add more than one matching alias to the "aliases" field.
if ( !empty( $entry['aliases'] ) ) {
return;
}

if ( preg_match( $this->searchPattern, $term->getText() ) ) {
if ( !isset( $entry['aliases'] ) ) {
$entry['aliases'] = array();
Expand Down

0 comments on commit f8641a6

Please sign in to comment.