Java Code Examples for org.elasticsearch.common.io.FastStringReader

The following examples show how to use org.elasticsearch.common.io.FastStringReader. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Elasticsearch   Source File: MustacheScriptEngineService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Compile a template string to (in this case) a Mustache object than can
 * later be re-used for execution to fill in missing parameter values.
 *
 * @param template
 *            a string representing the template to compile.
 * @return a compiled template object for later execution.
 * */
@Override
public Object compile(String template, Map<String, String> params) {
    String contentType = params.get(CONTENT_TYPE_PARAM);
    if (contentType == null) {
        contentType = JSON_CONTENT_TYPE;
    }

    final DefaultMustacheFactory mustacheFactory;
    switch (contentType){
        case PLAIN_TEXT_CONTENT_TYPE:
            mustacheFactory = new NoneEscapingMustacheFactory();
            break;
        case JSON_CONTENT_TYPE:
        default:
            // assume that the default is json encoding:
            mustacheFactory = new JsonEscapingMustacheFactory();
            break;
    }
    mustacheFactory.setObjectHandler(new CustomReflectionObjectHandler());
    Reader reader = new FastStringReader(template);
    return mustacheFactory.compile(reader, "query-template");
}
 
Example 2
Source Project: Elasticsearch   Source File: PropertiesSettingsLoader.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> load(String source) throws IOException {
    Properties props = new NoDuplicatesProperties();
    FastStringReader reader = new FastStringReader(source);
    try {
        props.load(reader);
        Map<String, String> result = newHashMap();
        for (Map.Entry entry : props.entrySet()) {
            result.put((String) entry.getKey(), (String) entry.getValue());
        }
        return result;
    } finally {
        IOUtils.closeWhileHandlingException(reader);
    }
}
 
Example 3
Source Project: Elasticsearch   Source File: XMoreLikeThis.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Find words for a more-like-this query former.
 *
 * @param docNum the id of the lucene document from which to find terms
 */
private PriorityQueue<ScoreTerm> retrieveTerms(int docNum) throws IOException {
    Map<String, Int> termFreqMap = new HashMap<>();
    for (String fieldName : fieldNames) {
        final Fields vectors = ir.getTermVectors(docNum);
        final Terms vector;
        if (vectors != null) {
            vector = vectors.terms(fieldName);
        } else {
            vector = null;
        }

        // field does not store term vector info
        if (vector == null) {
            Document d = ir.document(docNum);
            IndexableField fields[] = d.getFields(fieldName);
            for (IndexableField field : fields) {
                final String stringValue = field.stringValue();
                if (stringValue != null) {
                    addTermFrequencies(new FastStringReader(stringValue), termFreqMap, fieldName);
                }
            }
        } else {
            addTermFrequencies(termFreqMap, vector, fieldName);
        }
    }

    return createQueue(termFreqMap);
}
 
Example 4
Source Project: Elasticsearch   Source File: Strings.java    License: Apache License 2.0 5 votes vote down vote up
public static void spaceify(int spaces, String from, StringBuilder to) throws Exception {
    try (BufferedReader reader = new BufferedReader(new FastStringReader(from))) {
        String line;
        while ((line = reader.readLine()) != null) {
            for (int i = 0; i < spaces; i++) {
                to.append(' ');
            }
            to.append(line).append('\n');
        }
    }
}
 
Example 5
Source Project: Elasticsearch   Source File: TransportAnalyzeAction.java    License: Apache License 2.0 5 votes vote down vote up
private static TokenStream createStackedTokenStream(String source, CharFilterFactory[] charFilterFactories, TokenizerFactory tokenizerFactory, TokenFilterFactory[] tokenFilterFactories, int current) {
    Reader reader = new FastStringReader(source);
    for (CharFilterFactory charFilterFactory : charFilterFactories) {
        reader = charFilterFactory.create(reader);
    }
    Tokenizer tokenizer = tokenizerFactory.create();
    tokenizer.setReader(reader);
    TokenStream tokenStream = tokenizer;
    for (int i = 0; i < current; i++) {
        tokenStream = tokenFilterFactories[i].create(tokenStream);
    }
    return tokenStream;
}
 
Example 6
Source Project: Elasticsearch   Source File: AllEntries.java    License: Apache License 2.0 4 votes vote down vote up
public Entry(String name, FastStringReader reader, int startOffset, float boost) {
    this.name = name;
    this.reader = reader;
    this.startOffset = startOffset;
    this.boost = boost;
}
 
Example 7
Source Project: Elasticsearch   Source File: AllEntries.java    License: Apache License 2.0 4 votes vote down vote up
public FastStringReader reader() {
    return this.reader;
}
 
Example 8
Source Project: Elasticsearch   Source File: YamlXContent.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public XContentParser createParser(String content) throws IOException {
    return new YamlXContentParser(yamlFactory.createParser(new FastStringReader(content)));
}
 
Example 9
Source Project: Elasticsearch   Source File: CborXContent.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public XContentParser createParser(String content) throws IOException {
    return new CborXContentParser(cborFactory.createParser(new FastStringReader(content)));
}
 
Example 10
Source Project: Elasticsearch   Source File: JsonXContent.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public XContentParser createParser(String content) throws IOException {
    return new JsonXContentParser(jsonFactory.createParser(new FastStringReader(content)));
}
 
Example 11
Source Project: Elasticsearch   Source File: SmileXContent.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public XContentParser createParser(String content) throws IOException {
    return new SmileXContentParser(smileFactory.createParser(new FastStringReader(content)));
}
 
Example 12
Source Project: elasticsearch-xml   Source File: XmlXContent.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public XContentParser createParser(String content) throws IOException {
    return new XmlXContentParser(xmlFactory.createParser(new FastStringReader(content)));
}