Example usage for org.apache.lucene.document StoredField StoredField

List of usage examples for org.apache.lucene.document StoredField StoredField

Introduction

In this page you can find the example usage for org.apache.lucene.document StoredField StoredField.

Prototype

public StoredField(String name, double value) 

Source Link

Document

Create a stored-only field with the given double value.

Usage

From source file:org.openedit.data.lucene.SearchResultStoredFieldVisitor.java

License:Apache License

@Override
public void floatField(FieldInfo fieldInfo, float value) {
    StoredField stored = new StoredField(fieldInfo.name, value);
    putValue(fieldInfo.name, stored.stringValue());
}

From source file:org.openedit.data.lucene.SearchResultStoredFieldVisitor.java

License:Apache License

@Override
public void doubleField(FieldInfo fieldInfo, double value) {
    StoredField stored = new StoredField(fieldInfo.name, value);
    putValue(fieldInfo.name, stored.stringValue());
}

From source file:org.opengrok.indexer.analysis.FileAnalyzer.java

License:Open Source License

/**
 * Add a field to store document number of lines.
 * @param doc the target document/*from  www.j  ava 2 s  . com*/
 * @param value the number of lines
 */
@Override
protected void addNumLines(Document doc, int value) {
    doc.add(new StoredField(QueryBuilder.NUML, value));
}

From source file:org.opengrok.indexer.analysis.FileAnalyzer.java

License:Open Source License

/**
 * Add a field to store document lines-of-code.
 * @param doc the target document//w  w w  . j  a v  a  2  s  . c  o  m
 * @param value the loc
 */
@Override
protected void addLOC(Document doc, int value) {
    doc.add(new StoredField(QueryBuilder.LOC, value));
}

From source file:org.opengrok.indexer.analysis.plain.PlainAnalyzer.java

License:Open Source License

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException, InterruptedException {
    Definitions defs = null;// w  w w  . j  a  va  2 s . c om

    doc.add(new OGKTextField(QueryBuilder.FULL, getReader(src.getStream())));

    String fullpath = doc.get(QueryBuilder.FULLPATH);
    if (fullpath != null && ctags != null) {
        defs = ctags.doCtags(fullpath);
        if (defs != null && defs.numberOfSymbols() > 0) {
            tryAddingDefs(doc, defs, src, fullpath);
            byte[] tags = defs.serialize();
            doc.add(new StoredField(QueryBuilder.TAGS, tags));
        }
    }
    /*
     * This is to explicitly use appropriate analyzer's token stream to
     * work around #1376: symbols search works like full text search.
     */
    OGKTextField ref = new OGKTextField(QueryBuilder.REFS, this.symbolTokenizer);
    this.symbolTokenizer.setReader(getReader(src.getStream()));
    doc.add(ref);

    if (scopesEnabled && xrefOut == null) {
        /*
         * Scopes are generated during xref generation. If xrefs are
         * turned off we still need to run writeXref to produce scopes,
         * we use a dummy writer that will throw away any xref output.
         */
        xrefOut = new NullWriter();
    }

    if (xrefOut != null) {
        try (Reader in = getReader(src.getStream())) {
            WriteXrefArgs args = new WriteXrefArgs(in, xrefOut);
            args.setDefs(defs);
            args.setProject(project);
            Xrefer xref = writeXref(args);

            Scopes scopes = xref.getScopes();
            if (scopes.size() > 0) {
                byte[] scopesSerialized = scopes.serialize();
                doc.add(new StoredField(QueryBuilder.SCOPES, scopesSerialized));
            }

            addNumLines(doc, xref.getLineNumber());
            addLOC(doc, xref.getLOC());
        }
    }
}

From source file:org.opengrok.indexer.index.IndexAnalysisSettingsAccessor.java

License:Open Source License

/**
 * Writes a document to contain the serialized version of {@code settings},
 * with a {@link QueryBuilder#OBJUID} value set to
 * {@link #INDEX_ANALYSIS_SETTINGS_OBJUID}. An existing version of the
 * document is first deleted.// www. j a  v a2s. c  o  m
 * @param writer a defined, target instance
 * @param settings a defined instance
 * @throws IOException if I/O error occurs while writing Lucene
 */
