Esempio n. 1
0
        /// <summary>Return all term vectors stored for this document or null if the could not be read in. </summary>
        internal virtual TermFreqVector[] Get(int docNum)
        {
            lock (this)
            {
                TermFreqVector[] result = null;
                // Check if no term vectors are available for this segment at all
                if (tvx != null)
                {
                    try
                    {
                        //We need to offset by
                        tvx.Seek((docNum * 8L) + TermVectorsWriter.FORMAT_SIZE);
                        long position = tvx.ReadLong();

                        tvd.Seek(position);
                        int fieldCount = tvd.ReadVInt();

                        // No fields are vectorized for this document
                        if (fieldCount != 0)
                        {
                            int             number = 0;
                            System.String[] fields = new System.String[fieldCount];

                            for (int i = 0; i < fieldCount; i++)
                            {
                                number   += tvd.ReadVInt();
                                fields[i] = fieldInfos.FieldName(number);
                            }

                            // Compute position in the tvf file
                            position = 0;
                            long[] tvfPointers = new long[fieldCount];
                            for (int i = 0; i < fieldCount; i++)
                            {
                                position      += tvd.ReadVLong();
                                tvfPointers[i] = position;
                            }

                            result = ReadTermVectors(fields, tvfPointers);
                        }
                    }
                    catch (System.IO.IOException e)
                    {
                        Console.Error.Write(e.StackTrace);
                        Console.Error.Flush();
                    }
                }
                else
                {
                    System.Console.Out.WriteLine("No tvx file");
                }
                return(result);
            }
        }
Esempio n. 2
0
        private Term ReadTerm()
        {
            int start       = input.ReadVInt();
            int length      = input.ReadVInt();
            int totalLength = start + length;

            if (buffer.Length < totalLength)
            {
                GrowBuffer(totalLength);
            }

            input.ReadChars(buffer, start, length);
            return(new Term(fieldInfos.FieldName(input.ReadVInt()), new System.String(buffer, 0, totalLength), false));
        }