CatalogWordFile.cs
上传用户:huiyue
上传日期:2022-04-08
资源大小:1429k
文件大小:3k
源码类别:

搜索引擎

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Xml.Serialization;
  5. namespace Searcharoo.Common
  6. {
  7.     /// <summary>
  8.     /// Used solely by the <see cref="Catalog"/> class to XmlSerialize the index
  9.     /// to disk when binary serialization will not work due to Trust level issues.
  10.     /// </summary>
  11.     [Serializable]
  12.     public class CatalogWordFile
  13.     {
  14.         #region Private Fields: _text, _fileIds
  15.         private string _text;
  16.         //private List<int> _fileIds = new List<int>();
  17.         Dictionary<int, List<int>> _FileIdsWithPosition;
  18.         #endregion
  19.         public CatalogWordFile()
  20.         {
  21.             _FileIdsWithPosition = new Dictionary<int, List<int>>();
  22.         }
  23.         /// <summary>
  24.         /// The word that has been indexed
  25.         /// </summary>
  26.         [XmlElement("t")]
  27.         public string Text
  28.         {
  29.             get { return _text; }
  30.             set { _text = value; }
  31.         }
  32.         /// <summary>
  33.         /// The 'generated identifiers' of the File objects associated with the Word
  34.         /// </summary>
  35.         [XmlElement("ii")]
  36.         public string[] FileIdsWithPositionString
  37.         {
  38.             get 
  39.             {
  40.                 List<string> l = new List<string>();
  41.                 string f = "";
  42.                 foreach (int fileId in _FileIdsWithPosition.Keys)
  43.                 {
  44.                     f = "";
  45.                     foreach (int wordPosition in _FileIdsWithPosition[fileId])
  46.                     {
  47.                         f += wordPosition + ",";
  48.                     }
  49.                     l.Add(fileId.ToString() + ":" + f.Trim(','));
  50.                 }
  51.                 return l.ToArray(); 
  52.             }
  53.             set 
  54.             { 
  55.                 //List<string> l = value;
  56.                 string[] l = value;
  57.                 //_fileIds = new List<int>();
  58.                 foreach (string fileInfo in l)
  59.                 {
  60.                     string[] fileInfoA = fileInfo.Split(':');
  61.                     int fileId = Convert.ToInt32(fileInfoA[0]);
  62.                     string[] wordPositionsA = fileInfoA[1].Split(',');
  63.                     List<int> wordPositions = new List<int>();
  64.                     foreach (string s in wordPositionsA)
  65.                     {
  66.                         wordPositions.Add(Convert.ToInt32(s));
  67.                     }
  68.                     //_fileIds.Add(fileId);
  69.                     _FileIdsWithPosition.Add(fileId, wordPositions);
  70.                 }
  71.             }
  72.         }
  73.         /// <summary>
  74.         /// The 'generated identifiers' of the File objects associated with the Word
  75.         /// and all the 'position indexes' of that Word in that File (comma-seperate
  76.         /// </summary>
  77.         [XmlIgnore]
  78.         public Dictionary<int, List<int>> FileIdsWithPosition
  79.         {
  80.             get { return _FileIdsWithPosition; }
  81.             set { _FileIdsWithPosition = value; }
  82.         }
  83.         ///// <summary>
  84.         ///// The 'generated identifiers' of the File objects associated with the Word
  85.         ///// </summary>
  86.         //[XmlElement("i")]
  87.         //[Obsolete("Replaced by FileIdsWithPositionString in [v7]")]
  88.         //public List<int> FileIds
  89.         //{
  90.         //    get { return _fileIds; }
  91.         //    set { _fileIds = value; }
  92.         //}
  93.     }
  94. }