Skip to main content

Develop with FastTrack

Configure a constraint in the query options

After configuring a range index, a constraint in the query options can be configured so that the search application returns facet information for the property in the search results. The query options for the search application can be edited in QConsole. QConsole can be accessed on port 8000 when MarkLogic is running (for example: http://localhost:8000).

To configure a constraint in the query options:

  1. In QConsole, select Modules from the Databases menu, and then click Explore.

  2. Click the document with the URI /Default/App-Services/rest-api/options/search-options.xml and then click Edit.

  3. Replace the XML content for the query options. This XML adds a facet constraint corresponding to the index defined previously.

    <?xml version="1.0" encoding="UTF-8"?>
    <options xmlns="http://marklogic.com/appservices/search">
      <transform-results apply="snippet">
        <per-match-tokens>30</per-match-tokens>
        <max-matches>4</max-matches>
        <max-snippet-chars>200</max-snippet-chars>
      </transform-results>
      <constraint name="status">
        <range type="xs:string" facet="true" collation="http://marklogic.com/collation/codepoint">
          <path-index>/envelope/status</path-index>
          <facet-option>frequency-order</facet-option>
          <facet-option>descending</facet-option>
        </range>
      </constraint>
      <return-facets>true</return-facets>
    </options>
  4. Click Save to save the updated query options.

  5. With the query options updated, MarkLogic will return facet information for the status constraint in the search response. For example:

    {
        "snippet-format": "snippet",
        "total": 3,
        "start": 1,
        "page-length": 10,
        "selected": "include",
        "results": [
            {
                "index": 1,
                "uri": "/person/1001.json",
                "path": "fn:doc(\"/person/1001.json\")",
                "score": 0,
                "confidence": 0,
                "fitness": 0,
                "href": "/v1/documents?uri=%2Fperson%2F1001.json",
                "mimetype": "application/json",
                "format": "json",
                "matches": [
                    {
                        "path": "fn:doc(\"/person/1001.json\")/object-node()",
                        "match-text": [
                            "person Nerta Hallwood Marketing Manager active 1985-03-04 person-1001.jpg"
                        ]
                    }
                ],
                "extracted": {
                    "kind": "array",
                    "content": [
                        {
                            "envelope": {
                                "entityType": "person",
                                "id": 1001,
                                "firstName": "Nerta",
                                "lastName": "Hallwood",
                                "title": "Marketing Manager",
                                "status": "active",
                                "dob": "1985-03-04",
                                "image": "person-1001.jpg",
                            }
                        }
                    ]
                }
            },
            // ...
        ],
        "facets": {
            "status": {
                "type": "xs:string",
                "facetValues": [
                    {
                        "name": "inactive",
                        "count": 2,
                        "value": "Inactive"
                    },
                    {
                        "name": "active",
                        "count": 1,
                        "value": "Active"
                    }
                ]
            }
        },
        // ...
    }