using System;
namespace ScrewTurn.Wiki.SearchEngine {
///
/// A delegate that is used for converting a to an instance of a class implementing ,
/// while reading index data from a permanent storage.
///
/// The to convert.
/// The converted document implementing or null if no document is found.
public delegate IDocument BuildDocument(DumpedDocument document);
///
/// Defines an interface for a search engine index.
///
public interface IIndex {
///
/// Gets or sets the stop words to be used while indexing new content.
///
string[] StopWords { get; set; }
///
/// Gets the total count of unique words.
///
/// Computing the result is O(1).
int TotalWords { get; }
///
/// Gets the total count of documents.
///
/// Computing the result is O(n*m), where n is the number of
/// words in the index and m is the number of documents.
int TotalDocuments { get; }
///
/// Gets the total number of occurrences (count of words in each document).
///
/// Computing the result is O(n),
/// where n is the number of words in the index.
int TotalOccurrences { get; }
///
/// Completely clears the index (stop words are not affected).
///
/// A state object that is passed to the IndexStorer SaveDate/DeleteData function.
void Clear(object state);
///
/// Stores a document in the index.
///
/// The document.
/// The document keywords, if any, an empty array or null otherwise.
/// The content of the document.
/// A state object that is passed to the IndexStorer SaveDate/DeleteData function.
/// The number of indexed words (including duplicates).
/// Indexing the content of the document is O(n),
/// where n is the total number of words in the document.
/// If or are null.
int StoreDocument(IDocument document, string[] keywords, string content, object state);
///
/// Removes a document from the index.
///
/// The document to remove.
/// A state object that is passed to the IndexStorer SaveDate/DeleteData function.
/// If is null.
void RemoveDocument(IDocument document, object state);
///
/// Performs a search in the index.
///
/// The search parameters.
/// The results.
/// If is null.
SearchResultCollection Search(SearchParameters parameters);
}
///
/// Defines an interface for an in-memory index.
///
public interface IInMemoryIndex : IIndex {
///
/// An event fired when the index is changed.
///
event EventHandler IndexChanged;
///
/// Sets the delegate used for converting a to an instance of a class implementing ,
/// while reading index data from a permanent storage.
///
/// The delegate (cannot be null).
/// This method must be called before invoking .
/// If is null.
void SetBuildDocumentDelegate(BuildDocument buildDocument);
///
/// Initializes index data by completely emptying the index catalog and storing the specified data.
///
/// The documents.
/// The words.
/// The mappings.
/// The method does not check the consistency of the data passed as arguments.
/// If , or are null.
/// If was not called.
void InitializeData(DumpedDocument[] documents, DumpedWord[] words, DumpedWordMapping[] mappings);
}
///
/// Lists legal search options.
///
public enum SearchOptions {
///
/// Search for at least one word of the search query.
///
AtLeastOneWord,
///
/// Search for all the words of the search query, in any order.
///
AllWords,
///
/// Search for an exact phrase.
///
ExactPhrase
}
}