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 6789317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:35:22+00:00 2026-05-26T17:35:22+00:00

According to the Search Developers Guide: Each constraint is named, and the name must

  • 0

According to the Search Developers Guide:
Each constraint is named, and the name must be unique across all operators and constraints in your options node.

We are using a content enrichment package that produces output like this:

`<TM360:Measurements Measurements="Distance">
    <Measurements:Distance Amount="3" Unit="inches"/>
</TM360:Measurements>
<TM360:Measurements Measurements="Volume">
    <Measurements:Volume Amount="5.0" Unit="liters"/>
</TM360:Measurements>`

Looking at “Amount”:
The attribute localName is not unique, but the element that contains it is unique.

Is there a way get around the constraint name uniqueness limitation to build a constrained search, say, “Amount: 5.0” that would include the indexes over both entries above?

What is the best way to handle this situation?

  • 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-05-26T17:35:23+00:00Added an answer on May 26, 2026 at 5:35 pm

    You could create a custom constraint to achieve this. I succeeded in doing this using the following three scripts:

    • setup-db.xqy
    • search.xqy
    • custom-constraint.xqy

    Here’s the setup script, which creates the two “Amount” range indexes and adds a couple of sample documents (test1.xml and test2.xml):

    xquery version "1.0-ml";
    
    import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy" ;
    
    declare namespace TM360        = "http://example.com/TM360";
    declare namespace Measurements = "http://example.com/Measurements";
    
    declare function local:make-amount-index($parent-name) {
      admin:database-range-element-attribute-index(
        (: data type       :) "decimal",
        (: parent name     :) "http://example.com/Measurements",$parent-name,
        (: attribute name  :) "", "Amount",
        (: collation       :) "",
        (: value positions :) false()
      )
    };
    
    (: Set up the indexes (or you can add these via the Admin UI) :)
    let $dbid       := xdmp:database(),
        $rangespec1 := local:make-amount-index("Distance"),
        $rangespec2 := local:make-amount-index("Volume"),
        $config     := admin:get-configuration(),
        $config     := admin:database-add-range-element-attribute-index($config, $dbid, $rangespec1),
        $config     := admin:database-add-range-element-attribute-index($config, $dbid, $rangespec2)
    return
      admin:save-configuration($config)
    
    ,
    
    (: Add some sample docs :)
    xdmp:document-insert("/test1.xml",
      <TM360:Measurements Measurements="Distance">
          <Measurements:Distance Amount="3" Unit="inches"/>
      </TM360:Measurements>),
    
    xdmp:document-insert("/test2.xml",
      <TM360:Measurements Measurements="Volume">
          <Measurements:Volume Amount="5.0" Unit="liters"/>
      </TM360:Measurements>)
    

    Below is search.xqy, which makes two searches:

    • search:search("Amount:3",$options)
    • search:search("Amount:5",$options)

    Note in particular the $options node, which defines the custom constraint:

    xquery version "1.0-ml";
    
    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">
        <constraint name="Amount">
          <custom facet="false">
            <parse apply="parse-amount"
                   ns="http://example.com/custom-constraint"
                   at="/custom-constraint/custom-constraint.xqy">
            </parse>
          </custom>
        </constraint>
      </options>;
    
    (: matches test1.xml :)
    search:search("Amount:3",$options),
    
    (: matches test2.xml :)
    search:search("Amount:5",$options)
    

    And finally, here’s the custom-constraint.xqy code, which is what translates the constraint text into a cts OR query across the two Amount indexes:

    xquery version "1.0-ml";
    
    module namespace my = "http://example.com/custom-constraint";
    
    declare namespace Measurements = "http://example.com/Measurements";
    
    declare default function namespace "http://www.w3.org/2005/xpath-functions";
    
    (: Convert the constraint text into an OR query against "Distance" and "Volume" :)
    declare function my:parse-amount($constraint-qtext as xs:string,
                                     $right as schema-element(cts:query))
            as schema-element(cts:query)
    {
      let $value := xs:decimal($right//cts:text)
      return
        <cts:or-query>{
          my:make-amount-query("Distance",$value),
          my:make-amount-query("Volume"  ,$value)
        }</cts:or-query>
    };
    
    
    declare function my:make-amount-query($parent-name, $value) {
      cts:element-attribute-range-query(
        (: parent name    :) QName("http://example.com/Measurements", $parent-name),
        (: attribute name :) xs:QName("Amount"),
        (: operator       :) "=",
        (: value          :) $value
      )
    };
    

    If you want your constraint to function as a facet also, then you’d additionally need to implement the start-facet and finish-facet functions (and augment the definition in your options node accordingly. The Search Developer’s Guide includes an example of how to do this.

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

Sidebar

Related Questions

I am generating user control according to search result. And allowing to change text
According to select name from system_privilege_map System has been granted: SELECT ANY TABLE ...and
According to Google search: since MySQL does not support full outer join, it could
I have to search user according by city but my problem is that in
I've wrote a java code and compiled it. (foo1.6.class) According to my search, my
I am trying to dynamically filter table cell contents according to a search box.
According to the description of the Google Custom Search API you can invoke it
According to my question it is possible to do people search in sharepoint 2010
I am trying to search a table for records according to relevance with search
i want to know the method of the images search according to the main

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.