Package org.apache.lucene.document

Examples of org.apache.lucene.document.FieldType


    Field f1 = newTextField("f1", "This field has norms", Field.Store.NO);
    d.add(f1);
      
    // this field will NOT have norms

    FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);
    customType.setOmitNorms(true);
    Field f2 = newField("f2", "This field has NO norms in all docs", customType);
    d.add(f2);

    for (int i = 0; i < 5; i++) {
      writer.addDocument(d);
View Full Code Here


    LogMergePolicy lmp = (LogMergePolicy) writer.getConfig().getMergePolicy();
    lmp.setMergeFactor(2);
    lmp.setNoCFSRatio(0.0);
    Document d = new Document();

    FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);
    customType.setOmitNorms(true);
    Field f1 = newField("f1", "This field has no norms", customType);
    d.add(f1);

    for (int i = 0; i < 30; i++) {
      writer.addDocument(d);
View Full Code Here

   * Internally checks that MultiNorms.norms() is consistent (returns the same bytes)
   * as the fully merged equivalent.
   */
  public void testOmitNormsCombos() throws IOException {
    // indexed with norms
    FieldType customType = new FieldType(TextField.TYPE_STORED);
    Field norms = new Field("foo", "a", customType);
    // indexed without norms
    FieldType customType1 = new FieldType(TextField.TYPE_STORED);
    customType1.setOmitNorms(true);
    Field noNorms = new Field("foo", "a", customType1);
    // not indexed, but stored
    FieldType customType2 = new FieldType();
    customType2.setStored(true);
    Field noIndex = new Field("foo", "a", customType2);
    // not indexed but stored, omitNorms is set
    FieldType customType3 = new FieldType();
    customType3.setStored(true);
    customType3.setOmitNorms(true);
    Field noNormsNoIndex = new Field("foo", "a", customType3);
    // not indexed nor stored (doesnt exist at all, we index a different field instead)
    Field emptyNorms = new Field("bar", "a", customType);
   
    assertNotNull(getNorms("foo", norms, norms));
View Full Code Here

      final PhraseQuery pq = new PhraseQuery();
      pq.add(new Term("content", "bbb"));
      pq.add(new Term("content", "ccc"));

      final Document doc = new Document();
      FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);
      customType.setOmitNorms(true);
      doc.add(newField("content", "aaa bbb ccc ddd", customType));

      // add document and force commit for creating a first segment
      writer.addDocument(doc);
      writer.commit();
View Full Code Here

            setMergePolicy(newLogMergePolicy(false, 10)).setUseCompoundFile(false)
    );

    Document doc = new Document();
    for(int i=0;i<testFields.length;i++) {
      FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);
      if (testFieldsStorePos[i] && testFieldsStoreOff[i]) {
        customType.setStoreTermVectors(true);
        customType.setStoreTermVectorPositions(true);
        customType.setStoreTermVectorOffsets(true);
      }
      else if (testFieldsStorePos[i] && !testFieldsStoreOff[i]) {
        customType.setStoreTermVectors(true);
        customType.setStoreTermVectorPositions(true);
      }
      else if (!testFieldsStorePos[i] && testFieldsStoreOff[i]) {
        customType.setStoreTermVectors(true);
        customType.setStoreTermVectorOffsets(true);
      }
      else {
        customType.setStoreTermVectors(true);
      }
      doc.add(new Field(testFields[i], "", customType));
    }

    //Create 5 documents for testing, they all have the same
