Example usage for org.apache.lucene.codecs Codec getName

List of usage examples for org.apache.lucene.codecs Codec getName

Introduction

In this page you can find the example usage for org.apache.lucene.codecs Codec getName.

Prototype

@Override
public final String getName() 

Source Link

Document

Returns this codec's name

Usage

From source file:com.senseidb.abacus.api.codec.CodecTest.java

License:Apache License

static Directory buildIndex(Iterable<String> datasrc, Codec codec) throws Exception {
    String idxname = codec == null ? "lucene" : codec.getName();
    Directory dir = FSDirectory.open(new File("/tmp/codectest", idxname));//new RAMDirectory();
    //Directory dir = new RAMDirectory();
    IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_44, new StandardAnalyzer(Version.LUCENE_44));
    conf.setUseCompoundFile(false);//from  w  w  w.j  ava  2  s .  com
    if (codec != null) {
        conf.setCodec(codec);
    }

    IndexWriter writer = new IndexWriter(dir, conf);

    for (String doc : datasrc) {
        if (doc == null)
            break;
        doc = doc.trim();
        if (doc.length() == 0)
            continue;
        Document d = new Document();
        FieldType ft = new FieldType();
        ft.setIndexed(true);
        ft.setStored(false);
        ft.setIndexOptions(IndexOptions.DOCS_ONLY);
        ft.setOmitNorms(true);
        Field f = new Field(FIELD, doc, ft);
        d.add(f);
        writer.addDocument(d);
    }
    writer.forceMerge(1);
    writer.commit();
    writer.close();
    return dir;
}

From source file:com.vmware.xenon.services.common.LuceneCodecWithFixes.java

License:Open Source License

