Beispiel #1
0
 /// <summary>
 /// Add content to be indexed.
 /// </summary>
 /// <param name="searchContent"></param>
 public void AddContent(SearchContent searchContent)
 {
     if (_indexWriter == null)
     {
         InitIndexWriter();
     }
     _indexWriter.AddDocument(BuildDocumentFromSearchContent(searchContent));
 }
Beispiel #2
0
 /// <summary>
 /// Update existing content in the search index.
 /// </summary>
 /// <param name="searchContent"></param>
 public void UpdateContent(SearchContent searchContent)
 {
     if (_rebuildIndex)
     {
         throw new InvalidOperationException("Cannot update documents when rebuilding the index.");
     }
     else
     {
         // First delete the old content
         DeleteContent(searchContent);
         // Now add the content again
         AddContent(searchContent);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Delete existing content from the search index.
        /// </summary>
        /// <param name="searchContent"></param>
        public void DeleteContent(SearchContent searchContent)
        {
            if (_rebuildIndex)
            {
                throw new InvalidOperationException("Cannot delete documents when rebuilding the index.");
            }
            else
            {
                _indexWriter.Close();
                _indexWriter = null;

                // The path uniquely identifies a document in the index.
                Term        term = new Term("path", searchContent.Path);
                IndexReader rdr  = IndexReader.Open(_indexDirectory);
                rdr.Delete(term);
                rdr.Close();
            }
        }
Beispiel #4
0
        private Document BuildDocumentFromSearchContent(SearchContent searchContent)
        {
            Document doc = new Document();

            doc.Add(Field.Text("title", searchContent.Title));
            doc.Add(Field.Text("summary", searchContent.Summary));
            doc.Add(Field.UnStored("contents", searchContent.Contents));
            doc.Add(Field.Text("author", searchContent.Author));
            doc.Add(Field.Keyword("moduletype", searchContent.ModuleType));
            doc.Add(Field.Keyword("path", searchContent.Path));
            doc.Add(Field.Keyword("category", searchContent.Category));
            doc.Add(Field.Keyword("site", searchContent.Site));
            doc.Add(Field.Keyword("datecreated", searchContent.DateCreated.ToString("u")));
            doc.Add(Field.Keyword("datemodified", searchContent.DateModified.ToString("u")));
            doc.Add(Field.UnIndexed("sectionid", searchContent.SectionId.ToString()));

            return(doc);
        }