/// <summary>
/// Adds the specified page to the search index.
/// </summary>
/// <param name="model">The page to add.</param>
/// <exception cref="SearchException">An error occured with the lucene.net IndexWriter while adding the page to the index.</exception>
public virtual void Add(PageViewModel model)
{
try
{
EnsureDirectoryExists();
StandardAnalyzer analyzer = new StandardAnalyzer(LUCENEVERSION);
using (IndexWriter writer = new IndexWriter(FSDirectory.Open(new DirectoryInfo(IndexPath)), analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED))
{
Document document = new Document();
document.Add(new Field("id", model.Id.ToString(), Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("content", model.Content, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("contentsummary", GetContentSummary(model), Field.Store.YES, Field.Index.NO));
document.Add(new Field("title", model.Title, Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("tags", model.SpaceDelimitedTags(), Field.Store.YES, Field.Index.ANALYZED));
document.Add(new Field("createdby", model.CreatedBy, Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("createdon", model.CreatedOn.ToShortDateString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("contentlength", model.Content.Length.ToString(), Field.Store.YES, Field.Index.NO));
writer.AddDocument(document);
writer.Optimize();
}
}
catch (Exception ex)
{
if (!ApplicationSettings.IgnoreSearchIndexErrors)
throw new SearchException(ex, "An error occured while adding page '{0}' to the search index", model.Title);
}
}