示例#1
0
  private void indexNoCommit(CObj o, boolean onlynew) throws IOException {
    if (o.getDig() == null && o.getId() == null) {
      throw new IOException("Digest or id required!");
    }

    boolean indexit = true;
    Term updateterm = null;

    if (o.getId() != null) {
      updateterm = new Term("id", o.getId());
      Query id0 = new TermQuery(updateterm);

      if (onlynew) {
        CObjList cl = search(id0, 1);
        indexit = (cl.size() == 0);
        cl.close();
      }
    }

    if (o.getDig() != null && o.getId() == null) {
      updateterm = new Term("dig", o.getDig());
      Query id0 = new TermQuery(updateterm);

      if (onlynew) {
        CObjList cl = search(id0, 1);
        indexit = (cl.size() == 0);
        cl.close();
      }
    }

    if (indexit) {
      Document d = o.getDocument();
      writer.updateDocument(updateterm, d);
    }
  }
示例#2
0
  public void delete(CObj o) throws IOException {
    if (o.getDig() == null && o.getId() == null) {
      throw new IOException("Digest or id required!");
    }

    Term updateterm = null;

    if (o.getId() != null) {
      updateterm = new Term("id", o.getId());
    }

    if (o.getDig() != null && o.getId() == null) {
      updateterm = new Term("dig", o.getDig());
    }

    if (updateterm != null) {
      writer.deleteDocuments(updateterm);
      writer.commit();
    }
  }