Search code examples
python-2.7python-3.xmarklogicmarklogic-8

MarkLogic/Python query only searches for one file


fetching data from Marklogic database but code is searching only for one file. Is there any other way to achieve the objective

import `http`.`client`

`conn` = `http`.`client`.`HTTPConnection`("127.0.0.1:8040")

headers = {
    'authorization': "Digest `username`=\"root\", realm=\"public\", nonce=\"\", `uri`=\"/v1/documents?`uri`=/scripts/test_insert_2.`json`\", response=\"f5d58bcbccc9119fbf71f851ac4e90f0\", opaque=\"\"",
    'cache-control': "no-cache",
    'postman-token': "52c1f629-5bb9-e16c-5693-16d8d6001e2d"
    }

`conn`.`request`("GET", "/v1/documents?`uri`=%2Fscripts%2Ftest_insert_2.`json`", headers=headers)

res = `conn`.`getresponse`()
data = res.read()

print(data.decode("utf-8"))

Solution

  • def searchkeyword(self, keyword):
        try:
            self.querystring = {"q": keyword}
            url = self.baseUri + "/search"
            self.header = {'Accept': "application/json"}
            resp = requests.get(url, auth=self.auth, params=self.querystring, headers=self.header)
            result = json.loads(resp.content)
            res = []
            fres = []
            for uri in result['results']:
                x = uri['uri']
                if x.__contains__(self.collection):
                    res.append(x)
            for x in res:
                data = x.split('/')
                output = self.FetchData(data[2])
                fres.append(output)
            return fres
        except requests.HTTPError:
            raise RuntimeError('HTTPError occurred while fetching data from file on MarkLogic server')
        except requests.ConnectionError:
            raise RuntimeError('ConnectionError occurred while fetching data from file on MarkLogic server')