### Check Everything System Service Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Static methods to verify if the Everything system service is installed and currently running. ```csharp class ServiceControl { // ... static bool IsServiceInstalled() static bool IsServiceRunning() // ... } ``` -------------------------------- ### Sort Search Results by Name Ascending Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Sort search results by file name in ascending order. This example demonstrates basic sorting by name. ```csharp using EverythingSearchClient; SearchClient search = new(); // Sort by file name ascending Result byName = search.Search( "*.txt", SearchClient.SearchFlags.None, 100, 0, SearchClient.BehaviorWhenBusy.WaitOrError, SearchClient.DefaultTimeoutMs, SearchClient.SortBy.Name, SearchClient.SortDirection.Ascending ); ``` -------------------------------- ### Perform Basic File Search with SearchClient Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Initializes the SearchClient and retrieves file metadata including paths, sizes, and timestamps. ```csharp using EverythingSearchClient; // Create a new search client instance SearchClient everything = new(); // Basic search for all files with '.txt' in their name Result res = everything.Search(".txt"); Console.WriteLine("Found {0} items:", res.NumItems); foreach (Result.Item item in res.Items) { Console.WriteLine("{0}\\{1}", item.Path, item.Name); // Output: C:\Users\Documents\notes.txt // Output: D:\Projects\readme.txt } // Access detailed item properties (available with Query2 API) foreach (Result.Item item in res.Items) { Console.WriteLine("Name: {0}", item.Name); Console.WriteLine("Path: {0}", item.Path); Console.WriteLine("Flags: {0}", item.Flags); // None, Folder, Drive, or Unknown Console.WriteLine("Size: {0}", item.Size); // File size in bytes (nullable) Console.WriteLine("Created: {0}", item.CreationTime); // Creation timestamp (nullable) Console.WriteLine("Modified: {0}", item.LastWriteTime); // Last write timestamp (nullable) Console.WriteLine("Attributes: {0}", item.FileAttributes); // ReadOnly, Hidden, System, etc. } ``` -------------------------------- ### Perform a file search using EverythingSearchClient Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README_nuget.md Initializes the search client and executes a query for files containing a specific string. The result object provides access to the number of items found and their names. ```csharp SearchClient everything = new(); Result res = everything.Search(".txt"); // search all files/folders with '.txt' in their name (not just as extension) Console.WriteLine("Found {0} items:", res.NumItems); foreach (Result.Item item in res.Items) { Console.WriteLine(item.Name); } ``` -------------------------------- ### Limit and Paginate Results Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Shows how to use maxResults and offset to handle large result sets efficiently. ```csharp Result res = search.Search("draft", SearchClient.SearchFlags.MatchWholeWord, 100, 0); Console.WriteLine("Found {0} items:", res.TotalItems); Console.WriteLine("Items {0}-{1}:", res.Offset, res.Offset + res.NumItems - 1); foreach (Result.Item item in res.Items) { Console.WriteLine("{0}", item.Name); } ``` ```csharp // ... res = search.Search("draft", SearchClient.SearchFlags.MatchWholeWord, 100, 100); /// ... res = search.Search("draft", SearchClient.SearchFlags.MatchWholeWord, 100, 200); /// ... ``` -------------------------------- ### Handle Busy Everything Service with Continue Behavior Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Use the Continue behavior to proceed immediately without waiting if the Everything service is busy, potentially aborting other queries. ```csharp using EverythingSearchClient; SearchClient search = new(); // Continue immediately without waiting (may abort other queries) Result res4 = search.Search( "config", SearchClient.SearchFlags.None, SearchClient.AllItems, 0, SearchClient.BehaviorWhenBusy.Continue ); ``` -------------------------------- ### Check Everything Service Status in C# Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Verify service availability, version, and busy state before executing search queries to prevent runtime exceptions. ```csharp using EverythingSearchClient; // Check if Everything service is available if (!SearchClient.IsEverythingAvailable()) { Console.WriteLine("Everything service is not running. Please start Everything."); return; } // Get Everything version Version version = SearchClient.GetEverythingVersion(); Console.WriteLine("Everything version: {0}", version); // Output: Everything version: 1.4.1.1024 // Check if Everything is currently processing a query if (SearchClient.IsEverythingBusy()) { Console.WriteLine("Warning: Everything is busy. Query might be delayed or aborted."); } // Determine if running as service or user process bool isService = ServiceControl.IsServiceInstalled() && ServiceControl.IsServiceRunning(); Console.WriteLine("Running as: {0}", isService ? "Service" : "User Process"); // Complete availability check pattern SearchClient search = new(); try { if (!SearchClient.IsEverythingAvailable()) { throw new Exception("Everything service is unavailable"); } Console.WriteLine("Everything v{0}", SearchClient.GetEverythingVersion()); if (SearchClient.IsEverythingBusy()) { Console.WriteLine("Everything is busy, will wait for availability..."); } Result res = search.Search("*.dll", SearchClient.BehaviorWhenBusy.WaitOrError, 5000); Console.WriteLine("Found {0} DLL files", res.NumItems); } catch (InvalidOperationException ex) { Console.WriteLine("Everything not available: {0}", ex.Message); } catch (EverythingBusyException) { Console.WriteLine("Everything service remained busy, search aborted"); } ``` -------------------------------- ### Configure Search Behavior with SearchFlags Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Demonstrates using bitwise OR operations to combine flags for case-sensitive, whole-word, path-based, and regex searches. ```csharp using EverythingSearchClient; SearchClient search = new(); // Case-sensitive search Result caseResult = search.Search("README", SearchClient.SearchFlags.MatchCase); // Match whole word only (won't match 'draft123' or 'mydraft') Result wordResult = search.Search("draft", SearchClient.SearchFlags.MatchWholeWord); // Include full path in search (find files in specific directories) Result pathResult = search.Search("projects", SearchClient.SearchFlags.MatchPath); // Regular expression search for all .git directories Result regexResult = search.Search("^\\.git$", SearchClient.SearchFlags.RegEx); Console.WriteLine("Found {0} .git directories:", regexResult.NumItems); foreach (Result.Item item in regexResult.Items) { Console.WriteLine("{0} | {1}", item.Flags, item.Path); // Output: Folder | C:\Projects\MyApp // Output: Folder | D:\Repos\Library } // Combine multiple flags Result combinedResult = search.Search( "config", SearchClient.SearchFlags.MatchCase | SearchClient.SearchFlags.MatchWholeWord ); ``` -------------------------------- ### Handle Busy Everything Service with Error Behavior Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Configure the client to immediately throw an error if the Everything service is busy, without waiting. ```csharp using EverythingSearchClient; SearchClient search = new(); // Throw error immediately if Everything is busy try { Result res3 = search.Search( "test", SearchClient.SearchFlags.None, SearchClient.AllItems, 0, SearchClient.BehaviorWhenBusy.Error ); } catch (EverythingBusyException ex) { Console.WriteLine($"Error: {ex.Message}"); } ``` -------------------------------- ### Handle Busy Everything Service with WaitOrError and Timeout Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Configure how the client behaves when the Everything service is busy. Use WaitOrError with a timeout to wait for the service to become available, throwing an error if it remains busy. ```csharp using EverythingSearchClient; SearchClient search = new(); // Wait up to 5 seconds for Everything to become ready, then throw error if still busy try { Result res1 = search.Search( "*.log", SearchClient.SearchFlags.None, SearchClient.AllItems, 0, SearchClient.BehaviorWhenBusy.WaitOrError, 5000 // 5 second timeout ); } catch (EverythingBusyException) { Console.WriteLine("Everything service is busy and didn't become available in time"); } ``` -------------------------------- ### Perform a RegEx Search Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Demonstrates using the RegEx flag to perform a specific pattern-based search. ```csharp Result res = everything.Search("^\\.git$", SearchClient.SearchFlags.RegEx); ``` -------------------------------- ### Configure SearchClient Query API Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Select between Query1 and Query2 IPC API versions and configure receive timeouts for search operations. ```csharp using EverythingSearchClient; SearchClient search = new(); // Use any available API (default - tries Query2 first, falls back to Query1) search.UseQueryApi = SearchClient.QueryApi.Any; Result res1 = search.Search("*.txt"); // Force Query2 only (get file sizes and timestamps) search.UseQueryApi = SearchClient.QueryApi.Query2only; try { Result res2 = search.Search("*.doc"); foreach (Result.Item item in res2.Items) { Console.WriteLine("{0} - Size: {1} bytes, Modified: {2}", item.Name, item.Size ?? 0, item.LastWriteTime); } } catch (Exception ex) { Console.WriteLine("Query2 failed: {0}", ex.Message); } // Force Query1 only (basic name and path only) search.UseQueryApi = SearchClient.QueryApi.Query1only; Result res3 = search.Search("*.pdf"); // Configure receive timeout for slow systems search.ReceiveTimeout = TimeSpan.FromSeconds(10); Result res4 = search.Search("*", 1000, 0); ``` -------------------------------- ### Implement Search with Retry Logic in C# Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Uses a while loop to manage search retries and pagination. Handles transient failures and busy states with specific exception catching. ```csharp using EverythingSearchClient; SearchClient search = new(); string drivePath = "D:\\"; // Target drive uint pageSize = 10000; // Files per query uint timeoutMs = 2000; // 2 second timeout const int maxRetries = 10; // Maximum retry attempts uint offset = 0; int retryCount = maxRetries; while (true) { try { Result res = search.Search( $"{drivePath} files:", SearchClient.SearchFlags.None, pageSize, offset, SearchClient.BehaviorWhenBusy.WaitOrError, timeoutMs ); // Reset retry counter on success retryCount = maxRetries; Console.WriteLine($"{res.NumItems} items at offset {res.Offset} / {res.TotalItems}"); // Process results foreach (Result.Item item in res.Items) { // Process each file... } offset += res.NumItems; if (offset >= res.TotalItems) break; } catch (ResultsNotReceivedException) { if (retryCount > 0) { Console.WriteLine("Results not received - retrying..."); Thread.Sleep(100); // Brief pause before retry retryCount--; continue; } else { Console.WriteLine("Failed after {0} retries", maxRetries); throw; } } catch (EverythingBusyException) { Console.WriteLine("Everything is busy, waiting..."); Thread.Sleep(500); continue; } } Console.WriteLine("Search completed successfully"); ``` -------------------------------- ### Apply Predefined File Type Filters in C# Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Use these constants to narrow search results to specific categories like audio, video, or documents. ```csharp using EverythingSearchClient; SearchClient search = new(); // Search for audio files in Windows directory Result audioFiles = search.Search("C:\\Windows file: " + SearchClient.FilterAudio); Console.WriteLine("Found {0} Windows sound files", audioFiles.NumItems); // Search for picture files Result pictures = search.Search("vacation " + SearchClient.FilterPictures); Console.WriteLine("Found {0} vacation pictures", pictures.NumItems); // Search for video files on D: drive Result videos = search.Search("D:\\ " + SearchClient.FilterVideo); Console.WriteLine("Found {0} video files", videos.NumItems); // Search for documents Result docs = search.Search("report " + SearchClient.FilterDocuments); foreach (Result.Item item in docs.Items) { Console.WriteLine("{0}\\{1}", item.Path, item.Name); } // Search for executable files Result executables = search.Search("setup " + SearchClient.FilterExecutables); // Search for compressed archives Result archives = search.Search("backup " + SearchClient.FilterZipped); // Available filter constants: // SearchClient.FilterAudio - aac, mp3, wav, flac, ogg, etc. // SearchClient.FilterPictures - jpg, png, gif, bmp, tiff, etc. // SearchClient.FilterVideo - mp4, avi, mkv, mov, wmv, etc. // SearchClient.FilterDocuments - pdf, doc, txt, xml, html, etc. // SearchClient.FilterExecutables - exe, msi, bat, cmd, scr // SearchClient.FilterZipped - zip, rar, 7z, tar, gz, etc. ``` -------------------------------- ### Manage Everything Windows Service Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Check service status and perform start/stop operations. Requires administrator privileges for service control actions. ```csharp using EverythingSearchClient; // Check if Everything is installed as a Windows service if (ServiceControl.IsServiceInstalled()) { Console.WriteLine("Everything service is installed"); // Check if the service is running if (ServiceControl.IsServiceRunning()) { Console.WriteLine("Service is currently running"); } else { Console.WriteLine("Service is installed but not running"); } } else { Console.WriteLine("Everything is not installed as a service (running as user process)"); } // Start the service (requires administrator privileges) try { if (ServiceControl.IsServiceInstalled() && !ServiceControl.IsServiceRunning()) { Console.Write("Starting Everything service..."); ServiceControl.Start(); // Wait for service to start while (!ServiceControl.IsServiceRunning()) { Thread.Sleep(100); } Console.WriteLine(" done"); } } catch (UnauthorizedAccessException ex) { Console.WriteLine("Cannot start service - run as administrator: {0}", ex.Message); } catch (InvalidOperationException ex) { Console.WriteLine("Service not installed: {0}", ex.Message); } // Stop the service (requires administrator privileges) try { if (ServiceControl.IsServiceRunning()) { Console.Write("Stopping Everything service..."); ServiceControl.Stop(); // Wait for service to stop while (ServiceControl.IsServiceRunning()) { Thread.Sleep(100); } Console.WriteLine(" done"); } } catch (UnauthorizedAccessException) { Console.WriteLine("Access denied - administrator privileges required"); } ``` -------------------------------- ### Query Everything Service Status Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Static methods to check the availability, version, and busy state of the Everything process. ```csharp class SearchClient { // ... static bool IsEverythingAvailable(); static Version GetEverythingVersion(); static bool IsEverythingBusy(); // ... } ``` -------------------------------- ### Define BehaviorWhenBusy Enum Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Defines the available strategies for handling search requests when the Everything service is currently busy. ```csharp enum BehaviorWhenBusy { WaitOrError, WaitOrContinue, Error, Continue } ``` -------------------------------- ### Handle Busy Everything Service with WaitOrContinue and Timeout Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Use WaitOrContinue with a timeout to wait for the Everything service, proceeding even if it remains busy, which may abort other running queries. ```csharp using EverythingSearchClient; SearchClient search = new(); // Wait up to 2 seconds, then proceed anyway (may abort other running queries) Result res2 = search.Search( "*.txt", SearchClient.SearchFlags.None, SearchClient.AllItems, 0, SearchClient.BehaviorWhenBusy.WaitOrContinue, 2000 ); ``` -------------------------------- ### Paginate Search Results with maxResults and offset Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Use maxResults and offset to retrieve large result sets in manageable chunks. TotalItems indicates total matches, NumItems shows items in the current page. ```csharp using EverythingSearchClient; SearchClient search = new(); // Fetch first 100 results Result res = search.Search("draft", SearchClient.SearchFlags.MatchWholeWord, 100, 0); Console.WriteLine("Total found: {0}", res.TotalItems); // e.g., 5000 Console.WriteLine("Items returned: {0}", res.NumItems); // 100 Console.WriteLine("Offset: {0}", res.Offset); // 0 Console.WriteLine("Items {0}-{1}:", res.Offset, res.Offset + res.NumItems - 1); foreach (Result.Item item in res.Items) { Console.WriteLine("{0}", item.Name); } // Paginate through all results uint pageSize = 10000; uint offset = 0; uint totalProcessed = 0; while (true) { Result page = search.Search("*.cs", pageSize, offset); Console.WriteLine($"Page: {page.NumItems} items at offset {page.Offset} / {page.TotalItems} total"); foreach (Result.Item item in page.Items) { // Process each item totalProcessed++; } offset += page.NumItems; if (offset >= page.TotalItems) break; } Console.WriteLine($"Processed {totalProcessed} files total"); ``` -------------------------------- ### BehaviorWhenBusy Enum Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Defines the behavior of the client when the Everything service is busy. ```APIDOC ## Enums ### BehaviorWhenBusy Specifies how the client should react when the Everything service is busy. - **WaitOrError** - The client will wait for the service to become available or return an error if it times out. - **SkipResults** - The client will skip the current search and return immediately. ``` -------------------------------- ### Search API Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md This section details the primary search functionality provided by the EverythingSearchClient. It includes the main search method, its parameters, and how to interpret the results. ```APIDOC ## POST /api/search ### Description Performs a search using the Everything search engine with various optional parameters to refine the search criteria and limit results. ### Method POST ### Endpoint /api/search ### Parameters #### Query Parameters - **query** (string) - Required - The search query string. - **flags** (SearchFlags) - Optional - Flags to modify search behavior (e.g., MatchCase, MatchWholeWord, RegEx). - **maxResults** (uint) - Optional - The maximum number of results to return in this request. Defaults to AllItems. - **offset** (uint) - Optional - The offset for pagination, used to retrieve subsequent sets of results. Defaults to 0. - **whenBusy** (BehaviorWhenBusy) - Optional - Specifies the behavior when the Everything service is busy. Defaults to WaitOrError. - **timeoutMs** (uint) - Optional - The timeout in milliseconds for the search operation. Defaults to 0 (no timeout). ### Request Example ```json { "query": ".txt", "flags": "MatchWholeWord", "maxResults": 100, "offset": 0 } ``` ### Response #### Success Response (200) - **TotalItems** (UInt32) - The total number of items found matching the query across all possible results. - **NumItems** (UInt32) - The number of items returned in this specific request. - **Offset** (UInt32) - The offset used for this request. - **Items** (Array of Item) - An array containing the search results. #### Response Example ```json { "TotalItems": 500, "NumItems": 100, "Offset": 0, "Items": [ { "Flags": "None", "Name": "document1.txt", "Path": "C:\\Users\\User\\Documents" }, { "Flags": "None", "Name": "notes.txt", "Path": "C:\\Users\\User\\Documents\\Notes" } ] } ``` ### Error Handling - **400 Bad Request**: Invalid query parameters. - **500 Internal Server Error**: An error occurred on the server. ``` -------------------------------- ### Result Class Structure Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Outlines the data structure returned by search queries, containing item metadata and flags. ```csharp class Result { [Flags] enum ItemFlags { None, // aka normal file Folder, Drive, Unknown // Something strange was reported by Everything } class Item { ItemFlags Flags; string Name; string Path; } UInt32 TotalItems; UInt32 NumItems; UInt32 Offset; Item[] Items; } ``` -------------------------------- ### Sort Search Results by Size Descending Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Sort search results by file size in descending order to list the largest files first. This is useful for identifying large media files or archives. ```csharp using EverythingSearchClient; SearchClient search = new(); // Sort by file size descending (largest files first) Result bySize = search.Search( "*.mp4", SearchClient.SearchFlags.None, 50, 0, SearchClient.BehaviorWhenBusy.WaitOrError, SearchClient.DefaultTimeoutMs, SearchClient.SortBy.Size, SearchClient.SortDirection.Decending ); ``` -------------------------------- ### Search Method Signature Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Defines the full parameters available for the Search function, including flags, limits, and timeout settings. ```csharp Result Search( string query, SearchFlags flags = SearchFlags.None, uint maxResults = AllItems, uint offset = 0, BehaviorWhenBusy whenBusy = BehaviorWhenBusy.WaitOrError, uint timeoutMs = 0) ``` -------------------------------- ### Sort Search Results by Modification Date Descending Source: https://context7.com/sgrottel/everythingsearchclient/llms.txt Sort search results by modification date in descending order to see the most recently modified files first. This is helpful for tracking recent changes. ```csharp using EverythingSearchClient; SearchClient search = new(); // Sort by modification date (most recent first) Result byDate = search.Search( "*.log", SearchClient.SearchFlags.None, 100, 0, SearchClient.BehaviorWhenBusy.WaitOrError, SearchClient.DefaultTimeoutMs, SearchClient.SortBy.DateModified, SearchClient.SortDirection.Decending ); foreach (Result.Item item in byDate.Items) { Console.WriteLine("{0} - Modified: {1}", item.Name, item.LastWriteTime); } ``` -------------------------------- ### Search Flags Definition Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Enumerates the available flags to modify search behavior, such as case sensitivity or regex support. ```csharp [Flags] enum SearchFlags { None, MatchCase, MatchWholeWord, // match whole word MatchPath, // include paths in search RegEx // enable regex } ``` -------------------------------- ### SearchFlags Enum Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Enumeration for controlling search behavior and matching options. ```APIDOC ## Enums ### SearchFlags Allows customization of search behavior. - **None** (0) - No special flags are enabled. - **MatchCase** (1) - Enables case-sensitive matching. - **MatchWholeWord** (2) - Enables matching of whole words only. - **MatchPath** (4) - Includes file paths in the search criteria. - **RegEx** (8) - Enables regular expression matching for the query. ``` -------------------------------- ### Result Structure Source: https://github.com/sgrottel/everythingsearchclient/blob/main/README.md Defines the structure of the Result object returned by search operations, including item details and pagination information. ```APIDOC ## Data Structures ### Result Represents the outcome of a search query. - **TotalItems** (UInt32) - The total number of items found matching the query. - **NumItems** (UInt32) - The number of items returned in the current result set. - **Offset** (UInt32) - The offset used for pagination in this result set. - **Items** (Array of Item) - An array of `Item` objects representing the found files or folders. ### Item Represents a single search result. - **Flags** (ItemFlags) - Flags indicating the type of item (e.g., Folder, Drive). - **Name** (string) - The name of the file or folder. - **Path** (string) - The full path to the file or folder. ### ItemFlags Enum Flags that provide additional information about an item. - **None** (0) - Indicates a normal file. - **Folder** (1) - Indicates a folder. - **Drive** (2) - Indicates a drive. - **Unknown** (3) - Indicates an unknown item type reported by Everything. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.