using System; using System.Collections.Generic; using System.Text; using ScrewTurn.Wiki.SearchEngine; namespace ScrewTurn.Wiki.PluginFramework { /// /// Represents a message for use with the search engine. /// public class MessageDocument : IDocument { /// /// The type tag for a . /// public const string StandardTypeTag = "M"; /// /// Gets the document name for a message. /// /// The page. /// The message ID. /// The document name. public static string GetDocumentName(PageInfo page, int messageID) { if(page == null) throw new ArgumentNullException("page"); return page.FullName + "..." + messageID.ToString(); } /// /// Gets the page name and message ID from a document name. /// /// The document name. /// The page name. /// The message ID. public static void GetMessageDetails(string documentName, out string pageName, out int messageID) { if(documentName == null) throw new ArgumentNullException("documentName"); if(documentName.Length == 0) throw new ArgumentException("Document Name cannot be empty", "documentName"); int lastThreeDotsIndex = documentName.LastIndexOf("..."); if(lastThreeDotsIndex == -1) throw new ArgumentException("Document Name has an invalid format", "documentName"); pageName = documentName.Substring(0, lastThreeDotsIndex); messageID = int.Parse(documentName.Substring(lastThreeDotsIndex + 3)); } private uint id; private string name, title, typeTag; private DateTime dateTime; private int messageID; private PageInfo pageInfo; private Tokenizer tokenizer; /// /// Initializes a new instance of the class. /// /// The page. /// The message ID. /// The dumped document data. /// The tokenizer. public MessageDocument(PageInfo pageInfo, int messageID, DumpedDocument dumpedDocument, Tokenizer tokenizer) { if(dumpedDocument == null) throw new ArgumentNullException("dumpedDocument"); if(tokenizer == null) throw new ArgumentNullException("tokenizer"); this.pageInfo = pageInfo; this.messageID = messageID; id = dumpedDocument.ID; name = dumpedDocument.Name; typeTag = dumpedDocument.TypeTag; title = dumpedDocument.Title; dateTime = dumpedDocument.DateTime; this.tokenizer = tokenizer; } /// /// Gets or sets the globally unique ID of the document. /// public uint ID { get { return id; } set { id = value; } } /// /// Gets the globally-unique name of the document. /// public string Name { get { return name; } } /// /// Gets the title of the document, if any. /// public string Title { get { return title; } } /// /// Gets the tag for the document type. /// public string TypeTag { get { return typeTag; } } /// /// Gets the document date/time. /// public DateTime DateTime { get { return dateTime; } } /// /// Performs the tokenization of the document content. /// /// The content to tokenize. /// The extracted words and their positions. public WordInfo[] Tokenize(string content) { return tokenizer(content); } /// /// Gets the message ID. /// public int MessageID { get { return messageID; } } /// /// Gets the page information. /// public PageInfo PageInfo { get { return pageInfo; } } } }