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
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.
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"
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.
Correct.
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?
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.
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
The code in the GatheringNodeData is:
I noticed that OnExamineGatheringNodeData is firing first so I expected that the new value is saved for the DocWriting.
This is something I was also trying to do with no current solution, have you determine how to get this to work?
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:
You need to pass relevant parameters to those methods to make them work. Good luck.
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 callindexWriter.Close();
I got exception:Message = "this IndexWriter is closed" - I get this message the second time when I click "Save and Publish"Thanks
Hi Mila,
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.
is working on a reply...