MarkLogic: fn.empty fn.exsits !== null !== ""

MarkLogic: fn.empty fn.exsits !== null !== ""

为了确定 cts.search returns 是否为有效文件,以下语句的最终区别是什么?

1. if (!fn.empty(acctDoc)) {....}
    2. if (!fn.exists(acctDoc)) {....}
    3. if (acctDoc !== null || acctDoc !== "") {...}

我的经验是,No.3各方面都不错。

  1. if (!fn.empty(acctDoc)) {....} Return 如果 acctDoc 不是 空序列 ,则为真。
  2. if (!fn.exists(acctDoc)) {....} Return 如果 acctDoc 是一个空序列 .
  3. 则为真
  4. if (acctDoc !== null || acctDoc !== "") {...} Return 如果 acctDoc 不是 null 或者它不是空字符串,则为真。

fn.empty()

If the value of $arg is the empty sequence, the function returns true; otherwise, the function returns false.

fn.exists()

If the value of $arg is not the empty sequence, the function returns true; otherwise, the function returns false.

使用这个测试函数:

function test(acctDoc) {
  const results = [];
  if (!fn.empty(acctDoc)) { results.push("not empty") };
  if (!fn.exists(acctDoc)) { results.push("does not exist") };
  if (acctDoc !== null || acctDoc !== "") { results.push("not null or is not empty string") };
  return results; 

}

  • test("test") returns ["not empty", "not null or is not empty string"]
  • test("") returns ["not empty", "not null or is not empty string"]
  • test(null) returns ["does not exist", "not null or is not empty string"]
  • test(fn.head(fn.doc())) returns ["not empty", "not null or is not empty string"]
  • test(fn.doc(fn.string(xdmp.random()))) returns ["does not exist", "not null or is not empty string"]