Пример #1
0
        /// <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
        /// <summary>
        /// Writes the specified token from the specified field.
        /// </summary>
        /// <param name="documentId">The ID of the document data being written
        /// belong to.</param>
        /// <param name="partitionNr">The partition number of the caller.</param>
        /// <param name="field">The field the token comes from.</param>
        /// <param name="token">The token value.</param>
        /// <param name="metadata">The optional metadata for this token.
        /// Some tokens might be accompanied by some metadata; e.g. language,
        /// read from their source. In this case they are stored into this
        /// dictionary.</param>
        public void Write(string documentId, int partitionNr, string field,
                          string token,
                          IDictionary <string, object> metadata = null)
        {
            Logger?.LogDebug($"[#{partitionNr:000}] Write: {documentId}.{field}: {token}");
            IndexRecord record = GetTokenRecord(documentId, field, token, metadata);

            EnqueueRecord(partitionNr, record);
        }
Пример #3
0
        /// <summary>
        /// Enqueues the specified token and its occurrence.
        /// </summary>
        /// <param name="partitionNr">The partition number.</param>
        /// <param name="record">The record.</param>
        protected void EnqueueRecord(int partitionNr, IndexRecord record)
        {
            // create the partition's buffer if it does not exist
            if (!_buffers.ContainsKey(partitionNr))
            {
                _buffers[partitionNr] = new IndexWriterBuffer(
                    GetRecordWriter(), _savedTokens);
            }
            IndexWriterBuffer buffer = _buffers[partitionNr];

            buffer.Add(record);

            // flush when buffer size limit reached
            if (buffer.Count >= BufferSize)
            {
                buffer.Flush();
            }
        }
Пример #4
0
 /// <summary>
 /// Adds the specified record to the buffer.
 /// </summary>
 /// <param name="record">The record.</param>
 public void Add(IndexRecord record)
 {
     _queue.Enqueue(record);
 }