org.elasticsearch.common.io.FastStringReader Java Examples
The following examples show how to use
org.elasticsearch.common.io.FastStringReader.
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 File: MustacheScriptEngineService.java From Elasticsearch with Apache License 2.0 | 6 votes |
/** * 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 File: PropertiesSettingsLoader.java From Elasticsearch with Apache License 2.0 | 5 votes |
@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 File: XMoreLikeThis.java From Elasticsearch with Apache License 2.0 | 5 votes |
/** * 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 File: Strings.java From Elasticsearch with Apache License 2.0 | 5 votes |
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 File: TransportAnalyzeAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
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 File: AllEntries.java From Elasticsearch with Apache License 2.0 | 4 votes |
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 File: AllEntries.java From Elasticsearch with Apache License 2.0 | 4 votes |
public FastStringReader reader() { return this.reader; }
Example #8
Source File: YamlXContent.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public XContentParser createParser(String content) throws IOException { return new YamlXContentParser(yamlFactory.createParser(new FastStringReader(content))); }
Example #9
Source File: CborXContent.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public XContentParser createParser(String content) throws IOException { return new CborXContentParser(cborFactory.createParser(new FastStringReader(content))); }
Example #10
Source File: JsonXContent.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public XContentParser createParser(String content) throws IOException { return new JsonXContentParser(jsonFactory.createParser(new FastStringReader(content))); }
Example #11
Source File: SmileXContent.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override public XContentParser createParser(String content) throws IOException { return new SmileXContentParser(smileFactory.createParser(new FastStringReader(content))); }
Example #12
Source File: XmlXContent.java From elasticsearch-xml with Apache License 2.0 | 4 votes |
@Override public XContentParser createParser(String content) throws IOException { return new XmlXContentParser(xmlFactory.createParser(new FastStringReader(content))); }