Example usage for org.apache.lucene.queryparser.flexible.core.nodes FuzzyQueryNode getSimilarity

List of usage examples for org.apache.lucene.queryparser.flexible.core.nodes FuzzyQueryNode getSimilarity

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.flexible.core.nodes FuzzyQueryNode getSimilarity.

Prototype

public float getSimilarity() 

Source Link

Usage

From source file:com.sindicetech.siren.qparser.keyword.builders.NodeFuzzyQueryNodeBuilder.java

License:Open Source License

public NodeQuery build(QueryNode queryNode) throws QueryNodeException {
    FuzzyQueryNode fuzzyNode = (FuzzyQueryNode) queryNode;
    String text = fuzzyNode.getTextAsString();

    int numEdits = FuzzyQuery.floatToEdits(fuzzyNode.getSimilarity(), text.codePointCount(0, text.length()));

    NodeFuzzyQuery fuzzyQuery = new NodeFuzzyQuery(
            new Term(fuzzyNode.getFieldAsString(), fuzzyNode.getTextAsString()), numEdits,
            fuzzyNode.getPrefixLength());
    // assign the datatype. We must always have a datatype assigned.
    fuzzyQuery.setDatatype((String) queryNode.getTag(DatatypeQueryNode.DATATYPE_TAGID));

    // if it is tagged as a span query
    if (fuzzyNode.getTag(QueryTypeProcessor.QUERYTYPE_TAG) == QueryTypeProcessor.SPAN_QUERYTYPE) {
        return new MultiTermSpanQuery<>(fuzzyQuery);
    } else {/* w  w  w.  ja  v a  2  s.  com*/
        return fuzzyQuery;
    }
}

From source file:org.sindice.siren.qparser.keyword.builders.NodeFuzzyQueryNodeBuilder.java

License:Apache License

public NodeFuzzyQuery build(QueryNode queryNode) throws QueryNodeException {
    FuzzyQueryNode fuzzyNode = (FuzzyQueryNode) queryNode;
    String text = fuzzyNode.getTextAsString();

    int numEdits = FuzzyQuery.floatToEdits(fuzzyNode.getSimilarity(), text.codePointCount(0, text.length()));

    return new NodeFuzzyQuery(new Term(fuzzyNode.getFieldAsString(), fuzzyNode.getTextAsString()), numEdits,
            fuzzyNode.getPrefixLength());
}