Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Jul 18, 2016 @ 11:12
    Lee
    0

    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 4511 posts 10090 karma points MVP 2x admin c-trib
    Jul 18, 2016 @ 11:22
    Ismail Mayat
    0

    Lee,

    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

    Regards

    Ismail

  • Markus Johansson 1911 posts 5757 karma points MVP c-trib
    Dec 01, 2016 @ 10:15
    Markus Johansson
    0

    Hi!

    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 1130 posts 3088 karma points
    Aug 18, 2016 @ 08:44
    Lee
    0

    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
    nurul
    0

    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:

Draft