3
votes

I am trying to learn the OData version 4 protocol and am using the Northwind database to run queries against.

OData 4 introduced the free text search with $search but the queries I've tried all fail.

A couple things I tried (with many variants):

Error message I get is: The query parameter '$search' begins with a system-reserved '$' character but is not recognized.

The official docs don't say much here, and just reference another source for the exact format. However, the format is very cryptic to me...

From the docs, the general idea is http://host/service/Products?$search=blue OR green which seems in line with my examples. So not sure what I'm doing wrong here.

Has anyone successfully used this before and could give me an example? Thanks!

1

1 Answers

4
votes

You got an error message from http://services.odata.org/V4/Northwind/Northwind.svc because this service has not been updated to support $search. ODL began to support $search in version 6.1.0. please check 6.1.0 release notes

From the spec, "The $search system query option restricts the result to include only those entities matching the specified search expression. The definition of what it means to match is dependent upon the implementation." Since the match rule is dependent on the service implementation, the service can determine which property or even properties combinations to match the search expression.

This service http://odatae2etest.azurewebsites.net/demo/DefaultService/ has simply implemented $search, and this service choose to have the first string type property to match the search expression.

So for this service, http://odatae2etest.azurewebsites.net/demo/DefaultService/ProductDetails?$search=snack is actually meant to return ProductDetails whose description contains 'snack'.

Otherwise, $search supports AND, OR, NOT operations.