Example usage for org.apache.lucene.document Field stringValue

List of usage examples for org.apache.lucene.document Field stringValue

Introduction

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

Prototype

@Override
public String stringValue() 

Source Link

Document

The value of the field as a String, or null.

Usage

From source file:at.lux.retrieval.vectorspace.ElementTextVectorSimilarityTest.java

License:Open Source License

public void testSimilarity() throws IOException, JDOMException {
    ElementTextVectorSimilarity sim = new ElementTextVectorSimilarity();
    double distance = sim.getSimilarity(d1, d1);
    System.out.println("distance = " + distance);
    distance = sim.getSimilarity(d1, d2);
    System.out.println("distance = " + distance);
    distance = sim.getSimilarity(d2, d1);
    System.out.println("distance = " + distance);

    IndexReader reader = IndexReader.open("testdata/idx_paths");

    System.out.println("Loading documents and adding them to corpus ...");
    for (int i = 0; i < reader.numDocs(); i++) {
        //            Graph g_idx = new Graph(reader.document(i).getField("graph").stringValue());
        Field[] files = reader.document(i).getFields("file");
        for (Field file : files) {
            Document d = saxBuilder.build(file.stringValue());
            sim.addToCorpus(d);//  ww  w . j  a v a  2 s.  com
        }
    }

    System.out.println("");

    distance = sim.getSimilarity(d1, d1, ElementTextVectorSimilarity.WeightType.TfIdf);
    System.out.println("distance = " + distance);
    distance = sim.getSimilarity(d1, d2, ElementTextVectorSimilarity.WeightType.TfIdf);
    System.out.println("distance = " + distance);
    distance = sim.getSimilarity(d2, d1, ElementTextVectorSimilarity.WeightType.TfIdf);
    System.out.println("distance = " + distance);
    distance = sim.getSimilarity(d2, d2, ElementTextVectorSimilarity.WeightType.TfIdf);
    System.out.println("distance = " + distance);

    System.out.println("");

    distance = sim.getSimilarity(d1, d1, ElementTextVectorSimilarity.WeightType.BM25);
    System.out.println("distance = " + distance);
    distance = sim.getSimilarity(d1, d2, ElementTextVectorSimilarity.WeightType.BM25);
    System.out.println("distance = " + distance);
    distance = sim.getSimilarity(d2, d1, ElementTextVectorSimilarity.WeightType.BM25);
    System.out.println("distance = " + distance);
    distance = sim.getSimilarity(d2, d2, ElementTextVectorSimilarity.WeightType.BM25);
    System.out.println("distance = " + distance);

}

From source file:axiom.db.utils.LuceneManipulator.java

License:Open Source License

protected Document convertDocument(Document doc) {
    Document ndoc = new Document();
    Enumeration e = doc.fields();

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }/*w ww  . j  av a 2s  .  com*/
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();

        ndoc.add(new Field(name, value, currstore, curridx));
    }

    return ndoc;
}

From source file:axiom.objectmodel.dom.convert.LuceneVersion2Convertor.java

License:Open Source License

public Document convertDocument(Document doc) {
    Document ndoc = new Document();
    Enumeration e = doc.fields();

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }/*from   w w  w .j a v a  2s . c  o m*/
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();
        if (name.startsWith("__")) {
            name = name.substring(1);
            if ("_state".equals(name)) {
                name = "_status";
            } else if ("_prototype".equals(name) || "_parentproto".equals(name)) {
                if ("HopObject".equalsIgnoreCase(value)) {
                    value = "AxiomObject";
                }
            }
        }
        ndoc.add(new Field(name, value, currstore, curridx));
    }

    return ndoc;
}

From source file:axiom.objectmodel.dom.convert.LuceneVersion3Convertor.java

License:Open Source License

public Document convertDocument(Document doc) {

    Document ndoc = new Document();
    Enumeration e = doc.fields();

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }/*  ww w  .j  ava  2s.  co  m*/
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();
        if (name.startsWith("__")) {
            name = name.substring(1);
            if ("_state".equals(name)) {
                name = "_status";
            } else if ("_prototype".equals(name) || "_parentproto".equals(name)) {
                if ("HopObject".equalsIgnoreCase(value)) {
                    value = "AxiomObject";
                }
            }
        }
        ndoc.add(new Field(name, value, currstore, curridx));
    }

    return ndoc;
}

From source file:axiom.objectmodel.dom.convert.LuceneVersion4Convertor.java

License:Open Source License

public Document convertDocument(Document doc) {

    Document ndoc = new Document();
    Enumeration e = doc.fields();

    final String prototype = doc.get("_prototype");
    final Prototype proto = app.getPrototypeByName(prototype);

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }//from  w w  w  . j  a v  a2  s  .co m
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();
        final int type = this.getTypeForProperty(proto, name);
        if (type == IProperty.DATE) {
            value = formatDate(value);
        } else if (type == IProperty.TIME) {
            value = formatTime(value);
        }
        ndoc.add(new Field(name, value, currstore, curridx));
    }

    return ndoc;
}