protected LuceneCodecWithFixes(Codec original, FieldInfoCache fieldInfoCache) {
    super(original.getName(), original);

    this.fieldInfosFormat = new Lucene60FieldInfosFormatWithCache(fieldInfoCache);
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinitionTest.java

License:Apache License

@Test
public void codecConfig() throws Exception {
    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
    assertNotNull(defn.getCodec());//from   ww w  .java 2s . c o m
    assertEquals(oakCodec.getName(), defn.getCodec().getName());

    builder.setProperty(LuceneIndexConstants.FULL_TEXT_ENABLED, false);
    defn = new IndexDefinition(root, builder.getNodeState());
    assertNull(defn.getCodec());

    Codec simple = Codec.getDefault();
    builder.setProperty(LuceneIndexConstants.CODEC_NAME, simple.getName());
    defn = new IndexDefinition(root, builder.getNodeState());
    assertNotNull(defn.getCodec());
    assertEquals(simple.getName(), defn.getCodec().getName());
}

From source file:org.eu.bitzone.Leia.java

License:Apache License

public void showDiagnostics(final Object segmentsTable) {
    final Object diagsTable = find("diagsTable");
    removeAll(diagsTable);//from  w  w  w. j  a va 2s .co m
    final Object row = getSelectedItem(segmentsTable);
    if (row == null) {
        return;
    }
    final SegmentCommitInfo si = (SegmentCommitInfo) getProperty(row, "si");
    if (si == null) {
        showStatus("Missing SegmentInfoPerCommit???");
        return;
    }
    Map<String, String> map = si.info.attributes();
    if (map != null) {
        for (final Entry<String, String> e : map.entrySet()) {
            final Object r = create("row");
            add(diagsTable, r);
            Object cell = create("cell");
            setString(cell, "text", "A");
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getKey());
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getValue());
            add(r, cell);
        }
    }
    // separator
    // Object r1 = create("row");
    // add(diagsTable, r1);
    // Object c1 = create("cell");
    // setBoolean(c1, "enabled", false);
    // add(r1, c1);
    map = si.info.getDiagnostics();
    if (map != null) {
        for (final Entry<String, String> e : map.entrySet()) {
            final Object r = create("row");
            add(diagsTable, r);
            Object cell = create("cell");
            setString(cell, "text", "D");
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getKey());
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getValue());
            add(r, cell);
        }
    }
    // separator
    Object r1 = create("row");
    add(diagsTable, r1);
    Object c1 = create("cell");
    setBoolean(c1, "enabled", false);
    add(r1, c1);
    // codec info
    final Codec codec = si.info.getCodec();
    map = new LinkedHashMap<String, String>();
    map.put("codecName", codec.getName());
    map.put("codecClassName", codec.getClass().getName());
    map.put("docValuesFormat", codec.docValuesFormat().getClass().getName());
    map.put("fieldInfosFormat", codec.fieldInfosFormat().getClass().getName());
    map.put("liveDocsFormat", codec.liveDocsFormat().getClass().getName());
    map.put("normsFormat", codec.normsFormat().getClass().getName());
    map.put("postingsFormat",
            codec.postingsFormat().toString() + " " + codec.postingsFormat().getClass().getName());
    map.put("segmentInfoFormat", codec.segmentInfoFormat().getClass().getName());
    map.put("storedFieldsFormat", codec.storedFieldsFormat().getClass().getName());
    map.put("termVectorsFormat", codec.termVectorsFormat().getClass().getName());
    try {
        final List<String> files = new ArrayList<String>(si.files());
        Collections.sort(files);
        map.put("---files---", files.toString());
        if (si.info.getUseCompoundFile()) {
            final Directory d = new CompoundFileDirectory(dir,
                    IndexFileNames.segmentFileName(si.info.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION),
                    IOContext.READ, false);
            files.clear();
            files.addAll(Arrays.asList(d.listAll()));
            d.close();
            Collections.sort(files);
            map.put("-CFS-files-", files.toString());
        }
    } catch (final Exception e) {
        e.printStackTrace();
        map.put("---files---", "Exception: " + e.toString());
    }
    for (final Entry<String, String> e : map.entrySet()) {
        final Object r = create("row");
        add(diagsTable, r);
        Object cell = create("cell");
        setString(cell, "text", "C");
        add(r, cell);
        cell = create("cell");
        setString(cell, "text", e.getKey());
        add(r, cell);
        cell = create("cell");
        setString(cell, "text", e.getValue());
        add(r, cell);
    }
    // fieldInfos
    try {
        final SegmentReader sr = new SegmentReader(si, 1, IOContext.READ);
        final FieldInfos fis = sr.getFieldInfos();
        map = new LinkedHashMap<String, String>();
        final List<String> flds = new ArrayList<String>(fis.size());
        for (final FieldInfo fi : fis) {
            flds.add(fi.name);
        }
        Collections.sort(flds);
        map.put("L---fields---", flds.toString());
        for (final String fn : flds) {
            final FieldInfo fi = fis.fieldInfo(fn);
            map.put("A" + fi.name, fi.attributes().toString());
        }
        map.put("F---flags----", "IdfpoPVNtxxDtxx");
        for (final String fn : flds) {
            final FieldInfo fi = fis.fieldInfo(fn);
            map.put("F" + fi.name, Util.fieldFlags(null, fi));
        }
        sr.close();
        // separator
        r1 = create("row");
        add(diagsTable, r1);
        c1 = create("cell");
        setBoolean(c1, "enabled", false);
        add(r1, c1);
        for (final Entry<String, String> e : map.entrySet()) {
            final Object r = create("row");
            add(diagsTable, r);
            Object cell = create("cell");
            setString(cell, "text", "F" + e.getKey().charAt(0));
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getKey().substring(1));
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getValue());
            if (e.getKey().startsWith("F")) {
                setFont(cell, courier);
            }
            add(r, cell);
        }
    } catch (final IOException e1) {
        e1.printStackTrace();
    }
}

From source file:org.getopt.luke.Luke.java

License:Apache License

