Exemplo n.º 1
0
    public void run() {
      try {
        for (int i = 0; i < 1024 * 16; i++) {
          Document d = new Document();
          int n = RANDOM.nextInt();
          d.add(Field.Keyword("id", Integer.toString(n)));
          d.add(Field.UnStored("contents", intToEnglish(n)));
          System.out.println("Adding " + n);
          writer.addDocument(d);

          if (i % reopenInterval == 0) {
            writer.close();
            writer = new IndexWriter("index", ANALYZER, false);
          }
        }
      } catch (Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
        System.exit(0);
      }
    }
Exemplo n.º 2
0
  final Document doc(int n) throws IOException {
    indexStream.seek(n * 8L);
    long position = indexStream.readLong();
    fieldsStream.seek(position);

    Document doc = new Document();
    int numFields = fieldsStream.readVInt();
    for (int i = 0; i < numFields; i++) {
      int fieldNumber = fieldsStream.readVInt();
      FieldInfo fi = fieldInfos.fieldInfo(fieldNumber);

      byte bits = fieldsStream.readByte();

      doc.add(
          new Field(
              fi.name, // name
              fieldsStream.readString(), // read value
              true, // stored
              fi.isIndexed, // indexed
              (bits & 1) != 0)); // tokenized
    }

    return doc;
  }