Package org.apache.lucene.util

Examples of org.apache.lucene.util.BytesRef


    Terms terms = reader.terms(field);
    if (terms == null) {
      return ret;
    }
    TermsEnum termsEnum = terms.iterator(null);
    BytesRef text;
    while ((text = termsEnum.next()) != null) {
      if (!text.utf8ToString().startsWith("-")) {
        break;
      }
      ret++;
    }
    return ret;
View Full Code Here


    freqList.add(0);
    int totalFreq = 0;
    Terms terms = reader.terms(field);
    if (terms != null) {
      TermsEnum termsEnum = terms.iterator(null);
      BytesRef text;
      while ((text = termsEnum.next()) != null) {
        // store term text
        // we expect that there is at most one term per document
        if (t >= length) throw new RuntimeException("there are more terms than "
            + "documents in field \"" + field + "\", but it's impossible to sort on "
            + "tokenized fields");
        String strText = text.utf8ToString();
        list.add(strText);
        Term term = new Term(field, strText);
        DocsEnum docsEnum = reader.termDocsEnum(term);
        int minID = -1;
        int maxID = -1;
View Full Code Here

    _overflow = false;

    Terms terms = reader.terms(field);
    if (terms != null) {
      TermsEnum termsEnum = terms.iterator(null);
      BytesRef text;
      while ((text = termsEnum.next()) != null) {
        String strText = text.utf8ToString();
        list.add(strText);

        Term term = new Term(field, strText);
        DocsEnum docsEnum = reader.termDocsEnum(term);
        int df = 0;
View Full Code Here

    _overflow = false;

    Terms terms = reader.terms(field);
    if (terms != null) {
      TermsEnum termsEnum = terms.iterator(null);
      BytesRef text;
      while ((text = termsEnum.next()) != null) {
        String strText = text.utf8ToString();
        list.add(strText);

        Term term = new Term(field, strText);
        DocsEnum docsEnum = reader.termDocsEnum(term);
View Full Code Here

  }
 
  private void writeDoc(BufferedWriter bw, int docNum, Document doc, boolean decode,
          Bits liveDocs) throws Exception {
    bw.write("<doc id='" + docNum + "'>\n");
    BytesRef bytes = new BytesRef();
    for (String fieldName : fieldNames) {
      IndexableField[] fields = doc.getFields(fieldName);
      if (fields == null || fields.length == 0) {
        continue;
      }
View Full Code Here

    boolean warn = false;
    if (selEnc != null) enc = selEnc;
    int len = 0;
    byte[] data = null;
    if (f.binaryValue() != null) {
      BytesRef bytes = f.binaryValue();
      data = new byte[bytes.length];
      System.arraycopy(bytes.bytes, bytes.offset, data, 0,
          bytes.length);
    }
    else if (f.stringValue() != null) {
      try {
        data = f.stringValue().getBytes("UTF-8");
      } catch (UnsupportedEncodingException uee) {
        warn = true;
        uee.printStackTrace();
        data = f.stringValue().getBytes();
      }
    }
    if (data == null) data = new byte[0];
    if (enc.equals("cbHex")) {
      setString(find(dialog, "unit"), "text", " bytes");
      value = Util.bytesToHex(data, 0, data.length, true);
      len = data.length;
    } else if (enc.equals("cbUtf")) {
      setString(find(dialog, "unit"), "text", " UTF-8 characters");
      value = f.stringValue();
      if (value != null) len = value.length();
    } else if (enc.equals("cbDef")) {
      setString(find(dialog, "unit"), "text", " characters");
      value = new String(data);
      len = value.length();
    } else if (enc.equals("cbDate")) {
      try {
        Date d = DateTools.stringToDate(f.stringValue());
        value = d.toString();
        len = 1;
      } catch (Exception e) {
        warn = true;
        value = Util.bytesToHex(data, 0, data.length, true);
      }
    } else if (enc.equals("cbLong")) {
      try {
        long num = NumericUtils.prefixCodedToLong(new BytesRef(f.stringValue()));
        value = String.valueOf(num);
        len = 1;
      } catch (Exception e) {
        warn = true;
        value = Util.bytesToHex(data, 0, data.length, true);
View Full Code Here

    }
    Object progress = null;
    try {
      byte[] data = null;
      if (f.binaryValue() != null) {
        BytesRef bytes = f.binaryValue();
        data = new byte[bytes.length];
        System.arraycopy(bytes.bytes, bytes.offset, data, 0,
            bytes.length);
      }
      else {
View Full Code Here

          String fld = getString(fCombo, "text");
          Terms terms = MultiFields.getTerms(ir, fld);
          TermsEnum te = terms.iterator(null);
          putProperty(fCombo, "te", te);
          putProperty(fCombo, "teField", fld);
          BytesRef term = te.next();
          _showTerm(fCombo, fText, new Term(fld, term));
        } catch (Exception e) {
          e.printStackTrace();
          showStatus(e.getMessage());
        }       
View Full Code Here

          }
          TermsEnum te = (TermsEnum)getProperty(fCombo, "te");
          String fld = getString(fCombo, "text");
          String teField = (String)getProperty(fCombo, "teField");
          SeekStatus status;
          BytesRef rawTerm = null;
          if (te != null) {
            rawTerm = te.term();
          }
          String rawString = rawTerm != null ? rawTerm.utf8ToString() : null;
          if (te == null || !teField.equals(fld) || !text.equals(rawString)) {
            Terms terms = MultiFields.getTerms(ir, fld);
            te = terms.iterator(null);
            putProperty(fCombo, "te", te);
            putProperty(fCombo, "teField", fld);
            status = te.seekCeil(new BytesRef(text));
            if (status.equals(SeekStatus.FOUND)) {
              rawTerm = te.term();
            } else {
              rawTerm = null;
            }
View Full Code Here

          if (text == null || text.trim().equals("")) return;
          Term t = new Term(fld, text);
          if (ir.docFreq(t) == 0) { // missing term
            Terms terms = MultiFields.getTerms(ir, fld);
            TermsEnum te = terms.iterator(null);
            te.seekCeil(new BytesRef(text));
            t = new Term(fld, te.term().utf8ToString());
          }
          _showTerm(fCombo, fText, t);
        } catch (Exception e) {
          e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.BytesRef

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.