示例#1
0
        private Term termBuffer = new Term("", ""); // avoid consing

        private void  AddPosition(System.String field, System.String text, int position)
        {
            termBuffer.Set(field, text);
            Posting ti = (Posting)postingTable[termBuffer];

            if (ti != null)
            {
                // word seen before
                int freq = ti.freq;
                if (ti.positions.Length == freq)
                {
                    // positions array is full
                    int[] newPositions = new int[freq * 2]; // double size
                    int[] positions    = ti.positions;
                    for (int i = 0; i < freq; i++)
                    {
                        // copy old positions to new
                        newPositions[i] = positions[i];
                    }
                    ti.positions = newPositions;
                }
                ti.positions[freq] = position; // add new position
                ti.freq            = freq + 1; // update frequency
            }
            else
            {
                // word not seen before
                Term term = new Term(field, text, false);
                postingTable[term] = new Posting(term, position);
            }
        }