Esempio n. 1
0
        /// <summary>
        /// Indexes a single entity with the provided definition
        /// </summary>
        /// <typeparam name="TEntity">The type of entity to index</typeparam>
        /// <param name="entity">The entity to index</param>
        /// <param name="definition">The index definition</param>
        /// <returns>An index result with the outcome of the indexing operation</returns>
        public IndexResult IndexEntity <TEntity>(TEntity entity, IIndexDefinition <TEntity> definition) where TEntity : class
        {
            var result = new IndexResult();

            result.ExecutionTime = Time(() =>
            {
                this.GetWriter().UpdateDocument(definition.GetIndex(entity), definition.Convert(entity));
                result.Count++;
                result.Success = true;
            });

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Indexes a collection of entities using a delegate index definition
        /// </summary>
        /// <typeparam name="TEntity">The type of entity to index</typeparam>
        /// <param name="entities">A list of entities</param>
        /// <param name="converter">The delegate converter</param>
        /// <returns>An index result with the outcome of the indexing operation</returns>
        public IndexResult IndexEntities <TEntity>(IEnumerable <TEntity> entities, Func <TEntity, Document> converter)
        {
            var result = new IndexResult();

            result.ExecutionTime = Time(() =>
            {
                foreach (TEntity entity in entities)
                {
                    this.GetWriter().AddDocument(converter(entity));
                    result.Count++;
                }
                result.Success = true;
            });

            return(result);
        }