Gravatar for martin.duclos@accenture.com

Question by mduclos, Jun 23, 2015 2:55 PM

Wildcards in REST API

Hello

So i need to enable partial search, in Coveo terms will be Wildcards. So test it on the administrator of Coveo, if a put in the search that the coveo admin panel as, for example reque* returns about 400 results witch is correct. Now if i use the rest api and i put this(for example)

coveoinstance/search?@systitle=reque*

This returns me about 24000 resutls.

Any ideas?

Thanks, regads.

2 Replies
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jun 23, 2015 4:55 PM

http://coveoinstance/search?@systitle=reque* is not doing the @systitle=reque* query because there is no q, aq or cq query string parameter. Also, a wildcard field search in CES is not done with the = operator but with the *= operator (see Coveo Query Syntax Reference).

In addition, if you want to do a wildcard query in the basic expression (q query string parameter) on the REST API, you also need to include the wildcards=true query string parameter.

The correct URL for your query would be http://SitecoreInstance/coveo/rest?q=@systitle=reque*&wildcards=true or http://CoveoSearchApiInstance:8080/rest/search?q=@systitle=reque*&wildcards=true

Gravatar for martin.duclos@accenture.com

Answer by mduclos, Jun 25, 2015 5:04 PM

So if i want to search for "medicaid" and i put "caid" in the q parameter, when i put this as q=*caid* with the wildcard=true does not return results.

BTW: When i use this q*=*caid* return all results :S.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jun 26, 2015 10:03 AM

When you use ?q=*caid*&wildcards=true, I bet that you receive not only 0 results but also an exception from the service:

"exception": {
  "code": "NotEnoughLeadingCharsWildcard",
  "context": "*caid*"
}

This indicates that the CES index refused your query because wildcards queries needs to have at least 3 leading characters (configurable in the admin tool) and your query had 0 leading characters before the first * (star) character.

A correct query here would be ?q=med*&wildcards=true.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jun 26, 2015 10:03 AM

The other query ?q*=*caid* is not the correct syntax either. The wildcard advanced field operator (*=) must be used with a field to work. In your example, you use the operator to define the value of the q query string attribute. This is not valid for an URL.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jun 26, 2015 10:04 AM

I did some tests and realized it must also be used with the value enclosed in double quotes and the field must be configured as a facet. I'm sorry for the confusion. I edited my other answer to highlight this. The correct syntax for the wildcard advanced field operator (*=) would be ?q=@field*="*caid*" and this query would work only if @field is a facet field. It can work with multiple * and ? in the value (see Wildcard Match).

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Jun 26, 2015 10:04 AM

There is also the basic wildcard field query, which is done with the = operator and is subject to the same limitations than free text wildcard queries (3 leading characters minimum). The syntax in your case would be ?q=@systitle=med*&wildcards=true.

Gravatar for martin.duclos@accenture.com

Comment by mduclos, Jun 26, 2015 10:36 AM

Thanks for the help!

Ask a question