示例#1
0
            public virtual void IndexDoc()
            {
                Document d = new Document();

                FieldType customType1 = new FieldType(TextField.TYPE_STORED);

                customType1.Tokenized = false;
                customType1.OmitNorms = true;

                List <Field> fields   = new List <Field>();
                string       idString = IdString;
                Field        idField  = NewField("id", idString, customType1);

                fields.Add(idField);

                int nFields = NextInt(MaxFields);

                for (int i = 0; i < nFields; i++)
                {
                    FieldType customType = new FieldType();
                    switch (NextInt(4))
                    {
                    case 0:
                        break;

                    case 1:
                        customType.StoreTermVectors = true;
                        break;

                    case 2:
                        customType.StoreTermVectors         = true;
                        customType.StoreTermVectorPositions = true;
                        break;

                    case 3:
                        customType.StoreTermVectors       = true;
                        customType.StoreTermVectorOffsets = true;
                        break;
                    }

                    switch (NextInt(4))
                    {
                    case 0:
                        customType.Stored    = true;
                        customType.OmitNorms = true;
                        customType.Indexed   = true;
                        fields.Add(NewField("f" + NextInt(100), GetString(1), customType));
                        break;

                    case 1:
                        customType.Indexed   = true;
                        customType.Tokenized = true;
                        fields.Add(NewField("f" + NextInt(100), GetString(0), customType));
                        break;

                    case 2:
                        customType.Stored                   = true;
                        customType.StoreTermVectors         = false;
                        customType.StoreTermVectorOffsets   = false;
                        customType.StoreTermVectorPositions = false;
                        fields.Add(NewField("f" + NextInt(100), GetString(0), customType));
                        break;

                    case 3:
                        customType.Stored    = true;
                        customType.Indexed   = true;
                        customType.Tokenized = true;
                        fields.Add(NewField("f" + NextInt(100), GetString(BigFieldSize), customType));
                        break;
                    }
                }

                if (SameFieldOrder)
                {
                    fields.Sort(fieldNameComparator);
                }
                else
                {
                    // random placement of id field also
                    CollectionsHelper.Swap(fields, NextInt(fields.Count), 0);
                }

                for (int i = 0; i < fields.Count; i++)
                {
                    d.Add(fields[i]);
                }
                if (VERBOSE)
                {
                    Console.WriteLine(Thread.CurrentThread.Name + ": indexing id:" + idString);
                }
                w.UpdateDocument(new Term("id", idString), d);
                //System.out.println(Thread.currentThread().getName() + ": indexing "+d);
                Docs[idString] = d;
            }