2017-03-09 5 views
2

)のみを検索しますが、コードは1つのファイルのみを検索しています。目的を達成するための他の方法はありますか?MarkLogic/Pythonクエリは、Marklogicデータベースからデータをフェッチする1つのファイル(

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")) 

答えて

2
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') 
+0

Reading and Writing Multiple Documents sectionこの機能は、MarkLogic DB内の特定のキーワードを見つけることで私を助けます。 –

+0

これは、特定のコレクションから文書を取得するのに役立ちます。 –

2

コードは検索していないので、明示的に単一の文書を要求しています。

URL:

http://host:port/version/documents?uri=uri-1&uri=uri-2&... 

カール:

$ curl --anyauth --user user:password -X GET -i \ 
    -H "Accept: multipart/mixed; boundary=BOUNDARY" \ 
    'http://host:port/LATEST/documents?uri=uri-1&uri=uri-2' 

一度に複数のドキュメントを取得するには

は、あなたが/documentsエンドポイントに対する要求にURIが含まれるであろう複数のドキュメントを返す場合は、\search RESTエンドポイントを使用してドキュメント間の検索を許可する必要があります。詳しい情報はQuery Features sectionで発見され、REST Application Developer's Guide

関連する問題