Copied to clipboard

Flag this post as spam?

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


  • Bharath 40 posts 62 karma points
    Jun 25, 2010 @ 00:04
    Bharath
    0

    UmbracoExamine clarification creating a custom field in lucene index

    Can we create a custom field in Lucene Index file that is created by Umbraco Examine?

    Lets say i need to create a custom field named "CONTENT" that should contain all the tokenized string/word of UserFields in umbraco documents.

    ForExample

    NodeTypeAlias: AboutUs

    Contains UserFields: Field1, Field2, Field3

    UserFields contains LONG text that need to be tokenized.

    Tokenized words needs to be stored ONLY in lucene index custom column "CONTENT"

    CONTENT should contain all the TOKENIZED word, so that i can execute a lucene query like CONTENT:searchword

    GroupBy NodeId and then i can get the desired nodes and display to the users search results page.

    Is that possible to define a custom field using UmbracoExamine and direct the userfields tokenized words only to the one custom field in lucene index?

  • Travis 19 posts 46 karma points
    Jan 14, 2011 @ 11:39
    Travis
    0

    I am a bit late but something like this might work.  

     

     

    public class ExamineEvents : ApplicationBase 
    {
         public ExamineEvents()
            {
                 ExamineManager.Instance.IndexProviderCollection["indexername"].GatheringNodeData += ExamineEvents_GatheringNodeData;
        }
    
        void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
            {
            if (e.IndexType == IndexTypes.Content)
    
                {
                if (n.NodeTypeAlias == "somenodetype")
                        {
              // do some logic to work out the values
                e.Fields.Add("CustomField", Values );
                }
            }
    
        }
    
    }

     

     

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 14, 2011 @ 12:19
    Ismail Mayat
    0

    bharth,

    like travis's code however where you have e.fields.add call the following method:

    private void AddToContentsField(IndexingNodeDataEventArgs e)
            {
                Dictionary<string, string> fields = e.Fields;
                var combinedFields = new StringBuilder();
                foreach (KeyValuePair<string, string> keyValuePair in fields)
                {              
                    combinedFields.AppendLine(keyValuePair.Value);              
                }
                e.Fields.Add("contents",combinedFields.ToString());
            }

    eg

    AddToContentsField(e);

    that will take all your fields defined and contenate them to one field called contents that you can search on.  I did for site i built.

    Regards

     

    Ismail

     

Please Sign in or register to post replies

Write your reply to:

Draft