@@ -24,9 +24,9 @@ from marklogic.documents import Document, DefaultMetadata
24
24
25
25
client = Client('http://localhost:8000', digest=('python-user', 'pyth0n'))
26
26
client.documents.write([
27
- DefaultMetadata(permissions={"rest-reader": ["read", "update"]}, collections=["python-example"]),
28
- Document("/doc1.json", {"text": "example one "}),
29
- Document("/doc2.json", {"text": "example two "})
27
+ DefaultMetadata(permissions={"rest-reader": ["read", "update"]}, collections=["python-search- example"]),
28
+ Document("/search/ doc1.json", {"text": "hello world "}),
29
+ Document("/search/ doc2.json", {"text": "hello again "})
30
30
])
31
31
```
32
32
@@ -37,12 +37,12 @@ a search string that utilizes the
37
37
[ the MarkLogic search grammar] ( https://docs.marklogic.com/guide/search-dev/search-api#id_41745 ) :
38
38
39
39
```
40
- # Find documents with the term "example " in them.
41
- docs = client.documents.search("example ")
40
+ # Find documents with the term "hello " in them.
41
+ docs = client.documents.search("hello ")
42
42
assert len(docs) == 2
43
43
44
- # Find documents with the term "one " in them.
45
- docs = client.documents.search("one ")
44
+ # Find documents with the term "world " in them.
45
+ docs = client.documents.search("world ")
46
46
assert len(docs) == 1
47
47
```
48
48
@@ -65,12 +65,12 @@ Examples of a structured query:
65
65
66
66
```
67
67
# JSON
68
- docs = client.documents.search(query={"query": {"term-query": {"text": "example "}}})
68
+ docs = client.documents.search(query={"query": {"term-query": {"text": "hello "}}})
69
69
assert len(docs) == 2
70
70
71
71
# XML
72
72
query = "<query xmlns='http://marklogic.com/appservices/search'>\
73
- <term-query><text>example </text></term-query></query>"
73
+ <term-query><text>hello </text></term-query></query>"
74
74
docs = client.documents.search(query=query)
75
75
assert len(docs) == 2
76
76
```
@@ -79,12 +79,12 @@ Examples of a serialized CTS query:
79
79
80
80
```
81
81
# JSON
82
- query = {"ctsquery": {"wordQuery": {"text": "example "}}}
82
+ query = {"ctsquery": {"wordQuery": {"text": "hello "}}}
83
83
docs = client.documents.search(query=query)
84
84
assert len(docs) == 2
85
85
86
86
# XML
87
- query = "<word-query xmlns='http://marklogic.com/cts'><text>world </text></word-query>"
87
+ query = "<word-query xmlns='http://marklogic.com/cts'><text>hello </text></word-query>"
88
88
docs = client.documents.search(query=query)
89
89
assert len(docs) == 2
90
90
```
@@ -96,15 +96,15 @@ Examples of a combined query:
96
96
options = {"constraint": {"name": "c1", "word": {"element": {"name": "text"}}}}
97
97
query = {
98
98
"search": {"options": options},
99
- "qtext": "c1:example ",
99
+ "qtext": "c1:hello ",
100
100
}
101
101
docs = client.documents.search(query=query)
102
102
assert len(docs) == 2
103
103
104
104
# XML
105
105
query = "<search xmlns='http://marklogic.com/appservices/search'><options>\
106
106
<constraint name='c1'><word><element name='text'/></word></constraint>\
107
- </options><qtext>c1:example </qtext></search>"
107
+ </options><qtext>c1:hello </qtext></search>"
108
108
docs = client.documents.search(query=query)
109
109
assert len(docs) == 2
110
110
```
@@ -116,11 +116,11 @@ more commonly used parameters are available as arguments in the `client.document
116
116
117
117
```
118
118
# Specify the starting point and page length.
119
- docs = client.documents.search("example ", start=2, page_length=5)
119
+ docs = client.documents.search("hello ", start=2, page_length=5)
120
120
assert len(docs) == 1
121
121
122
122
# Search via a collection without any search string.
123
- docs = client.documents.search(collections=["python-example"])
123
+ docs = client.documents.search(collections=["python-search- example"])
124
124
assert len(docs) == 2
125
125
```
126
126
@@ -129,12 +129,12 @@ each matching document:
129
129
130
130
```
131
131
# Retrieve all content and metadata for each matching document.
132
- docs = client.documents.search("example ", categories=["content", "metadata"])
133
- assert "python-example" in docs[0].collections
134
- assert "python-example" in docs[1].collections
132
+ docs = client.documents.search("hello ", categories=["content", "metadata"])
133
+ assert "python-search- example" in docs[0].collections
134
+ assert "python-search- example" in docs[1].collections
135
135
136
136
# Retrieve only permissions for each matching document.
137
- docs = client.documents.search("example ", categories=["permissions"])
137
+ docs = client.documents.search("hello ", categories=["permissions"])
138
138
assert docs[0].content is None
139
139
assert docs[1].content is None
140
140
```
@@ -145,7 +145,7 @@ The `client.documents.search` method provides a `**kwargs` argument, so you can
145
145
normally pass to ` requests ` . For example:
146
146
147
147
```
148
- docs = client.documents.search("example ", params={"database": "Documents"})
148
+ docs = client.documents.search("hello ", params={"database": "Documents"})
149
149
assert len(docs) == 2
150
150
```
151
151
0 commit comments