From source file:axiom.objectmodel.dom.convert.LuceneVersion5Convertor.java

License:Open Source License

protected Document convertDocument(Document doc) {
    Document ndoc = new Document();
    Enumeration e = doc.fields();
    if (doc.get("cms_sortable_prototype") == null) {
        ndoc.add(new Field("cms_sortable_prototype", getDisplayPrototype(cms_props, doc.get("_prototype")),
                Field.Store.YES, Field.Index.UN_TOKENIZED));
    }/*from  w  w w  . java  2  s  .  co m*/
    if (doc.get("cms_sortabletitle") == null && doc.get("title") != null) {
        ndoc.add(new Field("cms_sortabletitle", doc.get("title").toLowerCase(), Field.Store.YES,
                Field.Index.UN_TOKENIZED));
    }

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();

        ndoc.add(new Field(name, value, currstore, curridx));
    }

    return ndoc;
}

From source file:axiom.objectmodel.dom.convert.LuceneVersion6Convertor.java

License:Open Source License

protected Document convertDocument(Document doc) {

    Document ndoc = new Document();
    Enumeration e = doc.fields();

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }//from   www  .j  ava  2s .  com
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();
        if (name.equals("cms_lasteditedby")) {
            Date last = new Date(Long.parseLong(doc.get("_lastmodified")));
            String user = doc.get("lastmodifiedby");
            if (user == null) {
                user = "";
            }
            value = last.getDate() + " " + months[last.getMonth()] + " " + (last.getYear() + "").substring(1)
                    + ", " + last.getHours() + ':'
                    + (last.getMinutes() < 10 ? '0' + last.getMinutes() : last.getMinutes()) + " by " + user;
        }
        ndoc.add(new Field(name, value, currstore, curridx));
    }

    return ndoc;
}

From source file:axiom.objectmodel.dom.convert.LuceneVersion7Convertor.java

License:Open Source License

protected Document convertDocument(Document doc) throws Exception {
    Document ndoc = new Document();
    Enumeration e = doc.fields();

    final String prototype = doc.get("_prototype");
    final Prototype proto = app.getPrototypeByName(prototype);

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }//from www . j  a va  2s.c om
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();
        final int type = this.getTypeForProperty(proto, name);
        if (type == IProperty.DATE) {
            value = formatDate(value);
        } else if (type == IProperty.TIME) {
            value = formatTime(value);
        } else if (type == IProperty.TIMESTAMP) {
            value = formatTimestamp(value);
        } else if (type == IProperty.INTEGER) {
            value = formatInt(value);
        } else if (type == IProperty.FLOAT) {
            value = formatFloat(value);
        } else if (type == IProperty.SMALLFLOAT) {
            value = formatSmallFloat(value);
        } else if (type == IProperty.SMALLINT) {
            value = formatSmallInt(value);
        }
        ndoc.add(new Field(name, value, currstore, curridx));
    }

    return ndoc;
}

From source file:axiom.objectmodel.dom.convert.LuceneVersion8Convertor.java

License:Open Source License

public Document convertDocument(Document doc) {
    Document ndoc = new Document();
    Enumeration e = doc.fields();

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }/*ww  w.j  ava2s  . c om*/
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();

        ndoc.add(new Field(name, value, currstore, curridx));
    }

    return ndoc;
}

From source file:axiom.objectmodel.dom.convert.LuceneVersion9Convertor.java

License:Open Source License

public Document convertDocument(Document doc) {
    Field protoField = doc.getField(LuceneManager.PROTOTYPE);
    if (protoField != null && ("CMSTask".equalsIgnoreCase(protoField.stringValue())
            || "CMSTaskContainer".equalsIgnoreCase(protoField.stringValue()))) {
        return null;
    }/*from w w  w.j  av  a 2s .  co m*/

    Document ndoc = new Document();
    Enumeration e = doc.fields();

    String id = null, layer = null;
    Field idField = doc.getField(LuceneManager.ID);
    Field layerField = doc.getField(LuceneManager.LAYER_OF_SAVE);
    if (idField != null && layerField != null) {
        id = idField.stringValue();
        layer = layerField.stringValue();
    }

    while (e.hasMoreElements()) {
        Field f = (Field) e.nextElement();
        Field.Store currstore = Field.Store.YES;
        if (!f.isStored()) {
            currstore = Field.Store.NO;
        } else if (f.isCompressed()) {
            currstore = Field.Store.COMPRESS;
        }
        Field.Index curridx = Field.Index.UN_TOKENIZED;
        if (!f.isIndexed()) {
            curridx = Field.Index.NO;
        } else if (f.isTokenized()) {
            curridx = Field.Index.TOKENIZED;
        }

        String name = f.name();
        String value = f.stringValue();

        if (!("84".equals(id) && "1".equals(layer) && "_task".equals(name))
                && !("71".equals(id) && "1".equals(layer) && "_task".equals(name))) {

            ndoc.add(new Field(name, value, currstore, curridx));
        }
    }

    return ndoc;
}