USAID / USAID-Data-Services

Do you have ideas or requests on how to use or improve USAID's APIs or the data we've opened at usaid.gov/data? Click on the "issues" tab to start a discussion.
22 stars 9 forks source link

DEC API returning incorrect results? #27

Closed markbrough closed 7 years ago

markbrough commented 7 years ago

I ran the following query on the DEC API: https://dec.usaid.gov/api/qsearch.ashx?q=(Documents.Contract_Grant_Number:(AID-388-A-14-00001))&rtype=json

i.e., give me all documents that are tagged with award ID AID-388-A-14-00001 (Bengal Tiger Conservation Activity)

It returns several documents that are related to this award, but also several that are not - they are not tagged with this award ID under Contract_Grant_Number. See for example the fifth result in the above query, which returns documents related to awards AID-388-TO-15-00002 and AID-486-I-14-00001. This document relates to an award also based in Bangladesh, but I don't think it is related to this particular award.

I am not looking at this award for any particular reason, just in order to provide an example of strange results being returned.

Is this expected behaviour or is something weird going on? Thank you!

theLetterM commented 7 years ago

Greetings Mark,

This is current expected behavior from the DEC API.

The feature in question is in the operator used in the search query. contenttype.fieldname:(term) vs. contenttype.fieldname="term" The difference is :() allows a partial match and ="" only allows an exact match with the field you are searching in. In your example, because you use the :() notation the system preformed a partial search and returned results that match or came close to matching the groups of numbers and letters in the contract number. To set the query for an exact match the DEC recommends the ="" notation.

For example: to search the Documents content type for a Summary that contains the phrase "political development":

To do an exact search, use an equals sign (=). Partial matches will not be found:

Here is a link to additional advance search notation supported in the DEC API

markbrough commented 7 years ago

Great - thanks so much for the explanation!