es:search-options-generate( $model as map:map ) as element(search:options)
This function is deprecated and will be removed in a future release.
Generate a set of query options that can be used to query your entity
instances using several MarkLogic server-side and client APIs.
Parameters | |
---|---|
model | A valid basic entity model. |
The generated query options can be used to query your entity instances using the XQuery Search API, the Server-Side JavaScript JSearch API, or the REST, Java, or Node.js Client APIs. For example, you can use the output of this function as the second argument to the search:search function or in a combined query passed through the REST, Java, or Node.js Client APIs.
You can use the options as-is or customize them. As-is, the options include several constraints and potentially useful default behavior. For example, the options include a constraint named entity-type that differentiates among the various entity types in the model. The options also leverage lexicon and range index definitions in the basic model. The options include the following:
tuples
option encompassing all the range indexesvalues
option for URIsadditional-query
option that limits searches
to just entity instances.extract-document-data
option to return just
entity instance data, without snippets or other metadata.xquery version "1.0-ml"; import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy"; es:search-options-generate( es:model-from-xml( <es:model xmlns:es="http://marklogic.com/entity-services"> <es:info> <es:title>Example</es:title> <es:version>1.0.0</es:version> <es:description>ES Examples</es:description> </es:info> <es:definitions> <Name> <es:properties> <first><es:datatype>string</es:datatype></first> <middle><es:datatype>string</es:datatype></middle> <last><es:datatype>string</es:datatype></last> </es:properties> <es:required>first</es:required> <es:required>last</es:required> </Name> <Person> <es:properties> <id><es:datatype>int</es:datatype></id> <name><es:ref>#/definitions/Name</es:ref></name> <bio><es:datatype>string</es:datatype></bio> <rating><es:datatype>float</es:datatype></rating> <phone> <es:datatype>array</es:datatype> <es:items><es:datatype>string</es:datatype></es:items> </phone> <friend> <es:datatype>array</es:datatype> <es:items><es:ref>#/definitions/Person</es:ref></es:items> </friend> </es:properties> <es:primary-key>id</es:primary-key> <es:required>id</es:required> <es:required>name</es:required> <es:range-index>rating</es:range-index> <es:word-lexicon>bio</es:word-lexicon> </Person> </es:definitions> </es:model> )) (: ==> Search options similar to the following: <search:options xmlns:search="http://marklogic.com/appservices/search"> <search:constraint name="entity-type"> <search:value> <search:element ns="http://marklogic.com/entity-services" name="title"/> </search:value> </search:constraint> <search:constraint name="id"> <search:value> <search:element ns="" name="id"/> </search:value> </search:constraint> <search:constraint name="rating"> <search:range type="xs:float" facet="true"> <search:path-index xmlns:es="http://marklogic.com/entity-services"> //es:instance/Person/rating </search:path-index> </search:range> </search:constraint> <search:constraint name="bio"> <search:word> <search:element ns="" name="bio"/> </search:word> </search:constraint> <search:tuples name="Person"> <search:range type="xs:float" facet="true"> <search:path-index xmlns:es="http://marklogic.com/entity-services"> //es:instance/Person/rating </search:path-index> </search:range> </search:tuples> <!--Uncomment to return no results for a blank search, rather than the default of all results <search:term xmlns:search="http://marklogic.com/appservices/search"> <search:empty apply="no-results"/> </search:term> --> <search:values name="uris"> <search:uri/> </search:values> <!--Change to 'filtered' to exclude false-positives in certain searches--> <search:search-option>unfiltered</search:search-option> <!--Modify document extraction to change results returned--> <search:extract-document-data selected="include"> <search:extract-path xmlns:es="http://marklogic.com/entity-services"> //es:instance/(Name|Person) </search:extract-path> </search:extract-document-data> <!--Change or remove this additional-query to broaden search beyond entity instance documents--> <search:additional-query> <cts:element-query xmlns:cts="http://marklogic.com/cts"> <cts:element xmlns:es="http://marklogic.com/entity-services"> es:instance </cts:element> <cts:true-query/> </cts:element-query> </search:additional-query> <!--To return facets, change this option to 'true' and edit constraints--> <search:return-facets>false</search:return-facets> <!--To return snippets, comment out or remove this option--> <search:transform-results apply="empty-snippet"/> </search:options> :)
xquery version "1.0-ml"; import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; (: Assume the model shown in the previous example, and that the : database is configured with a range index on the rating property. :) let $basic-model := fn:doc("/models/full.json") let $options := es:search-options-generate($basic-model) return search:search("entity-type:Person AND id:kc124 AND rating:5", $options)