Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your approach is not as bad as you might think. There are only a few changes necessary to make it work as you like.</p> <p>First of all, you are better off using <code>cts:element-value-query</code> instead of <code>cts:word-query</code>. It will allow you to limit the searched values to a specific element. It performs best when you add an <strong>element range index</strong> for that element, but it is not required. It can rely on the always present word index as well.</p> <p>Secondly, there is no need for the <code>cts:or-query</code>. Both <code>cts:word-query</code> and <code>cts:element-value-query</code> functions (as well as all other related functions) accept multiple search strings as one sequence argument. They are automatically treated as <strong>or-query</strong>.</p> <p>Thirdly, the phone numbers are your '<strong>primary key</strong>' in the result, so returning a list of all matching Phone elements <em>is</em> the way to go. You just need to realize that the resulting Phone element are still aware of where they came from. You can easily use <code>XPath</code> to navigate to parent and siblings.</p> <p>Fourthly, there is nothing against looping over the search results. It may sound a bit weird, but it doesn't cost much extra performance. Actually, it is pretty much negligable, in MarkLogic Server that is. Most performance could be lost when you try to return many results (more than several thousands), in which case most time is lost in serializing it all. And if it is likely you will have to handle lots of search results, it is wise to start using pagination straight away.</p> <p>To get what you ask, you could use the following code:</p> <pre><code>&lt;results&gt;{ for $phone in cts:search( doc()/Person/Phone, cts:element-value-query( xs:QName("Phone"), ("3738494044", "2373839383", "3933849383") ) ) return &lt;match id="{data($phone/../@id)}" phone="{data($phone)}" name="{data($phone/../Name)}" city="{data($phone/../City)}"/&gt; }&lt;/results&gt; </code></pre> <p>Best of luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload