/// <summary> /// Updates the specified object in the IndexWriter. /// </summary> /// <typeparam name="T"> /// The type of the object to update. /// </typeparam> /// <param name="writer"> /// The IndexWriter to update the object in. /// </param> /// <param name="obj"> /// The new object to write. /// </param> /// <param name="settings"> /// The MappingSettings to use when creating the Document to add to the index. /// </param> /// <param name="predicate"> /// The predicate for selecting the item to update. /// </param> /// <param name="analyzer"> /// The Analyzer to use. /// </param> public static void Update <T>(this IndexWriter writer, T obj, MappingSettings settings, Expression <Func <T, bool> > predicate, Analyzer analyzer) { if (null == writer) { throw new ArgumentNullException("writer"); } else if (null == obj) { throw new ArgumentNullException("obj"); } else if (null == settings) { throw new ArgumentNullException("settings"); } else if (null == predicate) { throw new ArgumentNullException("predicate"); } else if (null == analyzer) { throw new ArgumentNullException("analyzer"); } MappedFieldResolver resolver = settings.ObjectMapper.GetMappedFieldResolver(); Query query = resolver.GetQuery(predicate); Update <T>(writer, obj, settings, query, analyzer); }
/// <summary> /// Deletes the matching objects in the IndexWriter. /// </summary> /// <typeparam name="T"> /// The type of the object to update. /// </typeparam> /// <param name="writer"> /// The IndexWriter to update the object in. /// </param> /// <param name="predicate"> /// The predicate for selecting the item to update. /// </param> public static void Delete <T>(this IndexWriter writer, Expression <Func <T, bool> > predicate) { if (null == writer) { throw new ArgumentNullException("writer"); } else if (null == predicate) { throw new ArgumentNullException("predicate"); } MappingSettings settings = MappingSettings.Default; MappedFieldResolver resolver = settings.ObjectMapper.GetMappedFieldResolver(); Query query = resolver.GetQuery(predicate); DeleteDocuments <T>(writer, query); }