private boolean isPatternIndex(Index index) { return PathBuilder.isRegexPath(index.getPath()); }
@Override public Path[] createIndex(Index index) throws BagriException { Set<Integer> paths = getPathsForIndex(index); Path[] result = new Path[paths.size()]; int idx = 0; for (Integer pathId: paths) { //idxDict.putIfAbsent(pathId, index); idxDict.put(pathId, index); //indexStats.initStats(index.getName()); if (index.isRange()) { rangeIndex.put(pathId, new TreeMap<Comparable, Integer>()); logger.trace("createIndex; registered range index path: {}", index.getName()); } result[idx] = mdlMgr.getPath(pathId); idx++; } if (isPatternIndex(index)) { //String path = mdlMgr.normalizePath(index.getPath()); String path = index.getPath(); path = path.replaceAll("\\{", Matcher.quoteReplacement("\\{")); path = path.replaceAll("\\}", Matcher.quoteReplacement("\\}")); patterns.put(index, Pattern.compile(PathBuilder.regexFromPath(path))); } return result; }
private Set<Integer> getPathsForIndex(Index index) throws BagriException { String path = index.getPath(); Set<Integer> result; if (PathBuilder.isRegexPath(path)) { // replace {} result = mdlMgr.translatePathFromRegex(index.getDocumentType(), PathBuilder.regexFromPath(path)); } else { int dataType = XQUtils.getBaseTypeForTypeName(index.getDataType()); Path xPath = mdlMgr.translatePath(index.getDocumentType(), path, NodeKind.fromPath(path), 0, dataType, Occurrence.zeroOrOne); result = new HashSet<>(1); result.add(xPath.getPathId()); } logger.trace("getPathsForIndex; returning {} for index {}", result, index); return result; }
@Override public void write(ObjectDataOutput out, Index xIndex) throws IOException { super.writeEntity(out, xIndex); out.writeUTF(xIndex.getName()); out.writeUTF(xIndex.getDocumentType()); out.writeUTF(xIndex.getTypePath()); out.writeUTF(xIndex.getPath()); out.writeUTF(xIndex.getDataType().toString()); out.writeBoolean(xIndex.isCaseSensitive()); out.writeBoolean(xIndex.isRange()); out.writeBoolean(xIndex.isUnique()); out.writeUTF(xIndex.getDescription()); out.writeBoolean(xIndex.isEnabled()); }