Chúng tôi rất vui thông báo việc phát hành GroupDocs.Search for Python v26.10, có sẵn từ tháng 11 năm 2026. Đây là phiên bản đầu tiên của sản phẩm, mang toàn bộ chức năng của engine GroupDocs.Search 26.10 đến các nhà phát triển Python. Nó cho phép xây dựng và duy trì các chỉ mục toàn văn trên các thư mục tài liệu — bao gồm PDF, Word, Excel, PowerPoint, email, eBook, archive và nhiều định dạng khác (hơn 80 loại) — và tìm kiếm chúng bằng các loại truy vấn nâng cao: từ khóa, cụm từ, ký tự đại diện, regex, fuzzy, boolean, faceted và tìm kiếm theo khoảng thời gian. Bản phát hành hỗ trợ Python 3.5–3.14 trên Windows x64, Linux x64 (glibc 2.27+), và macOS 13+ (Intel và Apple Silicon), nhúng runtime .NET 10.0.14.
Những điểm mới trong phiên bản này
- [Feature] Phát hành ban đầu của GroupDocs.Search cho Python qua .NET (SEARCHPYTHONNET-40)
Thay đổi API công cộng
Đây là phiên bản đầu tiên, vì vậy không có gì cần nâng cấp. API tuân theo GroupDocs.Search for .NET 26.10: các lớp giữ nguyên tên .NET, trong khi các phương thức, thuộc tính và tham số được viết bằng snake_case (Index.Search là index.search, SearchResult.DocumentCount là result.document_count) và các thành viên enum bằng chữ hoa (OutputFormat.HTML). Gán một thuộc tính mà lớp không có sẽ gây ra AttributeError với gợi ý “Bạn có muốn nói là”, thay vì tạo một thuộc tính chỉ dành cho Python mà engine không bao giờ thấy.
Các mô-đun
groupdocs.search:Index,IndexSettings,IndexRepository,IndexUpdater,SearchQuery,Extractor,License,Metered,GroupDocsSearchException,LicenseError,CancellationTokenSource.groupdocs.search.options:IndexingOptions,SearchOptions,FuzzySearchOptions,SimilarityLevel,UpdateOptions,HighlightOptions,OutputFormat,SeparateProcessOptions,ImageSearchOptions.groupdocs.search.results:SearchResult,FoundDocument,FoundDocumentField,DocumentInfo,FileType,FormatFamily.groupdocs.search.highlighters:DocumentHighlighter,FragmentHighlighter.groupdocs.search.common:FileOutputAdapter,StringOutputAdapter,StreamOutputAdapter,Document,DocumentField,ExtractedData,FileLogger,AttributeChangeBatch.groupdocs.search.dictionaries:SynonymDictionary,HomophoneDictionary,StopWordDictionary,SpellingCorrector,AliasDictionary,CharacterReplacementPair.groupdocs.search.events:EventHub,FileIndexingEventArgs,IndexErrorEventArgs,OperationProgressEventArgs,PasswordRequiredEventArgs.groupdocs.search.exceptions:SearchException,LicenseRestrictionException.groupdocs.search.scaling:SearchNetworkNode,Indexer,Searcher.groupdocs.search.scaling.configuring:Configuration,Configurator,TcpSettings.
Tính năng mới
Lập chỉ mục tài liệu và tìm kiếm chúng
Index(folder) tạo một chỉ mục trong thư mục, hoặc mở chỉ mục đã tồn tại. add() lập chỉ mục cho một thư mục, một tệp, một danh sách đường dẫn, luồng hoặc dữ liệu đã trích xuất, và search() nhận một truy vấn theo ngôn ngữ truy vấn của GroupDocs.Search: từ khóa, cụm từ trong dấu ngoặc kép, ký tự đại diện (? cho một ký tự, ?(1~5) cho một đến năm ký tự), biểu thức chính quy sau ^, AND, OR và NOT, truy vấn trường như content: Bern hoặc filename: einstein, và các khoảng thời gian hoặc số. SearchQuery xây dựng các truy vấn tương tự dưới dạng đối tượng.
from groupdocs.search import Index
with Index("./index") as index: # creates the index folder, or opens it
index.add("./documents") # indexes every supported file in the folder
for query in ["relativity", '"theory of relativity"', "relativ?ty",
"^relativ.*", "Einstein AND NOT Newton", "content: Bern"]:
result = index.search(query)
print("%-26s %d documents, %d occurrences"
% (query, result.document_count, result.occurrence_count))
Tìm kiếm fuzzy, đồng nghĩa và dạng từ
Tìm kiếm fuzzy chịu lỗi gõ và lỗi OCR. Tìm kiếm đồng nghĩa, đồng âm và dạng từ mở rộng truy vấn thông qua các từ điển tiếng Anh tích hợp, mà index.dictionaries cho phép bạn chỉnh sửa, và sửa lỗi chính tả cũng như bố cục bàn phím là các tùy chọn tìm kiếm.
from groupdocs.search import Index
from groupdocs.search.options import SearchOptions, SimilarityLevel
with Index("./index") as index:
index.add("./documents")
fuzzy = SearchOptions()
fuzzy.fuzzy_search.enabled = True
fuzzy.fuzzy_search.fuzzy_algorithm = SimilarityLevel(0.8) # 0.0 (loose) .. 1.0 (strict)
print("relativty:", index.search("relativty").document_count,
"->", index.search("relativty", fuzzy).document_count)
synonyms = SearchOptions()
synonyms.use_synonym_search = True
print("picture:", index.search("picture").document_count,
"->", index.search("picture", synonyms).document_count)
word_forms = SearchOptions()
word_forms.use_word_forms_search = True
print("letter:", index.search("letter").document_count,
"->", index.search("letter", word_forms).document_count)
Đánh dấu những gì đã tìm thấy
DocumentHighlighter ghi toàn bộ tài liệu với các thuật ngữ đã tìm được được đánh dấu, và FragmentHighlighter chỉ ghi các đoạn xung quanh chúng, dưới dạng HTML hoặc văn bản thuần, vào tệp, chuỗi hoặc đối tượng tệp nhị phân.
from groupdocs.search import Index
from groupdocs.search.common import FileOutputAdapter
from groupdocs.search.highlighters import DocumentHighlighter
from groupdocs.search.options import OutputFormat
with Index("./index") as index:
index.add("./documents")
result = index.search("relativity")
if result.document_count > 0:
found = result.get_found_document(0)
adapter = FileOutputAdapter(OutputFormat.HTML, "./highlighted.html")
index.highlight(found, DocumentHighlighter(adapter))
print(found.document_info.file_path, "-> highlighted.html")
Sự kiện .NET dưới dạng trình xử lý Python
Mỗi sự kiện của chỉ mục là một sự kiện Python: đăng ký bằng += và hủy đăng ký bằng -=. Trình xử lý có thể bỏ qua một tài liệu, gắn thẻ nó bằng các thuộc tính hoặc cung cấp mật khẩu, và theo dõi tiến độ, lỗi và các giai đoạn của quá trình lập chỉ mục và tìm kiếm.
from groupdocs.search import Index
skipped = []
def on_file_indexing(sender, args):
if args.document_full_path.endswith(".zip"):
args.skip_indexing = True # leave archives out of the index
skipped.append(args.document_full_path)
with Index("./index") as index:
index.events.file_indexing += on_file_indexing
index.add("./documents")
index.events.file_indexing -= on_file_indexing
print(len(index.get_indexed_documents()), "documents indexed,", len(skipped), "archives skipped")
Đối tượng Python cho các điểm mở rộng của engine
Các bộ trích xuất văn bản tùy chỉnh cho các định dạng của riêng bạn, logger, bộ tách từ, nhà cung cấp dạng từ, bộ tải tài liệu và kết nối OCR đều là các đối tượng hoặc hàm Python thuần, mà engine sẽ gọi thông qua các giao diện của nó.
from groupdocs.search import Index, IndexSettings
class LogExtractor(object):
"""Text of .log files, which the engine does not read on its own."""
extensions = [".log"]
def get_fields(self, source): # a file path, or the engine's stream
if isinstance(source, str):
with open(source, encoding="utf-8") as f:
text = f.read()
else:
text = source.read().decode("utf-8")
return [("Content", text)]
settings = IndexSettings()
settings.custom_extractors.add(LogExtractor())
with Index("./log-index", settings) as index:
index.add("./logs")
print(index.search("quota").document_count, "log file(s) mention a quota")
Duy trì chỉ mục luôn cập nhật
Một chỉ mục là một thư mục: xây dựng một lần và mở lại trong lần chạy tiếp theo. update() lập chỉ mục lại chỉ những tài liệu đã thay đổi kể từ lần add() hoặc update() cuối cùng, optimize() hợp nhất các đoạn chỉ mục, và delete() xóa tài liệu theo đường dẫn.
from groupdocs.search import Index
with Index("./index") as index:
index.add("./documents")
# ... files in ./documents are added, changed or removed ...
index.update() # re-indexes only what changed
index.optimize() # merges index segments so searches stay fast
print(len(index.get_indexed_documents()), "documents in the index")
Giấy phép từ môi trường
Đặt GROUPDOCS_LIC_PATH tới đường dẫn hoặc URL của tệp giấy phép, và giấy phép sẽ được áp dụng khi lần gọi đầu tiên vào engine; License().set_license(path) thực hiện cùng chức năng trong mã. Một giấy phép không thể áp dụng sẽ gây ra LicenseError từ lần gọi đầu tiên trở đi, thay vì quay lại chế độ đánh giá. Không có giấy phép, một chỉ mục tối đa chỉ chứa 100 tài liệu và chỉ 10 tài liệu đầu tiên được tìm thấy trong một truy vấn có thể được đọc.
export GROUPDOCS_LIC_PATH="/path/to/GroupDocs.Search.lic"
Ví dụ mã
Xem các phần “Lập chỉ mục tài liệu và tìm kiếm chúng”, “Tìm kiếm fuzzy, đồng nghĩa và dạng từ”, “Đánh dấu những gì đã tìm thấy”, “Sự kiện .NET dưới dạng trình xử lý Python”, “Đối tượng Python cho các điểm mở rộng của engine”, và “Duy trì chỉ mục luôn cập nhật” ở trên để có các ví dụ mã hoạt động.
Cách nhận bản cập nhật
PyPI
- Gói: groupdocs-search-net 26.10.0
- Lệnh cài đặt:
pip install groupdocs-search-net==26.10.0
Tải trực tiếp
Tải file wheel cho nền tảng của bạn từ trang GroupDocs.Search for Python via .NET 26.10 và sau đó cài đặt file:
- Windows x64:
pip install groupdocs_search_net-26.10.0-py3-none-win_amd64.whl - Linux x64:
pip install groupdocs_search_net-26.10.0-py3-none-manylinux_2_27_x86_64.whl - macOS Intel:
pip install groupdocs_search_net-26.10.0-py3-none-macosx_13_0_x86_64.whl - macOS Apple Silicon:
pip install groupdocs_search_net-26.10.0-py3-none-macosx_13_0_arm64.whl