3

The program I am writing needs to execute complex search queries. An example would be

(blue AND jeans AND NOT (cheap || expensive)) . How can I do this. I know there are parameters such as hq and exclude and orTerms (or just the boolean operator), but I don't know how to combine them, or if they can be combined for that matter.

Thanks a bunch

Alkis Kalogeris
  • 17,044
  • 15
  • 59
  • 113

1 Answers1

9

The parameters are described here.

q (string)
The search expression.

exactTerms (string)
Identifies a phrase that all documents in the search results must contain.

excludeTerms (string)
Identifies a word or phrase that should not appear in any documents in the search results.

orTerms (string)
Provides additional search terms to check for in a document, where each document in the search results must contain at least one of the additional search terms.

And the different Boolean Operators are described here.

AND
includeTerms=(phrase%20one).(phrase%20two)

NOT
q=key1%20(-key2)

OR
excludeTerms=key1|key2
orTerms=key1|key2

()
lr=-(lang_fr|lang_it)

By that you could call q=john%20doe&orTerms=wikipedia|imdb and this will result documents containing john AND doe AND ( wikipedia OR imbd ).

Something what I did not expect was q=&exactTerms=(john).(doe).(wikipedia) (46 results) returns the same as q="john%20doe%20wikipedia" (46 results). I thought it would result the same as q="john"%20"doe"%20"wikipedia" (153000 results). So it is sometimes more a CONCAT than an AND operator or exactTerms is simply not able to support multiple keywords.

mgutt
  • 5,867
  • 2
  • 50
  • 77
  • I never checked the xml api since it's for commercial users only, but it seems they offer the same functionality regarding the orTerms. I deleted my answer, since it's not offering much after yours. Feel free to remove the reference you make to my answer – Alkis Kalogeris Mar 25 '15 at 13:48
  • Thx, it's very helpful – Lola Apr 20 '16 at 12:32
  • @mgutt: Do you know if orTerms boost the ranking of the query too? If I include 100 terms in the orTerms, will it rank the document with the most overlapping terms first? – pg2455 Apr 04 '17 at 17:14