IAdmSearchResultIterator

The IAdmSearchResultIterator interface provides methods and properties that are used to iterate through search results.

Inheritance: IDisposable

Methods

  • Method

  • Description

  • FetchAll()

  • Fetches all results that were found during the search.

  • MoveNext()

  • Advances the search iterator to the next element in the search results.

  • MovePrevious()

  • Moves the search iterator to the previous element in the search results.

  • GetNextPage()

  • Gets the next page of search results.

  • Reset()

  • Moves the iterator to the start of the search results.

  • AbandonSearch()

  • Abandons the search.

Properties

Details

FetchAll()

Fetches all results that were found during the search.

AdmSearchResult[] FetchAll()

MoveNext()

Advances the search iterator to the next element in the search results.

bool MoveNext()

Return value

The method returns true if the iterator successfully moved, and false if the iterator passes the end of the search results.

Remarks

If directory search is performed synchronously, when this method is called for the first time, it waits for all search results to load, and then tries to advance the iterator. If the search is asynchronous, and the method reaches the last element in the collection, it tries to load another portion of data, and only when that portion of data is empty, it returns false.


MovePrevious()

Moves the search iterator to the previous element in the search results.

bool MovePrevious()

Return value

The method returns true if the iterator succeeds, and false if the iterator passes the beginning of the collection.

Remarks

This method can be used only if caching is enabled.


GetNextPage()

Gets the next page of search results. The number of search results per page is determined by the SearchParameters::PageSize property.

AdmSearchResult[] GetNextPage()

Examples

The following code sample outputs names and the total count of contacts located in an organizational unit.

PowerShell
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

$ouDN = "OU=Contacts,DC=domain,DC=com"

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the organizational unit
$searcher = $service.OpenObject("Adaxes://$ouDN", $null, $null, 0)

# Specify search parameters
$searcher.Criteria = New-AdmCriteria "contact"
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500 # search results per page

try
{
    # Execute search
    $searchResultIterator = $searcher.ExecuteSearch()
    
    $totalCount = 0
    while($true)
    {
        # Get the next page of search results
        $searchResults = $searchResultIterator.GetNextPage()
        if (($searchResults.Length -eq 0) -and ($searchResultIterator.IsSearchCompleted))
        {
            break # no more results to return
        }
        
        $totalCount += $searchResults.Length
        foreach ($searchResult in $searchResults)
        {
            Write-Host $searchResult.Name
        }

        Start-Sleep -Milliseconds 0
    }

    Write-Host
    Write-Host "Contacts found: $totalCount"
}
finally
{
    # Release resources used by the search
    $searchResultIterator.Dispose()
}
C#
using System;
using System.Threading;
using Softerra.Adaxes.Directory.Criteria;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;

class Program
{
    static void Main(string[] args)
    {
        const string ouPath = "Adaxes://OU=Contacts,DC=domain,DC=com";

        // Connect to the Adaxes service
        AdmNamespace ns = new AdmNamespace();
        IAdmService service = ns.GetServiceDirectly("localhost");

        // Bind to the organizational unit
        IAdmDirectorySearcher searcher = (IAdmDirectorySearcher)service.OpenObject(
            ouPath, null, null, 0);

        // Build search criteria
        Criteria criteria = new();
        criteria.AddType("contact");

        // Specify search parameters
        searcher.Criteria = criteria;
        searcher.SearchScope = ADS_SCOPEENUM.ADS_SCOPE_SUBTREE;
        searcher.PageSize = 500; // search results per page

        // Execute search
        using (IAdmSearchResultIterator searchResultIterator =
                (IAdmSearchResultIterator)searcher.ExecuteSearch())
        {
            int totalCount = 0;
            while (true)
            {
                // Get the next page of search results
                AdmSearchResult[] searchResults = searchResultIterator.GetNextPage();
                if ((searchResults.Length == 0) && (searchResultIterator.IsSearchCompleted))
                {
                    break; // no more results to return
                }
                
                totalCount += searchResults.Length;
                foreach (AdmSearchResult searchResult in searchResults)
                {
                    Console.WriteLine(searchResult.Name);
                }

                Thread.Sleep(0);
            }

            Console.WriteLine();
            Console.WriteLine("Contacts found: " + totalCount);
        }
    }
}

Reset()

Moves the iterator to the start of the search results.

void Reset()

Remarks

This method can be used only if caching is enabled.


AbandonSearch()

Abandons the search.

void AbandonSearch()

Count

Gets the number of entries in the search result.

  • Type:
  • int
  • Access:
  • Read-only

Current

Gets the current search result entry.


IsSearchCompleted

Gets a value that indicates whether the current search is complete.

  • Type:
  • bool
  • Access:
  • Read-only

IsSizeLimitExceeded

Gets a value that indicates whether the size limit was exceeded.

  • Type:
  • bool
  • Access:
  • Read-only

IsTimeLimitExceeded

Gets a value that indicates whether the time limit was exceeded.

  • Type:
  • bool
  • Access:
  • Read-only

ResultDirectorySynchronization

Gets an instance of the AdmDirectorySynchronization class containing the data that was returned by the directory server.


ResultPagingInfo

Gets a cookie for the next search.


ResultVirtualListView

Gets an instance of the AdmDirectoryVirtualListView class containing the data that was returned by the directory server.


SearchReferences

Gets a collection of search references as returned by the server.

  • Type:
  • ICollection<ICollection<Uri>>
  • Access:
  • Read-only

Requirements

Minimum required version: 2023

See also