references/full-text.md
2.4 KB查看排版效果| 1 | # Full-Text Content |
| 2 | |
| 3 | Pyzotero can retrieve and set full-text index content for attachment items. |
| 4 | |
| 5 | ## Retrieving Full-Text Content |
| 6 | |
| 7 | ```python |
| 8 | # Get full-text content for a specific attachment item |
| 9 | data = zot.fulltext_item('ATTACHMENTKEY') |
| 10 | # Returns: |
| 11 | # { |
| 12 | # "content": "Full text of the document...", |
| 13 | # "indexedPages": 50, |
| 14 | # "totalPages": 50 |
| 15 | # } |
| 16 | # For text docs: indexedChars/totalChars instead of pages |
| 17 | |
| 18 | text = data['content'] |
| 19 | unit = 'Pages' if 'totalPages' in data else 'Chars' |
| 20 | total = data.get('total' + unit, 0) |
| 21 | coverage = data.get('indexed' + unit, 0) / total if total else None |
| 22 | ``` |
| 23 | |
| 24 | ## Finding Items with New Full-Text Content |
| 25 | |
| 26 | ```python |
| 27 | # Get item keys with full-text updated since a library version |
| 28 | new_fulltext = zot.new_fulltext(since=1085) |
| 29 | # Returns dict: {'KEY1': 1090, 'KEY2': 1095, ...} |
| 30 | # Values are the library version at which full-text was indexed |
| 31 | ``` |
| 32 | |
| 33 | ## Setting Full-Text Content |
| 34 | |
| 35 | ```python |
| 36 | # Set full-text for a PDF attachment |
| 37 | payload = { |
| 38 | 'content': 'The full text content of the document.', |
| 39 | 'indexedPages': 50, |
| 40 | 'totalPages': 50 |
| 41 | } |
| 42 | zot.set_fulltext('ATTACHMENTKEY', payload) |
| 43 | |
| 44 | # For text documents use indexedChars/totalChars |
| 45 | payload = { |
| 46 | 'content': 'Full text here.', |
| 47 | 'indexedChars': len('Full text here.'), |
| 48 | 'totalChars': len('Full text here.') |
| 49 | } |
| 50 | zot.set_fulltext('ATTACHMENTKEY', payload) |
| 51 | ``` |
| 52 | |
| 53 | ## Full-Text Search via CLI |
| 54 | |
| 55 | The CLI provides full-text search across locally indexed PDFs: |
| 56 | |
| 57 | ```bash |
| 58 | # Search full-text content |
| 59 | pyzotero search -q "CRISPR gene editing" --fulltext |
| 60 | |
| 61 | # Output as JSON (retrieves parent bibliographic items for attachments) |
| 62 | pyzotero search -q "climate tipping points" --fulltext --json |
| 63 | ``` |
| 64 | |
| 65 | ## Search in API (qmode=everything) |
| 66 | |
| 67 | ```python |
| 68 | # Search in titles/creators + full-text content |
| 69 | results = zot.items(q='protein folding', qmode='everything', limit=20) |
| 70 | ``` |
| 71 | |
| 72 | `fulltext_item()` sends GET to `/items/{attachmentKey}/fulltext`; a 404 can mean missing indexed content as well as a missing item. `new_fulltext()` uses `/fulltext?since=<version>` and returns a key-to-version dict. `set_fulltext()` PUTs the supplied index and returns Boolean success; it does not extract text from a PDF. Supply the actual extracted content and coverage, not guessed counts. Remote search sees synced indexed content; local search sees the local index and can differ. Keep local server versions separate from Web API versions. [Official full-text contract](https://www.zotero.org/support/dev/web_api/v3/fulltext_content). |
文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。

