I’ve been trying to get search to work on my site, but it keeps throwing errors, which are really unhelpful as they suggest that there is a result when I’m guessing there is none.
Here’s what I am trying:
$my_itemRepresentation = $this->api()->search(‘items’, [‘title’=>‘Malaysia’])->getContent();
I’m not a php guru by any stretch, but I am wondering why that returns nothing when this does:
$itemRepresentation = $this->api()->read(‘items’, 655)->getContent();
Am I forced to use the item number?
Also, I am quite frustrated with the lack of working code examples in the documentation. There’s seems to be a lot a built in expectation of expertise that a lot of users won’t have.
The read API method reads one single resource by its identifier. search looks for multiple. The only problem you have here is that there’s no title parameter for the search. Searches limited to a specific property use the key property, which takes a multi-level array allowing for AND/OR boolean searching.
The parameters that the search accepts, including property, are listed in the documentation. In general, the parameters are the same as are used by the advanced search form, so that can also be a convenient way of constructing a query for the search operation.
Ok. Thanks. I think I’m understanding a little more. If had used a valid property rather than a field (in this case dc:title or title) it would have worked as the ID search does.
So then the question is, how do you search by the dcterms:title? It’s not really clear, at least to me, how to search for that in the documentation. I’m guessing this is an RDF full text search?
It would really really help me if you posted an example along with any guidance. It helps me understand the technical documentation which, though thorough, is more general and abstract especially for newbies.
That would search for items whose dcterms:title is exactly “Malaysia”. You can use in as the type instead of eq to find matches where the titles merely contain “Malaysia”.
Oh this is great! Thank you so much! Perfectly clear now. Would love to see more of this sprinkled throughout the documentation. It would really help me wrap my brain around all of it.
Hi @Jovi, I think the reason you get an error in the first example is because the api is returning an array of item representations whereas in the second example the api returns just one.
If you were to loop through the array in the first example, then you’d be able to call the values() method on each item.