Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Lee 1105 posts 3034 karma points
    Jul 18, 2016 @ 11:12

    Custom Examine/Lucene Index With Ability To Insert & Update Individual Entries

    I'm looking for pointers/links to articles or documents on how to create a custom index that let gives me the ability to insert and update individual entries/records.

  • Ismail Mayat 4239 posts 8983 karma points MVP admin c-trib
    Jul 18, 2016 @ 11:22
    Ismail Mayat


    In service somewhere you could have method

    /// <summary>
        /// Updates an entry in the search index that is related to the post provided by the parameter.
        /// </summary>
        /// <param name="post"></param>
        private void UpdateIndex(Post post)
            var examineNode = post.ToSimpleDataSet().RowData.ToExamineXml(post.Id, "CustomData");
            ExamineManager.Instance.IndexProviderCollection["CustomIndexer"].ReIndexNode(examineNode, "CustomData");

    And in the post class the method like:

    using Examine.LuceneEngine;     
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public SimpleDataSet ToSimpleDataSet()
            var data = new SimpleDataSet()
                //create the node definition, ensure that it is the same type as referenced in the config
                NodeDefinition = new IndexedNode()
                    NodeId = this.Id,
                    Type = "CustomData"
                //add the data to the row
                RowData = new Dictionary<string, string>() 
                         {"id", this.Id.ToString(CultureInfo.InvariantCulture)},
                         {"title", this.Title},
                         {"body", StringUtil.RemoveHtmlTags(HttpUtility.HtmlDecode(this.Body))},
                         {"tags", String.Join(",", this.PostTags.Select(x => x.TagId.ToString(CultureInfo.InvariantCulture)).ToArray())},
                         {"topicId", this.Topic.Id.ToString(CultureInfo.InvariantCulture)},
                         {"topicViews", this.Topic.Views.ToString(CultureInfo.InvariantCulture)},
                         {"topicTotalLikes", this.Topic.DeepLikeCount.ToString(CultureInfo.InvariantCulture)},
                         {"topicTotalReplies", this.Topic.DeepReplyCount .ToString(CultureInfo.InvariantCulture)},
                         {"topicDateUpdated", this.Topic.DateCreated.ToString(CultureInfo.InvariantCulture)},
                         {"isActive", this.IsActive.ToString(CultureInfo.InvariantCulture)}
            return data;

    See the using statement as well. For insert it will be the initial mass insert see the demo in examine source on how to implement custom indexer.

    This is old code it may be in v7 some namespaces may have changed



  • Markus Johansson 1578 posts 4447 karma points
    Dec 01, 2016 @ 10:15
    Markus Johansson


    Thanks for great pointers!

    So if a "mass insert" is my only option, everytime some new node (or row in the db) is created I would have to rerun that import? Is't there something like this:

    ExamineManager.Instance.IndexProviderCollection["CustomIndexer"].AddIndexNode(examineNode, "CustomData");

    Same question when something is deleted or hidden? How would I remove it?

    ? =D

  • Lee 1105 posts 3034 karma points
    Aug 18, 2016 @ 08:44

    Forgot to ask, do you have to still create the XML based indexer and searcher?

  • nurul 2 posts 20 karma points
    Nov 07, 2016 @ 03:13

    hi i have an issue regarding the image. the image change when i save and publish. what should i do?

Please Sign in or register to post replies

Write your reply to: