es.searchOptionsGenerate( model as Object ) as element(search.options)
This function is deprecated and will not be supported in MarkLogic 11.
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 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.// Generate query options from a basic model. const es = require('/MarkLogic/entity-services/entity-services'); es.searchOptionsGenerate( es.modelValidate( { "info": { "title": "Example", "description": "ES Examples", "version": "1.0.0", }, "definitions": { "Name" : { "properties": { "first": { "datatype": "string" }, "middle": { "datatype": "string" }, "last": { "datatype": "string" } }, "required": ["first", "last"] }, "Person": { "properties": { "id": { "datatype": "int" }, "name": { "$ref": "#/definitions/Name", }, "bio": { "datatype": "string" }, "rating": { "datatype": "float" }, "phone": { "datatype": "array", "items": { "datatype": "string"} }, "friend": { "datatype" : "array", "items": { "$ref" : "#/definitions/Person" } } }, "required": ["id", "name"], "primaryKey" : "id", "rangeIndex": ["rating"], "wordLexicon": ["bio"] } }} )); /* Result: XML Query options similar to the following, usable with the * XQuery Search API and the REST, Node.js, and Java Client APIs. <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> */