Last active
January 20, 2021 17:06
-
-
Save enkelmedia/fbc9de7e92581c075d9762276f8862c2 to your computer and use it in GitHub Desktop.
Update field in Lucene / Examine index (Umbraco 8 v8 -specific)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var index = (LuceneIndex)ExamineManager.Instance.Indexes.Where(f => f.Name == "ExternalIndex").FirstOrDefault(); | |
// Get the IndexWriter | |
var writer = index.GetIndexWriter(); | |
var searcher = (BaseLuceneSearcher)index.GetSearcher(); | |
// perform search to get the doc from the index based on node id | |
Term term = new Term("id", "1082"); // Term to get node by id | |
var q = new TermQuery(term); | |
var sres = searcher.GetLuceneSearcher().Search(q, 1); | |
var doc = searcher.GetLuceneSearcher().Doc(sres.ScoreDocs.First().Doc); | |
doc.RemoveFields("testing"); | |
doc.Add(new Field("testing", "Hallo world mamma", Field.Store.YES, Field.Index.ANALYZED)); | |
writer.UpdateDocument(term,doc); | |
//writer.Commit(); | |
//writer.Optimize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment