Search thread safety

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Search MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-search -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-search/search-net-mcp:latest
Folders, licensing and more →

Multiple simultaneous searches

Search in an index is a thread safe operation. This means that calls to the Search and SearchNext methods can be made from different threads to the same instance of the Index class without any cross-threading problems. Since version 26.11, an index folder can be used by one Index object at a time, in this process or in another one: share one Index object between the threads, because the constructor of another Index object for the same folder throws IOException until the first object is disposed.

Since version 26.11, the searches of an index that run at the same time share the threads set by the SearchThreads index setting. A search runs on the thread that calls it, and while fewer threads than this number are busy with the searches of the index, the index helps them with threads of its own. So one search uses up to SearchThreads threads, and several searches that run at the same time use this number of threads together; when as many searches as this number run or more, every search runs on its own thread only. A search never waits for a free thread. A part of a search that is too small to gain from several threads, for example a search of a small index, runs on the thread of the search. Before, every search used SearchThreads threads of its own. For details on the setting, see the Search index settings page.

Search during index-modifying operations

Since version 26.10, searches and index-modifying operations do not block each other. A search can be performed from any thread even while documents are being indexed, updated or deleted, or while the index is being merged or optimized. Each search works with a consistent snapshot of the index taken when the search starts: the changes made by an operation that is performed at the same time do not affect the search that has already started. For the specifics of search by chunks, see the Search by chunks page.

Index-modifying operations

Index-modifying operations cannot be performed at the same time. The following operations are mutually exclusive:

  • indexing documents (Add);
  • updating the index (Update);
  • deleting documents from the index (Delete);
  • merging indexes (Merge);
  • optimizing the index (Optimize);
  • changing document attributes (ChangeAttributes);
  • checking index segments (CheckSegments);
  • saving the index to another folder (SaveTo);
  • renaming an indexed document (Notify with a rename notification).

The current state of the index is available in the IndexInfo.IndexStatus property. If one of these operations is started before the previous one has finished, for example from another thread or while an asynchronous indexing operation is in progress, the new call does not throw an exception and does nothing: the ErrorOccurred event of the index is raised with the message “A new operation can not start until the previous one has finished” (for a merge or an optimization, the message is “Merged indexes must not be in progress state.”). The Notify method returns false in this case. Since version 26.11, the SaveTo method of an index that performs another operation throws InvalidOperationException and raises no event; before, it only raised the ErrorOccurred event and did not save the index.

Details on performing these operations can be found in the Indexing section and on the Update index, Delete indexed documents, Merge indexes, Optimize index, Document attributes, Document renaming and Search index location pages.

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.