0
votes

I am new to MarkLogic and we are evaluating MarkLogic for our product use case.

We evaluated few NoSQL databases like MongoDB, Couchbase etc.

I am looking for a below type of query search.

(Condition1 OR Condition2) AND (Condition3 OR Condition4) AND (Condition5)

Can MarkLogic provide such type of search query?

I am just started learning MarkLogic and trying to understand the architecture.

Thanks, Sameer

3

3 Answers

2
votes

Yes, MarkLogic provides some high level libraries for this type of functionality. Take a look at Search API.

Start here: https://developer.marklogic.com/learn/2009-07-search-api-walkthrough

And more thorough documentation is here: https://docs.marklogic.com/guide/search-dev/search-api

1
votes

MarkLogic can handle this kind of logic in many ways as mentioned.
For example, this is how you could setup a search query using the CTS library (I highly recommend the CTS library, since it uses indexes much better, and the construction of them are so much more flexible):

cts:search(//elementName,
  cts:and-query((
    cts:element-attribute-value-query(xs:QName("entry"), xs:QName("private"), "true"),
    cts:or-query((
      cts:element-attribute-value-query(xs:QName("entry"), xs:QName("forced"), "false"),
      cts:element-attribute-value-query(xs:QName("entry"), xs:QName("forced"), "pending")
      ))
    ))
  )

This snippet shows both AND and OR logic. The cts:and-query() and cts:or-query() functions can take a list of nodes. The above query says: "Find an element (called elementName) that has an attribute of private='true' AND has either one of the following: forced='true' or forced='pending'".

For much simpler data, you can use xQuery predicates by doing something like the following:

for $node in $xml/parent/child[@param1 eq "test" AND @param2 eq "OK"]/grandchild[@service eq "yahoo" or @service eq "google"]
  return $node
0
votes

The short answer to the original question is "yes". The details of "how" will depend on the approach used to express the queries.

The reference architecture recommends a three-tier approach using the Java or Node.js Client APIs if you use one of those, or HTTP calls to the REST API if you use a different language in your middle tier.

You can also use the Search API (as mentioned by wst) if you're working in MarkLogic's application server (typically as a two-tier architecture). You can do that with either XQuery or Server-side JavaScript, as of MarkLogic 8.