Package org.apache.lucene.store

Examples of org.apache.lucene.store.OutputStream


    fieldInfos.add(testDoc);
    //Since the complement is stored as well in the fields map
    assertTrue(fieldInfos.size() == 7); //this is 7 b/c we are using the no-arg constructor
    RAMDirectory dir = new RAMDirectory();
    String name = "testFile";
    OutputStream output = dir.createFile(name);
    assertTrue(output != null);
    //Use a RAMOutputStream
   
    try {
      fieldInfos.write(output);
      output.close();
      assertTrue(output.length() > 0);
      FieldInfos readIn = new FieldInfos(dir, name);
      assertTrue(fieldInfos.size() == readIn.size());
      FieldInfo info = readIn.fieldInfo("textField1");
      assertTrue(info != null);
      assertTrue(info.storeTermVector == false);
View Full Code Here


  /** Writes this vector to the file <code>name</code> in Directory
    <code>d</code>, in a format that can be read by the constructor {@link
    #BitVector(Directory, String)}.  */
  public final void write(Directory d, String name) throws IOException {
    OutputStream output = d.createFile(name);
    try {
      output.writeInt(size());        // write size
      output.writeInt(count());        // write count
      output.writeBytes(bits, bits.length);    // write bits
    } finally {
      output.close();
    }
  }
View Full Code Here

    quickSort(postings, left + 1, hi);
  }

  private final void writePostings(Posting[] postings, String segment)
          throws IOException {
    OutputStream freq = null, prox = null;
    TermInfosWriter tis = null;
    TermVectorsWriter termVectorWriter = null;
    try {
      //open files for inverse index storage
      freq = directory.createFile(segment + ".frq");
      prox = directory.createFile(segment + ".prx");
      tis = new TermInfosWriter(directory, segment, fieldInfos);
      TermInfo ti = new TermInfo();
      String currentField = null;

      for (int i = 0; i < postings.length; i++) {
        Posting posting = postings[i];

        // add an entry to the dictionary with pointers to prox and freq files
        ti.set(1, freq.getFilePointer(), prox.getFilePointer(), -1);
        tis.add(posting.term, ti);

        // add an entry to the freq file
        int postingFreq = posting.freq;
        if (postingFreq == 1)          // optimize freq=1
          freq.writeVInt(1);        // set low bit of doc num.
        else {
          freq.writeVInt(0);        // the document number
          freq.writeVInt(postingFreq);        // frequency in doc
        }

        int lastPosition = 0;        // write positions
        int[] positions = posting.positions;
        for (int j = 0; j < postingFreq; j++) {      // use delta-encoding
          int position = positions[j];
          prox.writeVInt(position - lastPosition);
          lastPosition = position;
        }
        // check to see if we switched to a new field
        String termField = posting.term.field();
        if (currentField != termField) {
          // changing field - see if there is something to save
          currentField = termField;
          FieldInfo fi = fieldInfos.fieldInfo(currentField);
          if (fi.storeTermVector) {
            if (termVectorWriter == null) {
              termVectorWriter =
                new TermVectorsWriter(directory, segment, fieldInfos);
              termVectorWriter.openDocument();
            }
            termVectorWriter.openField(currentField);
          } else if (termVectorWriter != null) {
            termVectorWriter.closeField();
          }
        }
        if (termVectorWriter != null && termVectorWriter.isFieldOpen()) {
          termVectorWriter.addTerm(posting.term.text(), postingFreq);
        }
      }
      if (termVectorWriter != null)
        termVectorWriter.closeDocument();
    } finally {
      // make an effort to close all streams we can but remember and re-throw
      // the first exception encountered in this process
      IOException keep = null;
      if (freq != null) try { freq.close(); } catch (IOException e) { if (keep == null) keep = e; }
      if (prox != null) try { prox.close(); } catch (IOException e) { if (keep == null) keep = e; }
      if (tis  != null) try tis.close(); } catch (IOException e) { if (keep == null) keep = e; }
      if (termVectorWriter  != null) try termVectorWriter.close(); } catch (IOException e) { if (keep == null) keep = e; }
      if (keep != null) throw (IOException) keep.fillInStackTrace();
    }
View Full Code Here

  private final void writeNorms(Document doc, String segment) throws IOException {
    for(int n = 0; n < fieldInfos.size(); n++){
      FieldInfo fi = fieldInfos.fieldInfo(n);
      if(fi.isIndexed){
        float norm = fieldBoosts[n] * similarity.lengthNorm(fi.name, fieldLengths[n]);
        OutputStream norms = directory.createFile(segment + ".f" + n);
        try {
          norms.writeByte(similarity.encodeNorm(norm));
        } finally {
          norms.close();
        }
      }
    }
  }
View Full Code Here

    private boolean dirty;
    private int number;

    private void reWrite() throws IOException {
      // NOTE: norms are re-written in regular directory, not cfs
      OutputStream out = directory().createFile(segment + ".tmp");
      try {
        out.writeBytes(bytes, maxDoc());
      } finally {
        out.close();
      }
      String fileName = segment + ".f" + number;
      directory().renameFile(segment + ".tmp", fileName);
      this.dirty = false;
    }
View Full Code Here

    }
    return hasVectors;
  }

  public void write(Directory d, String name) throws IOException {
    OutputStream output = d.createFile(name);
    try {
      write(output);
    } finally {
      output.close();
    }
  }
View Full Code Here

  final int size() {
    return byNumber.size();
  }

  final void write(Directory d, String name) throws IOException {
    OutputStream output = d.createFile(name);
    try {
      write(output);
    } finally {
      output.close();
    }
  }
View Full Code Here

  private final void mergeNorms() throws IOException {
    for (int i = 0; i < fieldInfos.size(); i++) {
      FieldInfo fi = fieldInfos.fieldInfo(i);
      if (fi.isIndexed) {
  OutputStream output = directory.createFile(segment + ".f" + i);
  try {
    for (int j = 0; j < readers.size(); j++) {
      SegmentReader reader = (SegmentReader)readers.elementAt(j);
      BitVector deletedDocs = reader.deletedDocs;
      InputStream input = reader.normStream(fi.name);
            int maxDoc = reader.maxDoc();
      try {
        for (int k = 0; k < maxDoc; k++) {
    byte norm = input != null ? input.readByte() : (byte)0;
    if (deletedDocs == null || !deletedDocs.get(k))
      output.writeByte(norm);
        }
      } finally {
        if (input != null)
    input.close();
      }
    }
  } finally {
    output.close();
  }
      }
    }
  }
View Full Code Here

      input.close();
    }
  }

  public final void write(Directory directory) throws IOException {
    OutputStream output = directory.createFile("segments.new");
    try {
      output.writeInt(counter);        // write counter
      output.writeInt(size());        // write infos
      for (int i = 0; i < size(); i++) {
  SegmentInfo si = info(i);
  output.writeString(si.name);
  output.writeInt(si.docCount);
      }
    } finally {
      output.close();
    }

    // install new segment info
    directory.renameFile("segments.new", "segments");
  }
View Full Code Here

  /** Writes this vector to the file <code>name</code> in Directory
    <code>d</code>, in a format that can be read by the constructor {@link
    #BitVector(Directory, String)}.  */
  public final void write(Directory d, String name) throws IOException {
    OutputStream output = d.createFile(name);
    try {
      output.writeInt(size());        // write size
      output.writeInt(count());        // write count
      output.writeBytes(bits, bits.length);    // write bits
    } finally {
      output.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.store.OutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.