如何在Optic API中使用fn:contains(),fn:starts-with()和fn:ends-with [英] How to use fn:contains(), fn:starts-with() and fn:ends-with in Optic API

查看:71
本文介绍了如何在Optic API中使用fn:contains(),fn:starts-with()和fn:ends-with的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更早之前,我们使用FLOWR查询来满足搜索需求,因为数据每天都在增加,所以我们决定使用索引来提高搜索性能.

Earlier we used the FLOWR query to satisfy our search requirement, since data is getting increased day by day so we decided to use Indexing for better search performance.

工作流程查询(仅示例)

for $doc in collection("col1")
where fn:contains($doc//entityName/text(), "USA")
return document-uri($doc)

上面的查询是有效的,它返回一个文档 URI,现在我们正在尝试使用 Optic API 来满足相同的要求.

above query is working and it returns a document URI, Now we are trying to use Optic API to satisfy the same requirement.

我们为 entityName 创建了元素范围索引,但不确定如何将上述FLOWR查询转换为光学查询.

We have created an element range index for entityName but not sure how to convert the above FLOWR query into Optic Query.

与上述FLOWR查询等效的光学查询是什么?,将来我们也计划使用fn:starts-with()和fn:ends-with()函数.

What will be equivalent Optic Query for the above FLOWR query ?, also in future we are planning to use fn:starts-with() and fn:ends-with() functions too.

我们正在使用MarkLogic 10.0-2.1

We are using MarkLogic 10.0-2.1

感谢您的帮助

推荐答案

创建TDE以投影实体属性后,等效的Optic查询将类似于XQuery中的以下内容:

After creating a TDE to project the entity properties, the equivalent Optic query would resemble the following in XQuery:

op:from-view(null, VIEW_NAME, '', op:fragment-id-col('docId'))
=> op:where(ofn:contains(op:col('entityName', 'USA'))
=> op:where(cts:collection-query(COLLECTION_NAME))
=> op:join-doc-uri('uri', op:fragment-id-col('docId'))
=> op:select('uri')
=> op:result()

在XQuery中,必须导入 ofn 库.

In XQuery, the ofn library must be imported.

在SJS中, op.fn 字段提供了等效的功能:

In SJS, the op.fn field provides the equivalent functions:

op.fromView(null, VIEW_NAME, '', op.fragmentIdCol('docId'))
  .where(op.fn.contains(op.col('entityName', 'USA'))
  .where(cts.collectionQuery(COLLECTION_NAME))
  .joinDocUri('uri', op.fragmentIdCol('docId'))
  .select('uri')
  .result()

使用的操作:

  1. fromView()访问实体视图
  2. 在执行查询期间,第一个 where()过滤列的值
  3. 第二个 where()将实体行约束为匹配的源文档
  4. joinDocUri()根据实体行的源文档加入URI词典
  5. select()投影"uri"列,而忽略不需要的视图列.
  1. fromView() accesses the entity view
  2. The first where() filters on the value of the column during query execution
  3. The second where() constrains the entity rows to matching source documents
  4. The joinDocUri() joins the URI lexicon based on the source documents of the entity rows
  5. The select() projects the 'uri' column, ignoring the unneeded view columns.

joinDocUri()方便

.joinInner(
    op.fromLexicons({'uri':cts.uriReference()}, '', op.fragmentIdCol('uriDocId')),
    op.on(op.fragmentIdCol('docId'), op.fragmentIdCol('uriDocId'))
    )

Optic表达式函数还包括 op.fn.startsWith() op.fn.endsWith().通常,光学表达式可以同时使用函数

The Optic expression functions also include op.fn.startsWith() and op.fn.endsWith(). In general, Optic expressions can use a function if it both

  • 是内置的-换句话说,不需要导入或不需要
  • 仅将其输入转换为输出-换句话说,它是纯功能的,没有副作用或环境敏感性

另请参阅以下表达式函数列表:

See also this list of expression functions:

https://docs.marklogic.com/guide/app-dev/OpticAPI#id_69308

希望有帮助,

这篇关于如何在Optic API中使用fn:contains(),fn:starts-with()和fn:ends-with的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