public void write(IndexWriter writer, IndexAnalysisSettings settings) throws IOException {
    byte[] objser = settings.serialize();

    writer.deleteDocuments(new Term(QueryBuilder.OBJUID, INDEX_ANALYSIS_SETTINGS_OBJUID));

    Document doc = new Document();
    StringField uidfield = new StringField(QueryBuilder.OBJUID, INDEX_ANALYSIS_SETTINGS_OBJUID, Field.Store.NO);
    doc.add(uidfield);
    doc.add(new StoredField(QueryBuilder.OBJSER, objser));
    doc.add(new StoredField(QueryBuilder.OBJVER, INDEX_ANALYSIS_SETTINGS_OBJVER));
    writer.addDocument(doc);
}

From source file:org.opensolaris.opengrok.analysis.plain.PlainAnalyzer.java

License:Open Source License

@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    doc.add(new TextField("full", getReader(src.getStream())));
    String fullpath = doc.get("fullpath");
    if (fullpath != null && ctags != null) {
        defs = ctags.doCtags(fullpath + "\n");
        if (defs != null && defs.numberOfSymbols() > 0) {
            doc.add(new TextField("defs", new IteratorReader(defs.getSymbols())));
            doc.add(new TextField("refs", getReader(src.getStream())));
            byte[] tags = defs.serialize();
            doc.add(new StoredField("tags", tags));
        }/* w w  w . j av a 2  s  .  c om*/
    }

    if (xrefOut != null) {
        try (Reader in = getReader(src.getStream())) {
            writeXref(in, xrefOut);
        }
    }
}

From source file:org.opensolaris.opengrok.index.IndexAnalysisSettingsAccessor.java

License:Open Source License

/**
 * Writes a document to contain the serialized version of {@code settings},
 * with a {@link QueryBuilder#OBJUID} value set to
 * {@link #INDEX_ANALYSIS_SETTINGS_OBJUID}. An existing version of the
 * document is first deleted.//from  w w  w .j  a  v a  2  s .  com
 * @param writer a defined, target instance
 * @param settings a defined instance
 * @throws IOException if I/O error occurs while writing Lucene
 */
public void write(IndexWriter writer, IndexAnalysisSettings settings) throws IOException {
    byte[] objser = settings.serialize();

    writer.deleteDocuments(new Term(QueryBuilder.OBJUID, INDEX_ANALYSIS_SETTINGS_OBJUID));

    Document doc = new Document();
    StringField uidfield = new StringField(QueryBuilder.OBJUID, INDEX_ANALYSIS_SETTINGS_OBJUID, Field.Store.NO);
    doc.add(uidfield);
    doc.add(new StoredField(QueryBuilder.OBJSER, objser));
    writer.addDocument(doc);
}

From source file:org.searsia.index.ResourceIndex.java

License:Apache License

private void updateResourceIndex(String id, Resource engine) throws IOException {
    Document doc = new Document();
    if (id != null) {
        JSONObject json = engine.toJson();
        json.put("parameters", engine.getJsonPrivateParameters()); // we need to remember those
        doc.add(new StringField("id", id, Field.Store.YES)); // unique identifier
        doc.add(new StoredField("json", json.toString()));
        this.writer.updateDocument(new Term("id", id), doc);
    }//from  w ww .j  a  v  a 2s  .co  m
    this.writer.commit();
}

From source file:org.ujmp.lucene.LuceneMap.java

License:Open Source License

public synchronized V put(K key, V value) {
    try {/*  www .j a  va  2  s .c  om*/
        Term term = new Term(KEYSTRING, getUniqueString(key));
        Document doc = new Document();
        doc.add(new StringField(KEYSTRING, getUniqueString(key), Field.Store.YES));
        doc.add(new StoredField(KEYDATA, SerializationUtil.serialize((Serializable) key)));
        doc.add(new StringField(VALUESTRING, getUniqueString(value), Field.Store.YES));
        doc.add(new StoredField(VALUEDATA, SerializationUtil.serialize((Serializable) value)));
        getIndexWriter().updateDocument(term, doc);
        return null;
    } catch (Exception e) {
        throw new RuntimeException("could not add document: " + key, e);
    }
}