0
votes

Hello i am new to Querying with MarkLogic 9 in combination with NodeJS and try to use the QBE (Query By Example) as it is mentioned in the example of MarkLogic 9 ( https://docs.marklogic.com/guide/search-dev/qbe ) When i use xquery with the following statement:

xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";

let $items := fn:collection()/scope/item
for $i in $items
  let $sscc := $i/*:transaction/*:sscc/text()
  let $type:= $i/*:transaction/*:type/text()
  let $actorId := $i/*:transaction/*:actorId/text()
  let $device := $i/*:transaction/*:device/text()
  let $ordernummer := $i/*:order/*:orderNumber/text()
  where $ordernummer = 3788888
  return <td>{$sscc}</td>

Which returns 46 correctresult. When i try to do this with QBE with:

exports.postQuery = function(req, res) {


var queryInput = req.body.message
  console.info('Start postQuery!!!')
  console.info(queryInput)
  db.documents.query(
    //qb.where(qb.byExample(
    //  queryInput
    qb.byExample({
      $query: {
        orderNumber: {$word : '3788888'},
        $filtered: true
      },
      $format: 'json'
}))

it returns 10 results instead of 46. It does not mater which order number i use all possibilities shows 10 records. Can you please tell me what i am doing wrong.

The source xml files within MarkLogic are in this format:

<scope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <item>
        <transaction>
            <type>CI</type>
            <sscc>00000379471900000025</sscc>
            <location>4260210630688</location>
            <device>VISTALINK.004</device>
            <date>2017-04-25</date>
            <time>02:15:33</time>
            <gmtOffset>+02:00</gmtOffset>
            <actorId>155081</actorId>
        </transaction>
        <order>
            <orderNumber>3794719</orderNumber>
        </order>
        <load>
            <rti>
                <ean>8714548186004</ean>
                <grai>8003087145481860040019877322</grai>
                <column>2</column>
                <size>
                    <width>1900</width>
                    <height>95</height>
                    <depth>0</depth>
                </size>
                <position>
                    <x>2062,48707520218</x>
                    <y>2015,24337520512</y>
                    <z>0</z>
                </position>
            </rti>
            <rti>
                <ean>8714548106002</ean>
                <grai>8003087145481060020016434653</grai>
                <column>0</column>
                <size>
                    <width>1900</width>
                    <height>95</height>
                    <depth>0</depth>
                </size>
                <position/>
            </rti>
            <rti>
                <ean>8714548186004</ean>
                <grai>8003087145481860040012803719</grai>
                <column>2</column>
                <size>
                    <width>1900</width>
                    <height>95</height>
                    <depth>0</depth>
                </size>
                <position>
                    <x>2064,20629390666</x>
                    <y>2124,57539157396</y>
                    <z>0</z>
                </position>
            </rti>
            <rti>...</rti>
            <rti>...</rti>
            <rti>...</rti>
            <rti>...</rti>
            <rti>...</rti>
        </load>
    </item>
</scope>

Manny thanks

Erik

1

1 Answers

3
votes

Search requests in the MarkLogic client page over the result list. The default page length is 10 results.

To get more results, use the slice method to specify the length. To get all results, you can use the JavaScript MAX_SAFE_INTEGER constant:

qb.where(qb.byExample(...))
  .slice(0, Number.MAX_SAFE_INTEGER)
  .withOptions({search: ['filtered']})

Caveat: the practical approach for a large result set is to page instead of trying to get all of the results at once.

For more information, see:

http://docs.marklogic.com/jsdoc/queryBuilder.html#slice

Hoping that helps,