コード例 #1
0
ファイル: SqlIndexRecordWriter.cs プロジェクト: vedph/embix
        /// <summary>
        /// Writes the specified record.
        /// </summary>
        /// <param name="record">The record, whose token can be null if
        /// already written.</param>
        /// <param name="parts">The parts of the record to be written.</param>
        /// <exception cref="System.ArgumentNullException">record</exception>
        /// <exception cref="ArgumentNullException">record</exception>
        public void Write(IndexRecord record,
                          IndexRecordParts parts = IndexRecordParts.All)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            // write token if any
            if (record.Token != null && ((parts & IndexRecordParts.Token) != 0))
            {
                Query query = _queryFactory.Query("token")
                              .AsInsert(record.Names.TokenNames, record.Token);
                _queryFactory.Execute(query);
            }

            // write occurrence if any
            if (record.Occurrence != null &&
                ((parts & IndexRecordParts.Occurrence) != 0))
            {
                Query query = _queryFactory.Query("occurrence")
                              .AsInsert(record.Names.OccurrenceNames, record.Occurrence);
                _queryFactory.Execute(query);
            }
        }
コード例 #2
0
ファイル: SqlIndexRecordWriter.cs プロジェクト: vedph/embix
        /// <summary>
        /// Writes all the specified records at once.
        /// </summary>
        /// <param name="records">The records.</param>
        /// <param name="parts">The parts of the record to be written.</param>
        /// <exception cref="ArgumentNullException">records</exception>
        public void Write(IList <IndexRecord> records,
                          IndexRecordParts parts = IndexRecordParts.All)
        {
            if (records == null)
            {
                throw new ArgumentNullException(nameof(records));
            }
            if (records.Count == 0)
            {
                return;
            }

            // write tokens
            if ((parts & IndexRecordParts.Token) != 0)
            {
                object[][] tokens = records
                                    .Where(r => r.Token != null)
                                    .Select(r => r.Token).ToArray();
                if (tokens.Length > 0)
                {
                    Query query = _queryFactory.Query("token")
                                  .AsInsert(records[0].Names.TokenNames, tokens);
                    _queryFactory.Execute(query);
                }
            }

            // write occurences
            if ((parts & IndexRecordParts.Occurrence) != 0)
            {
                object[][] occurrences = records
                                         .Where(r => r.Occurrence != null)
                                         .Select(r => r.Occurrence).ToArray();
                if (occurrences.Length > 0)
                {
                    Query query = _queryFactory.Query("occurrence")
                                  .AsInsert(records[0].Names.OccurrenceNames, occurrences);
                    _queryFactory.Execute(query);
                }
            }
        }