api/MarkLogic/MLPHP/Search.php
public function retrieveKeyValueElement(
        $element, $attribute, $value, $params = array()
    )
    {
        $this->element = (string)$element;
        $this->attribute = (string)$attribute;
        $this->value = (string)$value;
        // /v1/keyvalue is deprecated, use /v1/search with structured
        // $query = '<query xmlns="http://marklogic.com/appservices/search">
        //             <container-query>
        //               <element name="' . $this->element . '" ns="" />';
        // $query .= $this->attribute ?
        //     '<attribute name=' . $this->attribute . ' ns="" />' :
        //     '';
        // $query .= '<term-query>
        //                 <text>' . $this->value . '</text>
        //               </term-query>
        //             </container-query>
        //           </query>';

        try {
            // Only include attribute in final array if it is set
            $array_attr = (!empty($attribute)) ?
                array('attribute' => $this->attribute) : array();
            $params = array_merge(
                array('element' => $this->element, 'value' => $this->value),
                $array_attr, $this->getParams(), $params);
            $request = new RESTRequest('GET', 'keyvalue', $params);

            $params = array_merge(
                array('element' => $this->element, 'value' => $this->value),
                $array_attr, $this->getParams(), $params);
            // $params = array_merge(
            //     array('structuredQuery' => $query),
            //     $this->getParams(), $params
            // );
            $request = new RESTRequest('GET', 'keyvalue', $params);
            $response = $this->client->send($request);
            $results = new SearchResults($response->getBody());
            return $results;
        } catch(Exception $e) {
            echo $e->getMessage() . ' in ' . $e->getFile() .
            ' on line ' . $e->getLine() . PHP_EOL;
        }
    }
public function retrieveKeyValueElement(
        $element, $attribute, $value, $params = array()
    )
    {
        $this->element = (string)$element;
        $this->attribute = (string)$attribute;
        $this->value = (string)$value;
        // /v1/keyvalue is deprecated, use /v1/search with structured
        // $query = '<query xmlns="http://marklogic.com/appservices/search">
        //             <container-query>
        //               <element name="' . $this->element . '" ns="" />';
        // $query .= $this->attribute ?
        //     '<attribute name=' . $this->attribute . ' ns="" />' :
        //     '';
        // $query .= '<term-query>
        //                 <text>' . $this->value . '</text>
        //               </term-query>
        //             </container-query>
        //           </query>';

        try {
            // Only include attribute in final array if it is set
            $array_attr = (!empty($attribute)) ?
                array('attribute' => $this->attribute) : array();
            $params = array_merge(
                array('element' => $this->element, 'value' => $this->value),
                $array_attr, $this->getParams(), $params);
            $request = new RESTRequest('GET', 'keyvalue', $params);

            $params = array_merge(
                array('element' => $this->element, 'value' => $this->value),
                $array_attr, $this->getParams(), $params);
            // $params = array_merge(
            //     array('structuredQuery' => $query),
            //     $this->getParams(), $params
            // );
            $request = new RESTRequest('GET', 'keyvalue', $params);
            $response = $this->client->send($request);
            $results = new SearchResults($response->getBody());
            return $results;
        } catch(Exception $e) {
            echo $e->getMessage() . ' in ' . $e->getFile() .
            ' on line ' . $e->getLine() . PHP_EOL;
        }
    }
Retrieve the key-value search results, where the key is an element
name, for XML content using the REST client.

@param string $element The element name.
@param string $attribute The attribute for the element, to search for
attribute content.
@param string $value The value for that element (or attribute).
@return SearchResults A search results object.