Example #1
0
        /// <summary>
        /// Get the specify document position list from .idx file
        /// </summary>
        /// <param name="position">the position of the first byte of the index</param>
        /// <param name="length">index content length</param>
        /// <param name="count">max count of the documents that want read</param>
        /// <param name="simple">is it simple index mode</param>
        /// <returns>Word position list</returns>
        public WordDocumentsList GetDocList(long position, long length, int count, bool simple)
        {
            Query.PerformanceReport performanceReport = new Hubble.Core.Query.PerformanceReport();

            _IndexFile.Seek(position, System.IO.SeekOrigin.Begin);

            WordDocumentsList result = new WordDocumentsList();

            if (count >= 0)
            {
                result.AddRange(Entity.DocumentPositionList.Deserialize(_IndexFile, ref count, simple, out result.WordCountSum));
                result.RelDocCount = count;
            }
            else
            {
                result.AddRange(Entity.DocumentPositionList.Deserialize(_IndexFile, simple, out result.WordCountSum));
                result.RelDocCount = result.Count;
            }

            performanceReport.Stop(string.Format("Read index file: len={0}, {1} results. ", _IndexFile.Position - position,
                                                 result.Count));

            return(result);
        }
Example #2
0
        internal Hubble.Core.Index.WordIndexReader GetWordIndex(string word,
                                                                WordFilePositionList filePositionList, int totalDocs, Data.DBProvider dbProvider, int maxReturnCount)
        {
            WordDocumentsList docList = new WordDocumentsList();

            bool simple = _IndexMode == Hubble.Core.Data.Field.IndexMode.Simple;

            if (maxReturnCount < 0)
            {
                foreach (FilePosition filePosition in filePositionList.FPList)
                {
                    IDXFile idxFile = GetIDXFile(filePosition.Serial);

                    if (idxFile == null)
                    {
                        continue;
                    }

                    WordDocumentsList wdl = idxFile.GetDocList(filePosition.Position, filePosition.Length, -1, simple);

                    if (filePositionList.Count == 1)
                    {
                        docList = wdl;
                    }
                    else
                    {
                        docList.AddRange(wdl);
                        docList.WordCountSum += wdl.WordCountSum;
                    }
                }
            }
            else
            {
                int remain = maxReturnCount;

                foreach (FilePosition filePosition in filePositionList.FPList)
                {
                    IDXFile idxFile = GetIDXFile(filePosition.Serial);

                    if (idxFile == null)
                    {
                        continue;
                    }

                    WordDocumentsList wdl = idxFile.GetDocList(filePosition.Position, filePosition.Length, remain, simple);

                    if (filePositionList.Count == 1)
                    {
                        docList = wdl;
                    }
                    else
                    {
                        docList.AddRange(wdl);
                        docList.WordCountSum += wdl.WordCountSum;
                        docList.RelDocCount  += wdl.RelDocCount;
                    }

                    remain -= wdl.Count;
                }
            }

            return(new WordIndexReader(word, docList, totalDocs, dbProvider));
        }