Skip to content

Commit 6a68f0c

Browse files
committed
Fixed broken journal search
Simplified the code by: 1. Using the `requests` `params` keyword argument instead of manually constructing query string. 2. Accepting query, limit, offset, etc. directly as arguments to the search method. This way, when you do `help(bugout_client.search)`, you see immediately what the structure of the input should be. 3. Removing unnecessary Pydantic model for search fields.
1 parent 1c58b6a commit 6a68f0c

File tree

3 files changed

+19
-33
lines changed

3 files changed

+19
-33
lines changed

bugout/app.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,11 @@ def search(
525525
self,
526526
token: Union[str, uuid.UUID],
527527
journal_id: Union[str, uuid.UUID],
528+
query: str,
529+
limit: int = 10,
530+
offset: int = 0,
531+
content: bool = True,
528532
timeout: float = REQUESTS_TIMEOUT,
529-
**queries: Dict[str, Any],
530533
) -> data.BugoutSearchResults:
531534
self.journal.timeout = timeout
532-
return self.journal.search(token=token, journal_id=journal_id, **queries)
535+
return self.journal.search(token, journal_id, query, limit, offset, content)

bugout/data.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,6 @@ class BugoutJournalEntryTags(BaseModel):
153153
tags: List[str]
154154

155155

156-
class BugoutSearchFields(BaseModel):
157-
query: str = ""
158-
filters: Optional[List[str]] = None
159-
limit: int = 10
160-
offset: int = 0
161-
content: Optional[bool] = True
162-
163-
164156
class BugoutSearchResult(BaseModel):
165157
entry_url: str
166158
content_url: str

bugout/journal.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
BugoutJournalEntries,
1212
BugoutJournalEntryContent,
1313
BugoutJournalEntryTags,
14-
BugoutSearchFields,
1514
BugoutSearchResults,
1615
HolderType,
1716
Method,
@@ -344,34 +343,26 @@ def delete_tag(
344343
return BugoutJournalEntryTags(**result)
345344

346345
# Search module
347-
def _search_query(self, search_path: str, **queries: Dict[str, Any]) -> str:
348-
"""
349-
Validate search arguments with pydantic model BugoutSearchFields and
350-
generate search_path with queries.
351-
"""
352-
field_queries = BugoutSearchFields(**queries)
353-
fields_list = list(BugoutSearchFields.schema().get("properties").keys()) # type: ignore
354-
355-
search_path += f"?{fields_list[0]}={getattr(field_queries, fields_list[0])}"
356-
for field in fields_list[1:]:
357-
attr = getattr(field_queries, field)
358-
if type(attr) is list:
359-
attr = ",".join(attr)
360-
search_path += f"&{field}={attr}"
361-
362-
return search_path
363-
364346
def search(
365347
self,
366348
token: Union[str, uuid.UUID],
367349
journal_id: Union[str, uuid.UUID],
368-
**queries: Dict[str, Any],
350+
query: str,
351+
limit: int = 10,
352+
offset: int = 0,
353+
content: bool = True,
369354
) -> BugoutSearchResults:
370-
search_path_org = f"journals/{journal_id}/search"
371-
search_path = self._search_query(search_path=search_path_org, **queries)
372-
355+
search_path = f"journals/{journal_id}/search"
373356
headers = {
374357
"Authorization": f"Bearer {token}",
375358
}
376-
result = self._call(method=Method.get, path=search_path, headers=headers)
359+
query_params = {
360+
"q": query,
361+
"limit": limit,
362+
"offset": offset,
363+
"content": content,
364+
}
365+
result = self._call(
366+
method=Method.get, path=search_path, params=query_params, headers=headers
367+
)
377368
return BugoutSearchResults(**result)

0 commit comments

Comments
 (0)