Reputation: 493
I'm using Marklogic8, and our query like below:
query=Color:red,yellow,black AND Size:middle
search options like below:
<options xmlns="http://marklogic.com/appservices/search">
<grammar>
<quotation>"</quotation>
<implicit>
<cts:and-query strength="20" xmlns:cts="http://marklogic.com/cts"/>
</implicit>
<starter strength="30" apply="grouping" delimiter=")">(</starter>
<starter strength="40" apply="prefix" element="cts:not-query" tokenize="word">NOT</starter>
<joiner strength="10" apply="infix" element="cts:or-query" tokenize="word">OR</joiner>
<joiner strength="20" apply="infix" element="cts:and-query" tokenize="word">AND</joiner>
<joiner strength="10" apply="infix" element="cts:or-query">,</joiner>
<joiner strength="50" apply="constraint">:</joiner>
</grammar>
<constraint name="Color"><value><element name="Color" ns="" /></value></constraint>
<constraint name="Size"><value><element name="Size" ns="" /></value></constraint>
</options>
We are using this to parse our query text:
cts:query(search:parse($query, $options)
However, it can't parse the query to correct way:
<cts:or-query xmlns:cts="http://marklogic.com/cts">
<cts:element-value-query>
<cts:element>Color</cts:element>
<cts:text xml:lang="en">red</cts:text>
</cts:element-value-query>
<cts:word-query>
<cts:text xml:lang="en">yellow</cts:text>
</cts:word-query>
<cts:word-query>
<cts:text xml:lang="en">black</cts:text>
</cts:word-query>
<cts:element-value-query>
<cts:element>Size</cts:element>
<cts:text xml:lang="en">middle</cts:text>
</cts:element-value-query>
</cts:or-query>
I know that we can use the input query like below:
query=Color:red OR Color:yellow OR Color:black AND Size:middle
But it's too long.
Is there any possible to cut short our input query?
Upvotes: 2
Views: 89
Reputation: 20414
It might be worth looking into cts:parse. You have to translate your options to bindings yourself (not too difficult), but you'll get a slightly more advanced, and faster parser for your search strings. It allows for amongst others expressions like:
Color = (yellow red black) AND Size:middle
See also: http://docs.marklogic.com/guide/search-dev/cts_query#id_15151
HTH!
Upvotes: 0
Reputation: 7770
The markLogic Search API does not do that. However, you can write a small custom search constraint on the search API to accomplish what you are trying to do. Custom constraints are passed 2 parameters - the information on the left and right sides of the semi-colon. You could then create the proper query to match as you like. You could probably accomplish this by extending the search library as well.
However, it is also something that you can likely take care of in your logic before passing the query to the server.
Upvotes: 3