pyzotero 1.7.0__py3-none-any.whl → 1.7.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyzotero/cli.py CHANGED
@@ -6,6 +6,7 @@ import sys
6
6
  import click
7
7
 
8
8
  from pyzotero import zotero
9
+ from pyzotero.zotero import chunks
9
10
 
10
11
 
11
12
  def _get_zotero_client(locale="en-US"):
@@ -36,7 +37,7 @@ def main(ctx, locale):
36
37
  @click.option(
37
38
  "--fulltext",
38
39
  is_flag=True,
39
- help="Enable full-text search (qmode='everything')",
40
+ help="Search full-text content including PDFs. Retrieves parent items when attachments match.",
40
41
  )
41
42
  @click.option(
42
43
  "--itemtype",
@@ -63,6 +64,12 @@ def main(ctx, locale):
63
64
  def search(ctx, query, fulltext, itemtype, collection, limit, output_json): # noqa: PLR0912, PLR0915
64
65
  """Search local Zotero library.
65
66
 
67
+ By default, searches top-level items in titles and metadata.
68
+
69
+ When --fulltext is enabled, searches all items including attachment content
70
+ (PDFs, documents, etc.). If a match is found in an attachment, the parent
71
+ bibliographic item is retrieved and included in results.
72
+
66
73
  Examples:
67
74
  pyzotero search -q "machine learning"
68
75
 
@@ -92,8 +99,43 @@ def search(ctx, query, fulltext, itemtype, collection, limit, output_json): # n
92
99
  # Join multiple item types with || for OR search
93
100
  params["itemType"] = " || ".join(itemtype)
94
101
 
95
- # Execute search using collection_items_top() if collection specified, otherwise top()
96
- if collection:
102
+ # Execute search
103
+ # When fulltext is enabled, use items() or collection_items() to get both
104
+ # top-level items and attachments. Otherwise use top() or collection_items_top()
105
+ # to only get top-level items.
106
+ if fulltext:
107
+ if collection:
108
+ results = zot.collection_items(collection, **params)
109
+ else:
110
+ results = zot.items(**params)
111
+
112
+ # When using fulltext, we need to retrieve parent items for any attachments
113
+ # that matched, since most full-text content comes from PDFs and other attachments
114
+ top_level_items = []
115
+ attachment_items = []
116
+
117
+ for item in results:
118
+ data = item.get("data", {})
119
+ if "parentItem" in data:
120
+ attachment_items.append(item)
121
+ else:
122
+ top_level_items.append(item)
123
+
124
+ # Retrieve parent items for attachments in batches of 50
125
+ parent_items = []
126
+ if attachment_items:
127
+ parent_ids = list(
128
+ {item["data"]["parentItem"] for item in attachment_items}
129
+ )
130
+ for chunk in chunks(parent_ids, 50):
131
+ parent_items.extend(zot.get_subset(chunk))
132
+
133
+ # Combine top-level items and parent items, removing duplicates by key
134
+ all_items = top_level_items + parent_items
135
+ items_dict = {item["data"]["key"]: item for item in all_items}
136
+ results = list(items_dict.values())
137
+ # Non-fulltext search: use top() or collection_items_top() as before
138
+ elif collection:
97
139
  results = zot.collection_items_top(collection, **params)
98
140
  else:
99
141
  results = zot.top(**params)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pyzotero
3
- Version: 1.7.0
3
+ Version: 1.7.1
4
4
  Summary: Python wrapper for the Zotero API
5
5
  Keywords: Zotero,DH
6
6
  Author: Stephan Hügel
@@ -126,6 +126,12 @@ pyzotero listcollections
126
126
  pyzotero itemtypes
127
127
  ```
128
128
 
129
+ ## Search Behaviour
130
+
131
+ By default, `pyzotero search` searches only top-level item titles and metadata fields.
132
+
133
+ When the `--fulltext` flag is used, the search expands to include all full-text indexed content, including PDFs and other attachments. Since most full-text content comes from PDF attachments rather than top-level items, the CLI automatically retrieves the parent bibliographic items for any matching attachments. This ensures you receive useful bibliographic records (journal articles, books, etc.) rather than raw attachment items.
134
+
129
135
  ## Output Format
130
136
 
131
137
  By default, the CLI outputs human-readable text with a subset of metadata including:
@@ -1,9 +1,9 @@
1
1
  pyzotero/__init__.py,sha256=5QI4Jou9L-YJAf_oN9TgRXVKgt_Unc39oADo2Ch8bLI,243
2
- pyzotero/cli.py,sha256=H7R9Nx5OEyrET1S19kQrC2g_rDq_7_RE9iCe_dKBEwY,9126
2
+ pyzotero/cli.py,sha256=4vWX8SobVoHouJ1k7cumqtuWKqeFPPp5QyZzfdzBDOc,11023
3
3
  pyzotero/filetransport.py,sha256=umLik1LLmrpgaNmyjvtBoqqcaMgIq79PYsTvN5vG-gY,5530
4
4
  pyzotero/zotero.py,sha256=4qb7jLl1lNkDv3WpEPLW2L0SbleTtGYlQ6Rloz-hmN0,76497
5
5
  pyzotero/zotero_errors.py,sha256=6obx9-pBO0z1bxt33vuzDluELvA5kSLCsfc-uGc3KNw,2660
6
- pyzotero-1.7.0.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
7
- pyzotero-1.7.0.dist-info/entry_points.txt,sha256=MzN7IMRj_oPNmDCsseYFPum3bHWE1gFxywhlbFbcn2k,48
8
- pyzotero-1.7.0.dist-info/METADATA,sha256=P26XM2Jb11lOpAw4McrEZFwNpwvr9jyMfvC_2v6MVr8,9233
9
- pyzotero-1.7.0.dist-info/RECORD,,
6
+ pyzotero-1.7.1.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
7
+ pyzotero-1.7.1.dist-info/entry_points.txt,sha256=MzN7IMRj_oPNmDCsseYFPum3bHWE1gFxywhlbFbcn2k,48
8
+ pyzotero-1.7.1.dist-info/METADATA,sha256=-fxVGQetAnFkecnXs67FhGSJfsbL9i_a7VOMg7_Rz2c,9776
9
+ pyzotero-1.7.1.dist-info/RECORD,,