Thread:User talk:Mwjames/Providing suggestions to the user while he enters in a "Text" type of field

Hi James,

I am Clément from Dokit.io, a SMW Consulting company.

We're trying to provide suggestions to the user while he enters into a semantic properties "Text" type of field.

The SpecialPage "Search by property" returns all the values for the property but we need to filter the results and only returns those containing what the user typed. So this is what I've done :

$property = SMWDataValueFactory::getInstance->newPropertyValueByLabel(   str_replace( [ '_' ], [ ' ' ], $propname ) );

$requestOptions = new SMWRequestOptions; $requestOptions->sort = true; $requestOptions->setLimit( $limit ); $requestOptions->setOffset( $offset );

if ($query) { $requestOptions->addStringCondition($query, SMWStringCondition::COND_MID); }

but when doing the following query, I get a DB error :

$results = \SMW\StoreFactory::getStore->getPropertyValues( null, $property->getDataItem, $requestOptions );

The error didn't say much but after digging deeper, I found out it was the SQL query that was trigerring a syntax error.

The query looks something like this :

SELECT o_id AS id0, o0.smw_title AS v0, o0.smw_namespace AS v1, o0.smw_iw AS v2, o0.smw_sortkey AS v3, o0.smw_subobject AS v4 FROM `smw_di_wikipage` INNER JOIN `smw_object_ids` AS o0 ON o_id=o0.smw_id WHERE (p_id='523') AND ( AND o_id LIKE '%input%') ORDER BY o_id LIMIT 201

and the problem comes from:

So what's happening here? I'm guessing maybe I'm doing something wrong?! If I remove this line:

the problem goes away. Thanks a lot for your help.