0

I wanted to compare two queries:

1)

xdmp:plan(fn:distinct-values(/ts:top-song/ts:genres/ts:genre/text(), "http://marklogic.com/collation/en/S1/AS/T00BB"))

2)

declare variable $options :=
<options xmlns="http://marklogic.com/appservices/search">
  <constraint name="genre">
    <range type="xs:string" collation="http://marklogic.com/collation/en/S1/AS/T00BB">
      <element ns="http://marklogic.com/MLU/top-songs" name="genre"/>
    </range>
  </constraint>
</options>;

xdmp:plan(search:search("", $options)/search:facet/search:facet-value)

I have the following questions:

  1. In the result for both the queries I get: Expression is unsearchable. Is this a good thing? Does it mean that indexes are already being used and further indexing cannot be done?

  2. (Range index is enabled for genre) I am guessing fn:distict+Xpath uses range indexes but involves filtering due to the Xpath. OTOH search:search uses only value lexicons, so does it do an unfiltered search? If not, is there a way to find the distinct values in an unfiltered fashion?

James Z
  • 12,209
  • 10
  • 24
  • 44
Yash
  • 510
  • 2
  • 6
  • 14

1 Answers1

4

xdmp:plan does not take an arbitrary expression as its operand: it looks like a function but it really is not. (If you think about it, that must be the case, because if it were a function it would evaluate its arguments first, so it would have no basis for creating the plan.) It is not designed to give you a comparison of two general XQuery expressions, but of the index operations involved in a search or path.

You can only give it either an XPath or a cts:search expression.

So: xdmp:plan(ts:top-song/ts:genres/ts:genre/text())

For search:search there is an option you use to enable it (return-plan)

mholstege
  • 4,902
  • 11
  • 7
  • can you throw some light on the first question ? What does 'expression is unsearchable' mean exactly ? – Yash Jul 22 '17 at 19:31
  • I have used return-plan, which again shows that the query is unsearchable. Why so ? shouldn't both the approached be exploiting range indexes and value-lexicons ? – Yash Jul 23 '17 at 12:36
  • Yes, they should, but you were calling xdmp:plan in an illegal way in both cases. xdmp:plan can't be passed a function call like search:search or distinct-values. When you try to do that you will get that it is unsearchable. – mholstege Jul 24 '17 at 22:32
  • Okay thanks. Can we say that one of them will be more optimized ? – Yash Jul 25 '17 at 08:42
  • to answer Yash. "Unsearchable'" is a marklogic specific term. One that many (including myself) too a while to understand. Its a foundation concept for efficient ML programming so you should spend time researching it. Roughly: ML' implementation of XQuery is 'enhanced' -- not all expressions are equivalent. Some XQuery expressions are 'special', they are understood natively by the compiler and runtime as 'Searchable' - i.e. they can be decomposed into index references and query plans. Not all expressions are 'searchable'. Knowing the difference allows you to understand how to optimize – DALDEI Aug 22 '19 at 11:29