public void showDiagnostics(Object segmentsTable) {
    Object diagsTable = find("diagsTable");
    removeAll(diagsTable);//from  www.ja  v a 2 s  .c  o m
    Object row = getSelectedItem(segmentsTable);
    if (row == null) {
        return;
    }
    SegmentCommitInfo si = (SegmentCommitInfo) getProperty(row, "si");
    if (si == null) {
        showStatus("Missing SegmentInfoPerCommit???");
        return;
    }
    Map<String, String> map = si.info.attributes();
    if (map != null) {
        for (Entry<String, String> e : map.entrySet()) {
            Object r = create("row");
            add(diagsTable, r);
            Object cell = create("cell");
            setString(cell, "text", "A");
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getKey());
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getValue());
            add(r, cell);
        }
    }
    // separator
    //    Object r1 = create("row");
    //    add(diagsTable, r1);
    //    Object c1 = create("cell");
    //    setBoolean(c1, "enabled", false);
    //    add(r1, c1);
    map = si.info.getDiagnostics();
    if (map != null) {
        for (Entry<String, String> e : map.entrySet()) {
            Object r = create("row");
            add(diagsTable, r);
            Object cell = create("cell");
            setString(cell, "text", "D");
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getKey());
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getValue());
            add(r, cell);
        }
    }
    // separator
    Object r1 = create("row");
    add(diagsTable, r1);
    Object c1 = create("cell");
    setBoolean(c1, "enabled", false);
    add(r1, c1);
    // codec info
    Codec codec = si.info.getCodec();
    map = new LinkedHashMap<String, String>();
    map.put("codecName", codec.getName());
    map.put("codecClassName", codec.getClass().getName());
    map.put("docValuesFormat", codec.docValuesFormat().getClass().getName());
    map.put("fieldInfosFormat", codec.fieldInfosFormat().getClass().getName());
    map.put("liveDocsFormat", codec.liveDocsFormat().getClass().getName());
    map.put("normsFormat", codec.normsFormat().getClass().getName());
    map.put("postingsFormat",
            codec.postingsFormat().toString() + " " + codec.postingsFormat().getClass().getName());
    map.put("segmentInfoFormat", codec.segmentInfoFormat().getClass().getName());
    map.put("storedFieldsFormat", codec.storedFieldsFormat().getClass().getName());
    map.put("termVectorsFormat", codec.termVectorsFormat().getClass().getName());
    try {
        List<String> files = new ArrayList<String>(si.files());
        Collections.sort(files);
        map.put("---files---", files.toString());
        if (si.info.getUseCompoundFile()) {
            Directory d = new CompoundFileDirectory(dir,
                    IndexFileNames.segmentFileName(si.info.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION),
                    IOContext.READ, false);
            files.clear();
            files.addAll(Arrays.asList(d.listAll()));
            d.close();
            Collections.sort(files);
            map.put("-CFS-files-", files.toString());
        }
    } catch (Exception e) {
        e.printStackTrace();
        map.put("---files---", "Exception: " + e.toString());
    }
    for (Entry<String, String> e : map.entrySet()) {
        Object r = create("row");
        add(diagsTable, r);
        Object cell = create("cell");
        setString(cell, "text", "C");
        add(r, cell);
        cell = create("cell");
        setString(cell, "text", e.getKey());
        add(r, cell);
        cell = create("cell");
        setString(cell, "text", e.getValue());
        add(r, cell);
    }
    // fieldInfos
    try {
        SegmentReader sr = new SegmentReader(si, 1, IOContext.READ);
        FieldInfos fis = sr.getFieldInfos();
        map = new LinkedHashMap<String, String>();
        List<String> flds = new ArrayList<String>(fis.size());
        for (FieldInfo fi : fis) {
            flds.add(fi.name);
        }
        Collections.sort(flds);
        map.put("L---fields---", flds.toString());
        for (String fn : flds) {
            FieldInfo fi = fis.fieldInfo(fn);
            map.put("A" + fi.name, fi.attributes().toString());
        }
        map.put("F---flags----", "IdfpoPVNtxxDtxx");
        for (String fn : flds) {
            FieldInfo fi = fis.fieldInfo(fn);
            map.put("F" + fi.name, Util.fieldFlags(null, fi));
        }
        sr.close();
        // separator
        r1 = create("row");
        add(diagsTable, r1);
        c1 = create("cell");
        setBoolean(c1, "enabled", false);
        add(r1, c1);
        for (Entry<String, String> e : map.entrySet()) {
            Object r = create("row");
            add(diagsTable, r);
            Object cell = create("cell");
            setString(cell, "text", "F" + e.getKey().charAt(0));
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getKey().substring(1));
            add(r, cell);
            cell = create("cell");
            setString(cell, "text", e.getValue());
            if (e.getKey().startsWith("F")) {
                setFont(cell, courier);
            }
            add(r, cell);
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    }
}