Skip to content

Search Service

isubiker edited this page Oct 15, 2012 · 11 revisions

Search Service

The search service supports queries submitted in two different forms, string queries and structured queries.

Both types of queries can search either XML or JSON documents. They can also query XML that's embedded inside of JSON documents.

String Queries

The string queries allows for direct submission of user entered query strings. These query strings are similar to what you'd see in many recent and popular search interfaces such as Google (eg: "site:marklogic.com xml").

The grammar for the string query supports grouping via parentheses, negation via -, boolean logic via AND, OR and NEAR, phrases via quotes and fielded searches via <field>:<value>. Details info can be found on the string query syntax page.

Structured Queries

If the string queries don't fulfill your needs, the structured queries provide the most flexibility. Structured queries are created by combining together any number of query constructors to describe your search. The constructors are combined together via a JSON format that is documented on the structured query syntax page.

Endpoint Details

  • Endpoint: /search - For querying XML and JSON documents
  • Request type: GET or POST
    • Note: If using POST, the POST body should consist of URL encoded form values. POST variables are supported because structured queries can become quite large and may be more convenient to submit as a POST request.
  • Parameters: (Note: one of stringQuery or structuredQuery must be provided)
    • stringQuery - The string query to be executed
    • structuredQuery - The structured query to be executed
    • orderBy - Specify any range or bucketed range index to order the results by
    • orderDirection - Used in conjunction with orderBy to specify the direction of ordering. Must specify either "ascending" or "descending", defaults to descending.
    • start (integer, default: 1) - The first result to fetch for pagination, eg: 1
    • length (integer, default: 10) - The number of results to return
    • language - The language that the query is written in (eg: 'en', 'de', etc). Only applies to string queries.
    • qualityWeight (decimal, default: 1.0) - Influences how heavily document qualities should weigh in the relevance calculations
    • include (optional) - Can specify what you'd like returned in the search results. Multiple include parameters can be set and accepted values are:
      • content - The original document for the result. This is the default unless snippet is specified.
      • collections - The collections that the document is in
      • properties - The properties on the document
      • permissions - The permissions on the document
      • quality - The quality set for the document
      • snippet - A search result snippet including highlighting with <span class="hit"> elements based on the query
      • highlighting - The content will be highlighted with <span class="hit"> elements based on the query
      • confidence - Include the confidence of the search result (a value from 0 to 1.0)
      • all - returns all of the above options
      • none - just returns the metadata section without any actual results
    • extractPath (optional) - Either a JSON path or a simplified XPath (depending on the content type) that can be used to limit what part(s) of the document are returned
    • applyTransform (optional) - Applies a transform to the content. If an extractPath is also specified, the transform is handed the content specified by the extractPath.
    • collection (optional) - Limit the results to a specific collection. If multiple collection parameters are specified, only documents which are in all of the collections will be returned.
    • underDirectory (optional) - Limit the results to documents that are descendants of the specified directory
    • inDirectory (optional) - Limit the results to documents that are immediate children of the specified directory
    • filtered (optional, boolean, default: false) - Specifies if search results should be filtered or not
    • outputFormat (optional, default: json) - What format the results should be delivered as. Valid formats are xml or json, default is json.
    • txid (optional) - A pre-existing transaction ID in which the search should be performed. See creating transactions for more info. Note: If running in a clustered environment, search requests must be issued to the same host that created the ticket.
  • Returns

For details on the output format, see the search result format page.

Clone this wiki locally