Sdílet prostřednictvím


ISearchProvider Interface

Provides an abstraction for a search provider to implement a custom search provider that can be used to replace the default search provider only for the search and process timer 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 ISearchProvider
'Usage
Dim instance As ISearchProvider
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public interface ISearchProvider

Remarks

If you need to add a custom search provider for the search and process timer job, implement this interface and register the SearchProvider. Registering the search provider by using the method RegisterSearchEngine will replace the default search provider with your custom search provider. Doing this will not generically replace the search provider for the whole system, but only for the search and process timer job.

Examples

public class CustomSearchEngine : ISearchProvider {to implement // Return a search iterator object that provides search results within the passedto implement // in SPWeb.to implement public ISearchEnumerator PerformSearch(ISearchParameters param, SPWeb web)to implement {to implementto implement  return new CustomSearchIterator(web);to implement }to implementto implement /// <summary>to implement /// place holder  implementation for GetSearchPageUrlto implement /// </summary>to implement /// <param name="web">Search web name</param>to implement /// <returns>string</returns>to implement public string GetSearchPageUrl(SPWeb web)to implement {to implementto implement  return "/_layouts/customsearch.aspx";to implement }}to implementpublic class CustomSearchIterator : ISearchEnumerator{to implement private SPList m_currentList = null;to implement private IEnumerator m_itemsIterator = null;to implementto implement /// <summary>to implement /// Constructor of the search iterator. Here we find a list in the SPWeb withto implement  /// the supplied title. All items in the list will be returned as search results.to implement /// </summary>to implement public CustomSearchIterator(SPWeb web)to implement {to implementto implement  m_currentList = web.Lists["customlistforsearch"];to implementto implement  if (m_currentList != null)to implementto implement  {to implementm_itemsIterator = m_currentList.Items.GetEnumerator();to implementto implement  }to implement }to implementto implement /// <summary>to implement /// Move to the next item in the search results.to implement /// Essentially this method tells whether it's the end of search results.to implement /// </summary>to implement /// <returns>Return false if it's the end of search results. Otherwise return true.</returns>to implement public bool MoveNext()to implement {to implementto implement  return m_itemsIterator.MoveNext();to implement }to implementto implement // Never called. No need to implement.to implement public void Reset()to implement {to implement }to implementto implement /// <summary>to implement /// Return the current item in the search results.to implement /// Here we just return the full URL of current item from a SPListItemCollection enumerator.to implement /// </summary>to implement public object Currentto implement {to implementto implement  getto implementto implement  {to implementSPListItem currentItem = (SPListItem) m_itemsIterator.Current;to implementstring itemUrl = SPUrlUtility.CombineUrl(currentItem.Web.Url, currentItem.Url);to implementreturn (object)itemUrl;to implementto implement  }to implement }to implementto implement /// <summary>to implement /// Whether the current item from search results is null.to implement /// </summary>to implement public bool IsNullto implement {to implementto implement  getto implementto implement  {to implementreturn (Current == null);to implementto implement  }to implement }}

See Also

Reference

ISearchProvider Members

Microsoft.Office.RecordsManagement.SearchAndProcess Namespace