Example #1
0
        private static void Upload <T>(ISearchIndexClient indexClient, IEnumerable <T> docs)
            where T : class
        {
            var batch = IndexBatch.MergeOrUpload(docs);

            try
            {
                indexClient.Documents.Index(batch);
            }
            catch (IndexBatchException e)
            {
                Console.WriteLine(
                    "Failed to index some of the documents: {0}",
                    String.Join(", ", e.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key)));
            }
        }
Example #2
0
        /// <summary>
        /// Creates a new IndexBatch for merging documents into existing documents in the index.
        /// </summary>
        /// <typeparam name="T">
        /// The CLR type that maps to the index schema. Instances of this type can be stored as documents in the index.
        /// </typeparam>
        /// <param name="documents">The documents to merge; Set only the properties that you want to change.</param>
        /// <returns>A new IndexBatch.</returns>
        /// <remarks>
        /// If type T contains non-nullable value-typed properties, these properties may not merge correctly. If you
        /// do not set such a property, it will automatically take its default value (for example, 0 for int or false
        /// for bool), which will override the value of the property currently stored in the index, even if this was
        /// not your intent. For this reason, it is strongly recommended that you always declare value-typed
        /// properties to be nullable in type T.
        /// </remarks>
        public static IndexBatch <T> Merge <T>(IEnumerable <T> documents) where T : class
        {
            Throw.IfArgumentNull(documents, "documents");

            return(IndexBatch.New(documents.Select(d => IndexAction.Merge(d))));
        }
Example #3
0
        /// <summary>
        /// Creates a new IndexBatch for merging documents into existing documents in the index.
        /// </summary>
        /// <param name="documents">The documents to merge; Set only the fields that you want to change.</param>
        /// <returns>A new IndexBatch.</returns>
        public static IndexBatch Merge(IEnumerable <Document> documents)
        {
            Throw.IfArgumentNull(documents, "documents");

            return(IndexBatch.New(documents.Select(d => IndexAction.Merge(d))));
        }