/// <summary>
		/// Adds the information related to the new
		/// occurrence of the term in the field and
		/// position passed as argument. If a TermOccurrence
		/// object for the specified field
		/// is already in the collection, the new position
		/// information is simply added to the existing
		/// TermOccurrence object. Otherwise a new TermOccurrence
		/// object will be created and added to the
		/// collection.
		/// </summary>
		/// <param name="field">field where the term
		/// was found</param>
		/// <param name="position">
		/// position in the field where the term was found</param>
		public void Add(IndexedField field, int position)
		{
			foreach (TermOccurrence to in InnerList)
			{
				if (to.Field == field)
				{
					to.Add(position);
					return;
				}
			}
			InnerList.Add(new TermOccurrence(field, position));
		}
		void IndexByToken(Token token, IRecord record, IndexedField field)
		{
			Postings postings = (Postings)_postings[token.Value];
			if (null == postings)
			{
				postings = new Postings(token.Value);
				_postings[token.Value] = postings;
			}
			postings.Add(record, field, token.Position);
		}
		void IndexByField(IRecord record, IndexedField field)
		{
			string value = (string)record[field.Name];
			ITokenizer tokenizer = CreateTokenizer(value);
			Token token = tokenizer.NextToken();
			while (null != token)
			{
				IndexByToken(token, record, field);
				token = tokenizer.NextToken();
			}
		}
		/// <summary>
		/// Creates a new TermOccurrence for the
		/// field and position passed as arguments.
		/// </summary>
		/// <param name="field">the field where the term was found</param>
		/// <param name="position">the position where the term was found</param>
		public TermOccurrence(IndexedField field, int position)
		{
			_field = field;
			_positions = new int[] { position };
		}
Пример #5
0
		/// <summary>
		/// Adds a new occurrence of the term. The occurrence
		/// information (field and position) will be added
		/// to an existing Posting object whenever possible.
		/// </summary>
		/// <param name="record">the record where the term was found</param>
		/// <param name="field">the field where the term was found</param>
		/// <param name="position">the position in the field where the term was found</param>
		public void Add(IRecord record, IndexedField field, int position)
		{
			Posting posting = _postings[record] as Posting;
			if (null == posting)
			{
				posting = new Posting(record);
				_postings[record] = posting;
			}
			posting.Occurrences.Add(field, position);
		}