다음을 통해 공유


ISearchEnumerator Interface

Provides an interface to interact with the search and process job.

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

Remarks

A class that implements the ISearchEnumerator interface also needs to implement its base interface, IEnumerator.

The search and process job first checks if the search result enumerator is a null reference (Nothing in Visual Basic) with the IsNull() property. It then uses the IEnumerator.Current property to get current item in the search result. It uses the IEnumerator.MoveNext() method to move to the next search result. It also uses IEnumerator.Reset() to reset the enumerator.

Examples

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 and abstraction for a search provider to
    /// implement a custom search provider which 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>
        /// place holder  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);
            }
        }
    }


}

See Also

Reference

ISearchEnumerator Members

Microsoft.Office.RecordsManagement.SearchAndProcess Namespace