public static String getRiverVersion() { String version = "Undefined"; try { String properties = Streams.copyToStringFromClasspath("/org/elasticsearch/river/mongodb/es-build.properties"); Properties props = new Properties(); props.load(new FastStringReader(properties)); String ver = props.getProperty("version", "undefined"); String hash = props.getProperty("hash", "undefined"); if (!"undefined".equals(hash)) { hash = hash.substring(0, 7); } String timestamp = "undefined"; String gitTimestampRaw = props.getProperty("timestamp"); if (gitTimestampRaw != null) { timestamp = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(Long.parseLong(gitTimestampRaw)); } version = String.format("version[%s] - hash[%s] - time[%s]", ver, hash, timestamp); } catch (Exception ex) { } return version; }
/** * First call will return the original Reader provided. */ @Override public Reader giveAClone() { if (original != null) { Reader rtn = original; original = null; // no longer hold a reference return rtn; } return new FastStringReader(originalContent); }
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'); } } }
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'); } } }
@Override public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException { return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(new FastStringReader(content))); }
@Override public Factory buildFactory() { try { String properties = Resources.toString(Resources.getResource("es-build.properties"), UTF_8); Properties props = new Properties(); props.load(new FastStringReader(properties)); clientVersion = props.getProperty("version", "2.x"); } catch (IOException ignored) { } return new Factory(this); } }
@Override public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException { return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(new FastStringReader(content))); }
@Override public XContentParser createParser(String content) throws IOException { return new SmileXContentParser(smileFactory.createParser(new FastStringReader(content))); }
@Override public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException { return new CborXContentParser(xContentRegistry, cborFactory.createParser(new FastStringReader(content))); }
@Override public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException { return new SmileXContentParser(xContentRegistry, smileFactory.createParser(new FastStringReader(content))); }
@Override public XContentParser createParser(String content) throws IOException { return new CborXContentParser(cborFactory.createParser(new FastStringReader(content))); }
@Override public XContentParser createParser(String content) throws IOException { return new YamlXContentParser(yamlFactory.createParser(new FastStringReader(content))); }
@Override public XContentParser createParser(String content) throws IOException { return new JsonXContentParser(jsonFactory.createParser(new FastStringReader(content))); }
@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); } }
public void addText(String name, String text, float boost) { if (boost != 1.0f) { customBoost = true; } final int lastStartOffset; if (entries.isEmpty()) { lastStartOffset = -1; } else { final Entry last = entries.get(entries.size() - 1); lastStartOffset = last.startOffset() + last.reader().length(); } final int startOffset = lastStartOffset + 1; // +1 because we insert a space between tokens Entry entry = new Entry(name, new FastStringReader(text), startOffset, boost); entries.add(entry); }
/** * 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) { final MustacheFactory factory = new CustomMustacheFactory(isJsonEscapingEnabled(params)); Reader reader = new FastStringReader(template); return factory.compile(reader, "query-template"); }
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; }
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; }
private Query createQuery(XMoreLikeThis mlt) throws IOException { BooleanQuery.Builder bqBuilder = new BooleanQuery.Builder(); if (this.likeFields != null) { Query mltQuery = mlt.like(this.likeFields); mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch); bqBuilder.add(mltQuery, BooleanClause.Occur.SHOULD); } if (this.likeText != null) { Reader[] readers = new Reader[likeText.length]; for (int i = 0; i < readers.length; i++) { readers[i] = new FastStringReader(likeText[i]); } //LUCENE 4 UPGRADE this mapps the 3.6 behavior (only use the first field) Query mltQuery = mlt.like(moreLikeFields[0], readers); mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch); bqBuilder.add(mltQuery, BooleanClause.Occur.SHOULD); } return bqBuilder.build(); }
private Query createQuery(XMoreLikeThis mlt) throws IOException { BooleanQuery.Builder bqBuilder = new BooleanQuery.Builder(); if (this.likeFields != null) { Query mltQuery = mlt.like(this.likeFields); mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch); bqBuilder.add(mltQuery, BooleanClause.Occur.SHOULD); } if (this.likeText != null) { Reader[] readers = new Reader[likeText.length]; for (int i = 0; i < readers.length; i++) { readers[i] = new FastStringReader(likeText[i]); } //LUCENE 4 UPGRADE this mapps the 3.6 behavior (only use the first field) Query mltQuery = mlt.like(moreLikeFields[0], readers); mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch); bqBuilder.add(mltQuery, BooleanClause.Occur.SHOULD); } BooleanQuery bq = bqBuilder.build(); bq.setBoost(getBoost()); return bq; }