Skip to content

Commit 655deac

Browse files
committed
Making the search docs examples work
They weren't working if you went through the reading examples first.
1 parent 1ff0707 commit 655deac

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

docs/managing-documents/reading.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ normally pass to `requests`. For example:
9797
```
9898
uris = ["/doc1.json", "/doc2.xml", "/doc3.bin"]
9999
docs = client.documents.read(uris, params={"database": "Documents"})
100-
assert len(docs) == 2
100+
print(docs)
101101
```
102102

103103
## Error handling

docs/managing-documents/searching.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ from marklogic.documents import Document, DefaultMetadata
2424
2525
client = Client('http://localhost:8000', digest=('python-user', 'pyth0n'))
2626
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"})
3030
])
3131
```
3232

@@ -37,12 +37,12 @@ a search string that utilizes the
3737
[the MarkLogic search grammar](https://docs.marklogic.com/guide/search-dev/search-api#id_41745):
3838

3939
```
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")
4242
assert len(docs) == 2
4343
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")
4646
assert len(docs) == 1
4747
```
4848

@@ -65,12 +65,12 @@ Examples of a structured query:
6565

6666
```
6767
# JSON
68-
docs = client.documents.search(query={"query": {"term-query": {"text": "example"}}})
68+
docs = client.documents.search(query={"query": {"term-query": {"text": "hello"}}})
6969
assert len(docs) == 2
7070
7171
# XML
7272
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>"
7474
docs = client.documents.search(query=query)
7575
assert len(docs) == 2
7676
```
@@ -79,12 +79,12 @@ Examples of a serialized CTS query:
7979

8080
```
8181
# JSON
82-
query = {"ctsquery": {"wordQuery": {"text": "example"}}}
82+
query = {"ctsquery": {"wordQuery": {"text": "hello"}}}
8383
docs = client.documents.search(query=query)
8484
assert len(docs) == 2
8585
8686
# 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>"
8888
docs = client.documents.search(query=query)
8989
assert len(docs) == 2
9090
```
@@ -96,15 +96,15 @@ Examples of a combined query:
9696
options = {"constraint": {"name": "c1", "word": {"element": {"name": "text"}}}}
9797
query = {
9898
"search": {"options": options},
99-
"qtext": "c1:example",
99+
"qtext": "c1:hello",
100100
}
101101
docs = client.documents.search(query=query)
102102
assert len(docs) == 2
103103
104104
# XML
105105
query = "<search xmlns='http://marklogic.com/appservices/search'><options>\
106106
<constraint name='c1'><word><element name='text'/></word></constraint>\
107-
</options><qtext>c1:example</qtext></search>"
107+
</options><qtext>c1:hello</qtext></search>"
108108
docs = client.documents.search(query=query)
109109
assert len(docs) == 2
110110
```
@@ -116,11 +116,11 @@ more commonly used parameters are available as arguments in the `client.document
116116

117117
```
118118
# 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)
120120
assert len(docs) == 1
121121
122122
# 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"])
124124
assert len(docs) == 2
125125
```
126126

@@ -129,12 +129,12 @@ each matching document:
129129

130130
```
131131
# 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
135135
136136
# Retrieve only permissions for each matching document.
137-
docs = client.documents.search("example", categories=["permissions"])
137+
docs = client.documents.search("hello", categories=["permissions"])
138138
assert docs[0].content is None
139139
assert docs[1].content is None
140140
```
@@ -145,7 +145,7 @@ The `client.documents.search` method provides a `**kwargs` argument, so you can
145145
normally pass to `requests`. For example:
146146

147147
```
148-
docs = client.documents.search("example", params={"database": "Documents"})
148+
docs = client.documents.search("hello", params={"database": "Documents"})
149149
assert len(docs) == 2
150150
```
151151

0 commit comments

Comments
 (0)