Copied to clipboard

Flag this post as spam?

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


  • Mila Pandurska 43 posts 190 karma points
    Feb 10, 2018 @ 11:14
    Mila Pandurska
    0

    Lucene search using GatheringNodeData and DocumentWriting togather

    Hi, I am developing a bit complicated search and I need to use both GatheringNodeData and DocumentWriting. I save a property called "plan" on GatheringNodeData event and I want to make boost on that property value in DocumentWriting. The problem is that when I update an item in the Umbraco back office the new value of "plan" is saved properly but in the event DocumentWriting it gets the old value. If I make publish again it is fine. Why DocumentWriting doesn't get the updated value of the property at the time it is firing? The code in the DocumentWriting event is

     indexer.DocumentWriting += DocWriting;
    indexer.GatheringNodeData +=  OnExamineGatheringNodeData;
    
     private void DocWriting(object sender, DocumentWritingEventArgs e)
            {
                    //boost premium venues
                    if(e.Fields.ContainsKey("planName"))
                    {
                        string plan = e.Fields["planName"].ToString();
    
                        if (plan == "Gold"")
                        {
                            e.Document.SetBoost(1.5f);
                        }
                    }
    }
    

    The code in the GatheringNodeData is:

    private void OnExamineGatheringNodeData(object sender, IndexingNodeDataEventArgs e, UmbracoHelper helper)
     { 
             string plan="Gold"; //my own logic here
             e.Fields.Add("planName", plan);
    }
    

    I noticed that OnExamineGatheringNodeData is firing first so I expected that the new value is saved for the DocWriting.

  • John Bergman 483 posts 1132 karma points
    Feb 11, 2018 @ 19:47
    John Bergman
    0

    This is something I was also trying to do with no current solution, have you determine how to get this to work?

  • Thanh Pham 23 posts 140 karma points
    Feb 12, 2018 @ 05:57
    Thanh Pham
    0

    Hi Mila,

    The DocumentWriting event might still read data from cache's index. You properly need to commit and flush index in GatheringNodeData. Let me know how you go.

    Pseudo code:

    Create index writer
    indexWriter.UpdateDocument();
    indexWriter.Commit();
    indexWriter.Flush();
    indexWriter.Close();
    

    You need to pass relevant parameters to those methods to make them work. Good luck.

  • Mila Pandurska 43 posts 190 karma points
    Feb 17, 2018 @ 17:20
    Mila Pandurska
    0

    Hi, Thanh, 1. I am not sure how to call indexWriter.UpdateDocument(new Term("planBoostingValue", sb.ToString()), new Document()); from OnExamineGatheringNodeData method because I don't know what to pass as second parameter (Document). 2. VS warns me that Flush() is obsolete and should call Commit() insted. 3. In addition I after I call indexWriter.Close(); I got exception:Message = "this IndexWriter is closed" - I get this message the second time when I click "Save and Publish"

    Thanks

  • Thanh Pham 23 posts 140 karma points
    Feb 18, 2018 @ 23:10
    Thanh Pham
    0

    Hi Mila,

    1. The second param for the UpdateDocument is an Document which you can get it from DocumentWritingEventArgs (e.Document). According to Lucene.NET the UpdateDocument will update a document by first deleting document(s) containing term and then adding the new document. However I tried this last time and it did not delete documents, instead it just added new docs. In this case you might need to manually delete docs by calling DeleteDocuments method.
    2. Correct.
    3. Hmm not sure why you got that. Can you check if you tried to close the IndexWriter twice? Can you see if there is anything helpful from the log?
  • Thanh Pham 23 posts 140 karma points
    Feb 19, 2018 @ 22:27
    Thanh Pham
    0

    Hi Mila,

    Re #3 please note that when there is an unhandled exception and you couldn't close the indexwriter, you might get this error if there is another method trying to access the index folder.

Please Sign in or register to post replies

Write your reply to:

Draft