Page MenuHomePhabricator

The autocomplete feature fails for tokens fields populated with a concept
Closed, ResolvedPublic

Description

Hello,

I have a field with the following definition:

{{{field|Cultures|input type=tokens|values from concept=Production_types|delimiter=@}}}

The concept has about 230 items.

When I try to complete the form, the autocomplete fails to return any useful result.

The reasons comes from line 435 of includes/PF_ValuesUtils.php:

  $query = new SMWQuery( $desc );
> $query->setLimit( self::getMaxValuesToRetrieve( $substring ) );
  $query_result = $store->getQueryResult( $query );

When $substring is not null, getMaxValuesToRetrieve returns 20 - the thing is that $substring is not yet part of the query, it's only after this query is performed that $substring is tested against the results. Therefore the first query returns only 20 items, which are tested against the $substring which then basically fails to be useful...

One fix could be to remove $substring from the call: self::getMaxValuesToRetrieve(), another fix could be to add $substring to the query instead of filtering later (don't know if it is possible).

Event Timeline

What about just removing that $query->setLimit() line altogether? Does it work in that case? Or does a limit need to be set?

Good question. If the limit is there to keep the suggestions in shape, maybe it should be set not in the query as you suggest, but later to truncate the resultset after filtering with the substring... That way, the default limit (20) should be applied so that we don't return 3000 hits through ajax

Alright. It looks like two easy solutions exist: removing $substring from the getMaxValuesToRetrieve() call, or removing the setLimit() call altogether. Have you tried either one on your wiki? Do you know for sure if either one works? Is one better than the other?

Change #1087236 had a related patch set uploaded (by Yaron Koren; author: Yaron Koren):

[mediawiki/extensions/PageForms@master] Fix autocomplete with "values from concept"

https://gerrit.wikimedia.org/r/1087236

Change #1087236 merged by jenkins-bot:

[mediawiki/extensions/PageForms@master] Fix autocomplete with "values from concept"

https://gerrit.wikimedia.org/r/1087236

Yaron_Koren claimed this task.

@BertrandGorge - thanks for the fix! I checked in this code - I assume this issue can be closed now.