Skip to content

Adds a custom constraint for a triple-range-query in MarkLogic, available through mlpm.

License

Notifications You must be signed in to change notification settings

patrickmcelwee/triple-range-constraint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

triple-range-constraint

Summary

This module provides a module to easily create a MarkLogic custom constraint using a triple-range-query. This is helpful when composing a structured query.

Triple range queries return document fragments, and so are helpful for limiting the scope of a search, for example. The use case that inspired this library was to run searches across all documents related to a specific account document. Related documents were marked as related to particular account uris using embedded triples.

Triple range queries are not available out-of-the-box in a structured query (though they can be specified as an additional-query in your search options). They can be included as a custom-constraint-query, which calls arbitrary module code.

Using the additional-query search option is the best method in many cases, but may not be feasible if parts of the query are dynamically constructed client-side. In that case, building up a structured query is often the best solution, and this library allows triple-range-queries to be used in such a strategy.

Installation

This is an mlpm module. See that page for the latest installation directions. This should work:

npm install -g mlpm
mlpm install triple-range-constraint --save
mlpm deploy -H localhost -P 8040 -u admin -p admin

Use as a custom constraint

Add this to your MarkLogic search options (which can be saved on the server):

<search:constraint name="triples">
  <search:custom facet="false">
    <search:parse apply="query" ns="http://marklogic.com/constraint/triple-range-constraint" at="/ext/mlpm_modules/triple-range-constraint/triple-range-constraint.xqy"/>
  </search:custom>
</search:constraint>

As part of your structured query, you can now include something like this:

'custom-constraint-query': {
  'constraint-name': 'triples',
  'predicate': 'http://marklogic.com/relatesTo',
  'object': '/uri/something-I-care-about.json'
}

or, in XML:

<custom-constraint-query>
  <constraint-name>triples</constraint-name>
  <predicate>http://marklogic.com/relatesTo</predicate>
  <object>/uri/something-I-care-about.xml</object>
</custom-constraint-query>

Note that subject, predicate, and object are all optional, depending on what kind of triple-range-query you need. You can also pass in several subjects, predicates, or objects, which matches the function signature for cts:triple-range-query.

'custom-constraint-query': {
  'constraint-name': 'triples',
  'predicate': 'http://marklogic.com/relatesTo',
  'object': ['/uri/something-I-care-about.json', '/uri/something-else.json']
}
<custom-constraint-query>
  <constraint-name>triples</constraint-name>
  <predicate>http://marklogic.com/relatesTo</predicate>
  <object>/uri/something-I-care-about.xml</object>
  <object>/uri/something-else.xml</object>
</custom-constraint-query>

If you need to enter a string, or other data type, use a JSON object or XML child elements:

'custom-constraint-query': {
  'constraint-name': 'triples',
  'predicate': 'http://marklogic.com/relatesTo',
  'object': {
    'value': 'some string',
    'datatype': 'http://www.w3.org/2001/XMLSchema#string'
  }
}
<search:custom-constraint-query xmlns:search="http://marklogic.com/appservices/search">
  <search:constraint-name>triples</search:constraint-name>
  <search:predicate>http://marklogic.com/relatesTo</search:predicate>
  <search:object>
    <search:value>some string</search:value>
    <search:datatype>http://www.w3.org/2001/XMLSchema#string</search:datatype>
  </search:object>
</search:custom-constraint-query>

(Note that this XML version, is slightly different from the syntax for an embedded triple, which uses a @datatype attribute. If you have a use case for the embedded triple syntax, please file an issue.)

About

Adds a custom constraint for a triple-range-query in MarkLogic, available through mlpm.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages