简体   繁体   English

使用MarkLogic进行AND \\ OR查询搜索(XQuery或同等查询)

[英]AND\OR Query search using MarkLogic (XQuery or equivalent)

I am new to MarkLogic and we are evaluating MarkLogic for our product use case. 我是MarkLogic的新手,我们正在为产品用例评估MarkLogic。

We evaluated few NoSQL databases like MongoDB, Couchbase etc. 我们评估了少数NoSQL数据库,例如MongoDB,Couchbase等。

I am looking for a below type of query search. 我正在寻找以下类型的查询搜索。

(Condition1 OR Condition2) AND (Condition3 OR Condition4) AND (Condition5) (条件1或条件2)与(条件3或条件4)与(条件5)

Can MarkLogic provide such type of search query? MarkLogic可以提供这种类型的搜索查询吗?

I am just started learning MarkLogic and trying to understand the architecture. 我才刚刚开始学习MarkLogic并试图了解该体系结构。

Thanks, Sameer 谢谢,Sameer

Yes, MarkLogic provides some high level libraries for this type of functionality. 是的,MarkLogic为此类功能提供了一些高级库。 Take a look at Search API. 看一下Search API。

Start here: https://developer.marklogic.com/learn/2009-07-search-api-walkthrough 从这里开始: 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 更详尽的文档在这里: https : //docs.marklogic.com/guide/search-dev/search-api

MarkLogic can handle this kind of logic in many ways as mentioned. 如上所述,MarkLogic可以通过多种方式处理这种逻辑。
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库设置搜索查询的方式(我强烈建议CTS库,因为它使用的索引要好得多,并且它们的构造也更加灵活):

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. 此代码段显示了AND和OR逻辑。 The cts:and-query() and cts:or-query() functions can take a list of nodes. cts:and-query()cts:or-query()函数可以获取节点列表。 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'". 上面的查询说:“找到一个属性为private ='true'并且具有以下其中之一的元素(称为elementName):forced ='true'或force ='pending'”。

For much simpler data, you can use xQuery predicates by doing something like the following: 对于更简单的数据,可以通过执行以下操作来使用xQuery谓词:

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

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. 如果您使用JavaNode.js客户端API中的一种,则参考体系结构建议使用三层方法;如果在中间层中使用其他语言,则建议使用HTTP调用REST API

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). 如果您在MarkLogic的应用程序服务器(通常是两层体系结构)中工作,则还可以使用Search API(如wst所述)。 You can do that with either XQuery or Server-side JavaScript, as of MarkLogic 8. 从MarkLogic 8开始,您可以使用XQuery或服务器端JavaScript进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM