private void DocumentationIndexer_DocumentWriting(object sender, global::Examine.LuceneEngine.DocumentWritingEventArgs e)
        {
            //When document is writing we need to inject a field into the index for the url with a double underscore prefix as this will make it able to be searched
            //get url field
            if (e.Fields.ContainsKey("url"))
            {
                var urlField = e.Fields["url"];

                if (!String.IsNullOrEmpty(urlField))
                {
                    var field = new Field("__fullUrl", urlField.ToLowerInvariant(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES);
                    e.Document.Add(field);
                }
            }
        }
Example #2
0
 private void SaveExpiryDateToExamine_DocumentWriting(object sender, global::Examine.LuceneEngine.DocumentWritingEventArgs e)
 {
     try
     {
         if (e.Fields["__IndexType"] == "content")
         {
             // Save the expiry date in a format which allows Examine to do range queries.
             // DateTime.MaxValue is used as a proxy for never expire, so that those pages have a value in the index which can be queried.
             // Using DocumentWriting and a NOT_ANALYZED field should enable sorting using Lucene, but it doesn't work. It does insert the value correctly though.
             var contentService = ApplicationContext.Current.Services.ContentService;
             var content        = contentService.GetById(e.NodeId);
             var expireDate     = content.ExpireDate ?? DateTime.MaxValue;
             var field          = new Field("expireDate", expireDate.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED);
             e.Document.Add(field);
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error <Exception>($"Error saving expiry date to Examine for node {e.NodeId}", ex);
         ex.ToExceptionless().Submit();
     }
 }