View Full Code Here

  }

  public void testIllegalIndexableField() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setStoreTermVectors(true);
    ft.setStoreTermVectorPayloads(true);
    Document doc = new Document();
    doc.add(new Field("field", "value", ft));
    try {
      w.addDocument(doc);
      fail("did not hit exception");
    } catch (IllegalArgumentException iae) {
      // Expected
      assertEquals("cannot index term vector payloads without term vector positions (field=\"field\")", iae.getMessage());
    }

    ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setStoreTermVectors(false);
    ft.setStoreTermVectorOffsets(true);
    doc = new Document();
    doc.add(new Field("field", "value", ft));
    try {
      w.addDocument(doc);
      fail("did not hit exception");
    } catch (IllegalArgumentException iae) {
      // Expected
      assertEquals("cannot index term vector offsets when term vectors are not indexed (field=\"field\")", iae.getMessage());
    }

    ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setStoreTermVectors(false);
    ft.setStoreTermVectorPositions(true);
    doc = new Document();
    doc.add(new Field("field", "value", ft));
    try {
      w.addDocument(doc);
      fail("did not hit exception");
    } catch (IllegalArgumentException iae) {
      // Expected
      assertEquals("cannot index term vector positions when term vectors are not indexed (field=\"field\")", iae.getMessage());
    }

    ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setStoreTermVectors(false);
    ft.setStoreTermVectorPayloads(true);
    doc = new Document();
    doc.add(new Field("field", "value", ft));
    try {
      w.addDocument(doc);
      fail("did not hit exception");
View Full Code Here

  public void testStats() throws Exception {
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir,
        newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
    Document doc = new Document();
    FieldType ft = new FieldType(TextField.TYPE_NOT_STORED);
    ft.setIndexOptions(IndexOptions.DOCS_ONLY);
    ft.freeze();
    Field f = newField("foo", "bar", ft);
    doc.add(f);
    iw.addDocument(doc);
    IndexReader ir = iw.getReader();
    iw.close();
View Full Code Here

  }


  // IdfpoPSVBNtxx#txxDtxx
  public static String fieldFlags(Field fld, FieldInfo info) {
    FieldType t = null;
    BytesRef binary = null;
    Number numeric = null;
    if (fld == null) {
      t = new FieldType();
      t.setIndexed(false);
      t.setStored(false);
      t.setStoreTermVectors(false);
      t.setOmitNorms(true);
      t.setStoreTermVectorOffsets(false);
      t.setStoreTermVectorPositions(false);
      t.setTokenized(false);
      t.setNumericType(null);
    } else {
      t = fld.fieldType();
      binary = fld.binaryValue();
      numeric = fld.numericValue();
    }
    StringBuffer flags = new StringBuffer();
    if (info.isIndexed()) flags.append("I");
    else flags.append("-");
    IndexOptions opts = info.getIndexOptions();
    if (info.isIndexed() && opts != null) {
      switch (opts) {
      case DOCS_ONLY:
        flags.append("d---");
        break;
      case DOCS_AND_FREQS:
        flags.append("df--");
        break;
      case DOCS_AND_FREQS_AND_POSITIONS:
        flags.append("dfp-");
        break;
      case DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS:
        flags.append("dfpo");
      }
    } else {
      flags.append("----");
    }
    if (info.hasPayloads()) flags.append("P");
    else flags.append("-");
    if (t.stored()) flags.append("S");
    else flags.append("-");
    if (t.storeTermVectors()) flags.append("V");
    else flags.append("-");
    if (binary != null) flags.append("B");
    else flags.append("-");
    if (info.hasNorms()) {
      flags.append("N");
      flags.append(dvToString(info.getNormType()));
    }
    else flags.append("----");
    if (numeric != null) {
      flags.append("#");
      NumericType nt = t.numericType();
      if (nt != null) {
        flags.append(nt.toString().charAt(0));
        int prec = t.numericPrecisionStep();
        String p = Integer.toHexString(prec);
        if (p.length() == 1) {
          p = "0" + p;
        }
        flags.append(p);
View Full Code Here

      Object cbONorms = find(tabs[i], "cbONorms");
      Object cbOTF = find(tabs[i], "cbOTF");
      String text = getString(fText, "text");
      byte[] binValue;
      boolean binary = getBoolean(cbBin, "selected");
      FieldType ft = new FieldType();
      if (getBoolean(cbTVF, "selected")) {
        ft.setStoreTermVectors(true);
        if (getBoolean(cbTVFo, "selected")) {
          ft.setStoreTermVectorOffsets(true);
        }
        if (getBoolean(cbTVFp, "selected")) {
          ft.setStoreTermVectorPositions(true);
        }
      } else {
        ft.setStoreTermVectors(false);
      }
      // XXX omitTF needs fixing
      // f.setOmitTermFreqAndPositions(getBoolean(cbOTF, "selected"));
      if (getBoolean(cbOTF, "selected")) {
        ft.setIndexOptions(IndexOptions.DOCS_ONLY);
      } else {
        ft.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
      }
      ft.setStored(getBoolean(cbStored, "selected"));
      ft.setIndexed(getBoolean(cbIndexed, "selected"));
      ft.setTokenized(getBoolean(cbTokenized, "selected"));
      if (ft.stored() == false && ft.indexed() == false) {
        errorMsg("Field '" + name + "' is neither stored nor indexed.");
        return false;
      }
      ft.setOmitNorms(getBoolean(cbONorms, "selected"));
      Field f;
      if (binary) {
        try {
          binValue = Util.hexToBytes(text);
        } catch (Throwable e) {
View Full Code Here

  private void addDoc(IndexWriter w, DocumentInCollection xmlDoc)
      throws CorruptIndexException, IOException {

    Document doc = new Document();

    FieldType textFieldType = new FieldType();
    textFieldType.setIndexed(true);
    textFieldType.setStored(true);
    textFieldType.setTokenized(true);
    boolean boolean_relevance = xmlDoc.isRelevant();

    // String cast for relevance. Empty = False, 1 = True
    String relevance = "";
    if (boolean_relevance && xmlDoc.getSearchTaskNumber() == OUR_SEARCH_TASK)
View Full Code Here

TOP

Related Classes of org.apache.lucene.document.FieldType

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.