public Path getConfigInPluginDir() { return PathUtils .get(new File(AnalysisIkPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath()) .getParent(), "config") .toAbsolutePath(); }
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; }
@Override protected void prepareIndexRequest(IndexRequestBuilder indexRequest, String indexName, String indexType, Event event) throws IOException { BytesStream contentBuilder = serializer.getContentBuilder(event); indexRequest.setIndex(indexName) .setType(indexType) .setSource(contentBuilder.bytes()); } }
/** * read <i>length</i> bytes from <i>position</i> of a file channel */ public static byte[] readFromFileChannel(FileChannel channel, long position, int length) throws IOException { byte[] res = new byte[length]; readFromFileChannelWithEofException(channel, position, res, 0, length); return res; }
/** * Writes part of a byte array to a {@link java.nio.channels.WritableByteChannel} * * @param source byte array to copy from * @param channel target WritableByteChannel */ public static void writeToChannel(byte[] source, WritableByteChannel channel) throws IOException { writeToChannel(source, 0, source.length, channel); }
@Override public void start(Description description) throws Exception { FileSystemUtils.deleteRecursively(new File(embedded.getConfig().getDataDir())); embedded.start(); }
/** * Wraps the given {@link BytesStream} in a {@link StreamOutput} that simply flushes when * close is called. */ public static BytesStream flushOnCloseStream(BytesStream os) { return new FlushOnCloseOutputStream(os); }
/** * 加载用户配置的扩展词典到主词库表 */ private void loadExtDict() { // 加载扩展词典配置 List<String> extDictFiles = getExtDictionarys(); if (extDictFiles != null) { for (String extDictName : extDictFiles) { // 读取扩展词典文件 logger.info("[Dict Loading] " + extDictName); Path file = PathUtils.get(extDictName); loadDictFile(_MainDict, file, false, "Extra Dict"); } } }
@Override public void addEvent(Event event, IndexNameBuilder indexNameBuilder, String indexType, long ttlMs) throws Exception { BytesReference content = serializer.getContentBuilder(event).bytes(); Map<String, Map<String, String>> parameters = new HashMap<String, Map<String, String>>(); Map<String, String> indexParameters = new HashMap<String, String>(); indexParameters.put(INDEX_PARAM, indexNameBuilder.getIndexName(event)); indexParameters.put(TYPE_PARAM, indexType); if (ttlMs > 0) { indexParameters.put(TTL_PARAM, Long.toString(ttlMs)); } parameters.put(INDEX_OPERATION_NAME, indexParameters); Gson gson = new Gson(); synchronized (bulkBuilder) { bulkBuilder.append(gson.toJson(parameters)); bulkBuilder.append("\n"); bulkBuilder.append(content.toBytesArray().toUtf8()); bulkBuilder.append("\n"); } }
@Override public void stop(Description description) { embedded.stop(); FileSystemUtils.deleteRecursively(new File(embedded.getConfig().getDataDir())); }
public List<String> getExtStopWordDictionarys() { List<String> extStopWordDictFiles = new ArrayList<String>(2); String extStopWordDictCfg = getProperty(EXT_STOP); if (extStopWordDictCfg != null) { String[] filePaths = extStopWordDictCfg.split(";"); for (String filePath : filePaths) { if (filePath != null && !"".equals(filePath.trim())) { Path file = PathUtils.get(getDictRoot(), filePath.trim()); walkFileTree(extStopWordDictFiles, file); } } } return extStopWordDictFiles; }
@Override public void addEvent(Event event, IndexNameBuilder indexNameBuilder, String indexType, long ttlMs) throws Exception { if (bulkRequestBuilder == null) { bulkRequestBuilder = client.prepareBulk(); } IndexRequestBuilder indexRequestBuilder = null; if (indexRequestBuilderFactory == null) { indexRequestBuilder = client .prepareIndex(indexNameBuilder.getIndexName(event), indexType) .setSource(serializer.getContentBuilder(event).bytes()); } else { indexRequestBuilder = indexRequestBuilderFactory.createIndexRequest( client, indexNameBuilder.getIndexPrefix(event), indexType, event); } if (ttlMs > 0) { indexRequestBuilder.setTTL(ttlMs); } bulkRequestBuilder.add(indexRequestBuilder); }
public List<String> getExtDictionarys() { List<String> extDictFiles = new ArrayList<String>(2); String extDictCfg = getProperty(EXT_DICT); if (extDictCfg != null) { String[] filePaths = extDictCfg.split(";"); for (String filePath : filePaths) { if (filePath != null && !"".equals(filePath.trim())) { Path file = PathUtils.get(getDictRoot(), filePath.trim()); walkFileTree(extDictFiles, file); } } } return extDictFiles; }
private void loadSurnameDict() { _SurnameDict = new DictSegment((char) 0); Path file = PathUtils.get(getDictRoot(), Dictionary.PATH_DIC_SURNAME); loadDictFile(_SurnameDict, file, true, "Surname"); }
private void loadSuffixDict() { _SuffixDict = new DictSegment((char) 0); Path file = PathUtils.get(getDictRoot(), Dictionary.PATH_DIC_SUFFIX); loadDictFile(_SuffixDict, file, true, "Suffix"); }
private void loadPrepDict() { _PrepDict = new DictSegment((char) 0); Path file = PathUtils.get(getDictRoot(), Dictionary.PATH_DIC_PREP); loadDictFile(_PrepDict, file, true, "Preposition"); }
/** * 加载量词词典 */ private void loadQuantifierDict() { // 建立一个量词典实例 _QuantifierDict = new DictSegment((char) 0); // 读取量词词典文件 Path file = PathUtils.get(getDictRoot(), Dictionary.PATH_DIC_QUANTIFIER); loadDictFile(_QuantifierDict, file, false, "Quantifier"); }
/** * 加载主词典及扩展词典 */ private void loadMainDict() { // 建立一个主词典实例 _MainDict = new DictSegment((char) 0); // 读取主词典文件 Path file = PathUtils.get(getDictRoot(), Dictionary.PATH_DIC_MAIN); loadDictFile(_MainDict, file, false, "Main Dict"); // 加载扩展词典 this.loadExtDict(); // 加载远程自定义词库 this.loadRemoteExtDict(); }
/** * Resolves the specified location against the list of configured repository roots * * If the specified location doesn't match any of the roots, returns null. */ public Path resolveRepoFile(String location) { return PathUtils.get(repoFiles, location); }