Пример #1
0
        private Term termBuffer = new Term("", "");         // avoid consing

        private void  AddPosition(System.String field, System.String text, int position, TermVectorOffsetInfo offset)
        {
            termBuffer.Set(field, text);
            //System.out.println("Offset: " + offset);
            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

                if (offset != null)
                {
                    if (ti.offsets.Length == freq)
                    {
                        TermVectorOffsetInfo[] newOffsets = new TermVectorOffsetInfo[freq * 2];
                        TermVectorOffsetInfo[] offsets    = ti.offsets;
                        for (int i = 0; i < freq; i++)
                        {
                            newOffsets[i] = offsets[i];
                        }
                        ti.offsets = newOffsets;
                    }
                    ti.offsets[freq] = offset;
                }
                ti.freq = freq + 1;                 // update frequency
            }
            else
            {
                // word not seen before
                Term term = new Term(field, text, false);
                postingTable[term] = new Posting(term, position, offset);
            }
        }
Пример #2
0
            public override void Run()
            {
                DirectoryReader currentReader = null;
                Random          random        = LuceneTestCase.Random;

                try
                {
                    Document doc = new Document();
                    doc.Add(new TextField("id", "1", Field.Store.NO));
                    writer.AddDocument(doc);
                    holder.reader = currentReader = writer.GetReader(true);
                    Term term = new Term("id");
                    for (int i = 0; i < numOps && !holder.stop; i++)
                    {
                        float nextOp = (float)random.NextDouble();
                        if (nextOp < 0.3)
                        {
                            term.Set("id", new BytesRef("1"));
                            writer.UpdateDocument(term, doc);
                        }
                        else if (nextOp < 0.5)
                        {
                            writer.AddDocument(doc);
                        }
                        else
                        {
                            term.Set("id", new BytesRef("1"));
                            writer.DeleteDocuments(term);
                        }
                        if (holder.reader != currentReader)
                        {
                            holder.reader = currentReader;
                            if (countdown)
                            {
                                countdown = false;
                                latch.Signal();
                            }
                        }
                        if (random.NextBoolean())
                        {
                            writer.Commit();
                            DirectoryReader newReader = DirectoryReader.OpenIfChanged(currentReader);
                            if (newReader != null)
                            {
                                currentReader.DecRef();
                                currentReader = newReader;
                            }
                            if (currentReader.NumDocs == 0)
                            {
                                writer.AddDocument(doc);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    failed = e;
                }
                finally
                {
                    holder.reader = null;
                    if (countdown)
                    {
                        latch.Signal();
                    }
                    if (currentReader != null)
                    {
                        try
                        {
                            currentReader.DecRef();
                        }
#pragma warning disable 168
                        catch (IOException e)
#pragma warning restore 168
                        {
                        }
                    }
                }
                if (Verbose)
                {
                    Console.WriteLine("writer stopped - forced by reader: " + holder.stop);
                }
            }
Пример #3
0
            public override void Run()
            {
                DirectoryReader currentReader = null;
                Random          random        = LuceneTestCase.Random();

                try
                {
                    Document doc = new Document();
                    doc.Add(new TextField("id", "1", Field.Store.NO));
                    Writer.AddDocument(doc);
                    Holder.Reader = currentReader = Writer.GetReader(true);
                    Term term = new Term("id");
                    for (int i = 0; i < NumOps && !Holder.Stop; i++)
                    {
                        float nextOp = (float)random.NextDouble();
                        if (nextOp < 0.3)
                        {
                            term.Set("id", new BytesRef("1"));
                            Writer.UpdateDocument(term, doc);
                        }
                        else if (nextOp < 0.5)
                        {
                            Writer.AddDocument(doc);
                        }
                        else
                        {
                            term.Set("id", new BytesRef("1"));
                            Writer.DeleteDocuments(term);
                        }
                        if (Holder.Reader != currentReader)
                        {
                            Holder.Reader = currentReader;
                            if (Countdown)
                            {
                                Countdown = false;
                                Latch.Signal();
                            }
                        }
                        if (random.NextBoolean())
                        {
                            Writer.Commit();
                            DirectoryReader newReader = DirectoryReader.OpenIfChanged(currentReader);
                            if (newReader != null)
                            {
                                currentReader.DecRef();
                                currentReader = newReader;
                            }
                            if (currentReader.NumDocs == 0)
                            {
                                Writer.AddDocument(doc);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Failed = e;
                }
                finally
                {
                    Holder.Reader = null;
                    if (Countdown)
                    {
                        Latch.Signal();
                    }
                    if (currentReader != null)
                    {
                        try
                        {
                            currentReader.DecRef();
                        }
                        catch (IOException e)
                        {
                        }
                    }
                }
                if (VERBOSE)
                {
                    Console.WriteLine("writer stopped - forced by reader: " + Holder.Stop);
                }
            }
 public override void Run()
 {
     DirectoryReader currentReader = null;
     Random random = LuceneTestCase.Random();
     try
     {
         Document doc = new Document();
         doc.Add(new TextField("id", "1", Field.Store.NO));
         Writer.AddDocument(doc);
         Holder.Reader = currentReader = Writer.GetReader(true);
         Term term = new Term("id");
         for (int i = 0; i < NumOps && !Holder.Stop; i++)
         {
             float nextOp = (float)random.NextDouble();
             if (nextOp < 0.3)
             {
                 term.Set("id", new BytesRef("1"));
                 Writer.UpdateDocument(term, doc);
             }
             else if (nextOp < 0.5)
             {
                 Writer.AddDocument(doc);
             }
             else
             {
                 term.Set("id", new BytesRef("1"));
                 Writer.DeleteDocuments(term);
             }
             if (Holder.Reader != currentReader)
             {
                 Holder.Reader = currentReader;
                 if (Countdown)
                 {
                     Countdown = false;
                     Latch.Signal();
                 }
             }
             if (random.NextBoolean())
             {
                 Writer.Commit();
                 DirectoryReader newReader = DirectoryReader.OpenIfChanged(currentReader);
                 if (newReader != null)
                 {
                     currentReader.DecRef();
                     currentReader = newReader;
                 }
                 if (currentReader.NumDocs == 0)
                 {
                     Writer.AddDocument(doc);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Failed = e;
     }
     finally
     {
         Holder.Reader = null;
         if (Countdown)
         {
             Latch.Signal();
         }
         if (currentReader != null)
         {
             try
             {
                 currentReader.DecRef();
             }
             catch (IOException e)
             {
             }
         }
     }
     if (VERBOSE)
     {
         Console.WriteLine("writer stopped - forced by reader: " + Holder.Stop);
     }
 }