Freigeben über


ISearchEnumerator-Schnittstelle

Stellt eine Schnittstelle für die Interaktion mit dem Such- und Verarbeitungsauftrag bereit.

Namespace:  Microsoft.Office.RecordsManagement.SearchAndProcess
Assembly:  Microsoft.Office.Policy (in Microsoft.Office.Policy.dll)

Syntax

'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Interface ISearchEnumerator _
    Inherits IEnumerator
'Usage
Dim instance As ISearchEnumerator
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public interface ISearchEnumerator : IEnumerator

Hinweise

Auch muss eine Klasse, die die ISearchEnumerator -Schnittstelle implementiert die Basisschnittstelle IEnumeratorimplementieren.

Der Auftrag suchen und verarbeiten überprüft zuerst, ob der Suche Ergebnis Enumerator Null mit der IsNull() -Eigenschaft ist. Anschließend verwendet die IEnumerator.Current -Eigenschaft, um das aktuelle Element in den Suchergebnissen abrufen und mithilfe die IEnumerator.MoveNext() -Methode zum nächsten Suchergebnis verschoben. Außerdem wird IEnumerator.Reset() verwendet, um den Enumerator zurückgesetzt.

Beispiele

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.Office.RecordsManagement;
using Microsoft.Office.RecordsManagement.SearchAndProcess;

namespace Microsoft.SDK.SharePointServer.Samples
{
    /// <summary>
    /// The ISearchProvider interface provides an abstraction for a search provider to
    /// implement a custom search provider that can be used for replacing the out of box
    /// search provider only for the search and process timer job.
    /// </summary>
    /// <remarks>
    /// <para>
    /// If you need to add custom search provider for the search and process timer job
    /// just implementing this interface and registering the SearchProvider registering
    /// the search provider using the method RegisterSearchEngine will replace the out
    /// of box search provider with your custom search provider. This will not generically
    /// replace the search provider for the whole system but only for the search and process
    /// timer job.
    /// </para>
    /// </remarks>

    public class CustomSearchEngine : ISearchProvider
    {
        // Return a search iterator object that provides search results within the passed
        // in SPWeb.
        public ISearchEnumerator PerformSearch(ISearchParameters param, SPWeb web)
        {
            return new CustomSearchIterator(web);
        }

        /// <summary>
        /// placeholder  implementation for GetSearchPageUrl
        /// </summary>
        /// <param name="web">Search web name</param>
        /// <returns>string</returns>
        public string GetSearchPageUrl(SPWeb web)
        {
            return "/_layouts/customsearch.aspx";
        }
    }

    public class CustomSearchIterator : ISearchEnumerator
    {
        private SPList m_currentList = null;
        private IEnumerator m_itemsIterator = null;

        /// <summary>
        /// Constructor of the search iterator. Here we find a list in the SPWeb with 
        /// the supplied title. All items in the list will be returned as search results.
        /// </summary>
        public CustomSearchIterator(SPWeb web)
        {
            m_currentList = web.Lists["customlistforsearch"];
            if (m_currentList != null)
            {
                m_itemsIterator = m_currentList.Items.GetEnumerator();
            }
        }

        /// <summary>
        /// Move to the next item in the search results.
        /// Essentially this method tells whether it's the end of search results.
        /// </summary>
        /// <returns>Return false if it's the end of search results. Otherwise return true.</returns>
        public bool MoveNext()
        {
            return m_itemsIterator.MoveNext();
        }

        // Never called. No need to implement.
        public void Reset()
        {
        }

        /// <summary>
        /// Return the current item in the search results.
        /// Here we just return the full URL of current item from a SPListItemCollection enumerator.
        /// </summary>
        public object Current
        {
            get
            {
                SPListItem currentItem = (SPListItem)m_itemsIterator.Current;
                string itemUrl = SPUrlUtility.CombineUrl(currentItem.Web.Url, currentItem.Url);
                return (object)itemUrl;
            }
        }

        /// <summary>
        /// Whether the current item from search results is null.
        /// </summary>
        public bool IsNull
        {
            get
            {
                return (Current == null);
            }
        }
    }


}

Siehe auch

Referenz

ISearchEnumerator-Member

Microsoft.Office.RecordsManagement.SearchAndProcess-Namespace