Query persons by full name, company and email

Hey guys, 

I need to query contacts in SuperOffice (contact not as company, but as any kind of client information) on the condition that the query term matches either the contact's full name, company name, or email

As an example, say that my user is searching by query value 'sson'. I would like the following 3 results to be included: 

[{
  "firstName": "Markus",
  "lastName": "Persson",
  "fullName": "Markus Persson",
  "contactName": "Abbott LLC",
  "fullNameWithContact": "Markus Persson (Abbott LLC)",
  "emailAddress": "markus@abbott.io"
},{
  "firstName": "Herman",
  "lastName": "Fay",
  "fullName": "Herman Fay",
  "contactName": "Beatty & Leggesson AB",
  "fullNameWithContact": "Herman Fay (Beatty & Leggesson AB)",
  "emailAddress": "herman@bl.eu"
},{
  "firstName": "Estevan",
  "lastName": "Cronin",
  "fullName": "Estevan Cronin",
  "contactName": "Example Corp",
  "fullNameWithContact": "Estevan Cronin (Example Corp)",
  "emailAddress": "estevan.cronin@yahoooosson.com"
}]


I've found a separate query to search by each of the above conditions, but no query that can query by all 3 at the same time. 

To search by full name, I can query: 
https://sod.superoffice.com/Cust12345/api/v1/Person?$filter=fullName contains 'sson'&$top=10

To search by company name, I can query: 
https://sod.superoffice.com/Cust12345/api/v1/Contact?$filter=name contains 'sson'&$top=10

To search by email, I can query: 
https://sod.superoffice.com/Cust12345/api/v1/Archive/EmailAddress?$filter=emailAddress contains 'sson'&$top=10

Theoretically I could simply run all 3 queries separately, and just show the results in the same list, after I make sure that all entries are distinct. However I have another constraint: my customer is using the company name to filter out results (tag `STOPPED`) for cases where the company is entered twice in SuperOffice, or was closed down. So, in my results, I should not show any entries where the company name contains `STOPPED`.  

For example, this entry should not be included in the results: 

{
  "firstName": "Deja",
  "lastName": "Hand",
  "fullName": "Deja Hand",
  "contactName": "STOPPED Tree AB - company shut down",
  "fullNameWithContact": "Deja Hand (STOPPED Tree AB - company shut down)",
  "emailAddress": "foo@treebar.com"
}


I could filter out these results client-side,but then, if my first 10 results from the email query correspond to contacts with the word `STOPPED` in the company name, I'd need to query the next page of results, and the next, until I get to some results. But, over time, this approach would take longer and longer to answer, and would run unnecessary queries against the SuperOffice database. 

I've tried to only rely on the search by email query, since it includes `fullNameWithContact` in the results, but trying to query by this particular field never seems to have any effect. This query will still return stopped contacts:

https://sod.superoffice.com/Cust12345/api/v1/Archive/EmailAddress?$filter=emailAddress contains 'sson' and fullNameWithContact notContains 'STOPPED'

Any ideas on how I could solve this requirement?

RE: Query persons by full name, company and email

I've managed to find the solution to my problem in the EmailAddress archive. The end query looks like this: 
https://sod.superoffice.com/Cust12345/api/v1/Archive/EmailAddress?$filter=emailAddress contains 'sson' or fullName contains 'sson' or personContact/name contains 'sson'

The secret was in the subfields for `personContact`. They seem to only be available on demand, and not returned, if not specifically mentioned in the `$filter` parameter:
https://sod.superoffice.com/Cust12345/api/v1/Archive/EmailAddress?$filter=emailAddress contains 'sson' or fullName contains 'sson' or personContact/name contains 'sson'&$select=emailAddress,personContact/name,fullName

Also, if you're coming here following the `stop` that I mentioned in my initial post, note that "stop" is an actual property on SuperOffice, which means that my workaround of checking the name of the company is not necessary.

Av: Camelia Smeria 7. des 2020