Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:13:03+00:00 2026-06-13T04:13:03+00:00

I have the two following XML files: Page1.xml <pages xmlns=http://marklogic.com/docs> <page> <elementNode>data1</elementNode> <textNode>text1</textNode> </page>

  • 0

I have the two following XML files:

Page1.xml

<pages xmlns="http://marklogic.com/docs">
  <page>
    <elementNode>data1</elementNode>
    <textNode>text1</textNode>
  </page>
  <page>
    <elementNode>data1</elementNode>
    <textNode>text1</textNode>
  </page>
  <page>
    <elementNode>data3</elementNode>
    <textNode>text3</textNode>
  </page>
  <page>
    <elementNode>data4</elementNode>
    <textNode>text4</textNode>
  </page>
<pages>

Page2.xml

<pages xmlns="http://marklogic.com/docs">
  <page>
    <elementNode>data1</elementNode>
    <textNode>text1</textNode>
  </page>
  <page>
    <elementNode>data2</elementNode>
    <textNode>text3</textNode>
  </page>
  <page>
    <elementNode>data3</elementNode>
    <textNode>text5</textNode>
  </page>
  <page>
    <elementNode>data4</elementNode>
    <textNode>text6</textNode>
  </page>
<pages>

I have created an element range index on “elementNode” and also defined the “page” element as a fragment root. I executed the following xquery with searchText “text1”

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

import module namespace search ="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";

declare variable $options :=  
  <options xmlns="http://marklogic.com/appservices/search">
    <grammar>
      <starter strength="30" apply="grouping" delimiter=")">(</starter>
      <starter strength="40" apply="prefix" element="cts:not-query">NOT</starter>
      <joiner strength="10" apply="infix" element="cts:or-query" tokenize="word">OR</joiner>
      <joiner strength="20" apply="infix" element="cts:and-query" tokenize="word">AND</joiner>
      <joiner strength="50" apply="constraint">:</joiner>
    </grammar>
    <constraint name="elementNode">
      <range collation="http://marklogic.com/collation/" type="xs:string">
        <facet-option>limit=1000</facet-option>
        <element ns="http://marklogic.com/docs" name="elementNode"/>
      </range>
    </constraint>
  </options>;
let $searchResult := search:search("text1", $options)
return $searchResult

After executing the query I got the following response:

<?xml version="1.0" encoding="UTF-8"?>
<search:response total="3" start="1" page-length="10" xmlns="" xmlns:search="http://marklogic.com/appservices/search">
  <search:result index="1" uri="/content/C/Documents and Settings/vimleshm/Desktop/abc.xml" path="fn:doc(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc.xml&quot;)" score="22784" confidence="0.451657" fitness="0.663945">
    <search:snippet>
      <search:match path="fn:doc(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc.xml&quot;)/*:pages/*:page[1]">
        <search:highlight>text1</search:highlight>
      </search:match>
      <search:match path="fn:doc(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc.xml&quot;)/*:pages/*:page[2]">
        <search:highlight>text1</search:highlight>
      </search:match>
    </search:snippet>
  </search:result>
  <search:result index="2" uri="/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml" path="fn:doc(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml&quot;)" score="22784" confidence="0.451657" fitness="0.663945">
    <search:snippet>
      <search:match path="fn:doc(&quot;/content/C/Documents and Settings/vimleshm/Desktop/abc1.xml&quot;)/*:pages/*:page[1]">
        <search:highlight>text1</search:highlight>
      </search:match>
    </search:snippet>
  </search:result>
  <search:facet name="elementNode">
    <search:facet-value name="data1" count="3">data1</search:facet-value>
  </search:facet>
  <search:qtext>text1</search:qtext>
  <search:metrics>
    <search:query-resolution-time>PT0S</search:query-resolution-time>
    <search:facet-resolution-time>PT0.015S</search:facet-resolution-time>
    <search:snippet-resolution-time>PT0S</search:snippet-resolution-time>
    <search:total-time>PT0.015S</search:total-time>
  </search:metrics>
</search:response>

Now as you can see here the “total” attribute of search:response is “3” here because I have defined “page” as a fragment root [Marklogic Wrong count and Facet result Xquery. Is there any way to get the correct total count, which would be “2” here since “text1” exists only in Page1.xml and Page2.xml? Also, I got facet “data2” with count “3”, which should be “2” since it exists in two XML files as in the previous case. Please help me on this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:13:04+00:00Added an answer on June 13, 2026 at 4:13 am

    You can set the fragment root to <pages> (or to nothing, which will default to fragmenting on the root of each XML document), and then there will be 2 hits: one with 2 matches in Page1.xml and one with 1 match in Page2.xml. However, if you set the fragment root to <page> as you have done, search treats each of those elements as its own document, and it will count <page> instead of <pages>.

    Simply, result counts will reflect the number of fragment hits. So the question is really what do you want to count? Documents or <page>s?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two files file a.) xmlFile.xml b.) emails.txt xmlFile.xml has the following structure
The task I'm facing right now is the following: I have two XML files,
Let's say I have the following xml: <one> <two> <three> <three> foo </three> <four
I have the two following text files: First one: chr10 1000 1001 DEL 2.4807
I have two xml files which have the same data but different names for
I'm following two tutorials from Google: http://code.google.com/apis/maps/articles/phpsqlgeocode.html http://code.google.com/apis/maps/articles/phpsqlajax_v3.html#createmap I have the first tutorial working
I have two master pages and a content page. On my local machine this
I have two following rows of code: Microsoft.VisualBasic.Interaction.Beep() or Microsoft.VisualBasic.Beep() The result is the
I am using VB.NET with LINQ to MS SQL. I have two following tables.
I have following two arrays. I want the difference between these two arrays. That

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.