/// <summary> /// Updates the Document identified by its _id field. /// </summary> /// <param name="document">The document.</param> /// <exception cref="ArgumentNullException">document</exception> public void Update(Document document) { if (document == null) throw new ArgumentNullException(nameof(document)); if (document._id == null || document._id == Guid.Empty) throw new InvalidOperationException("Cannot update Document that does not have an _id"); var luceneDocument = document.ToLuceneDocument(Schema, _facetBuilder); var id = document._id.ToString().ToLower(); var idTerm = new Term(Schema.StandardField.ID, id); _writeAllowedFlag.Wait(); _indexWriter.UpdateDocument(idTerm, luceneDocument); }
/// <summary> /// Inserts a dynamic document into the index. /// </summary> /// <param name="document">The dynamic document.</param> public void Insert(Document document) { if (document == null) throw new ArgumentNullException(nameof(document)); if (document._id == null || document._id.Value == Guid.Empty) document._id = Guid.NewGuid(); var luceneDocument = document.ToLuceneDocument(Schema, _facetBuilder); _writeAllowedFlag.Wait(); _indexWriter.AddDocument(luceneDocument); }