当前位置: 首页>>代码示例>>Java>>正文


Java Regex类代码示例

本文整理汇总了Java中org.elasticsearch.common.regex.Regex的典型用法代码示例。如果您正苦于以下问题:Java Regex类的具体用法?Java Regex怎么用?Java Regex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Regex类属于org.elasticsearch.common.regex包,在下文中一共展示了Regex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: PatternAnalyzerProvider

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
public PatternAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) {
    super(indexSettings, name, settings);

    final CharArraySet defaultStopwords = CharArraySet.EMPTY_SET;
    boolean lowercase =
        settings.getAsBooleanLenientForPreEs6Indices(indexSettings.getIndexVersionCreated(), "lowercase", true, deprecationLogger);
    CharArraySet stopWords = Analysis.parseStopWords(env, indexSettings.getIndexVersionCreated(), settings, defaultStopwords);

    String sPattern = settings.get("pattern", "\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/);
    if (sPattern == null) {
        throw new IllegalArgumentException("Analyzer [" + name + "] of type pattern must have a `pattern` set");
    }
    Pattern pattern = Regex.compile(sPattern, settings.get("flags"));

    analyzer = new PatternAnalyzer(pattern, lowercase, stopWords);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:PatternAnalyzerProvider.java

示例2: buildTable

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
private Table buildTable(RestRequest request, ClusterStateResponse clusterStateResponse, String patternString) {
    Table table = getTableWithHeader(request);
    MetaData metadata = clusterStateResponse.getState().metaData();
    for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : metadata.templates()) {
        IndexTemplateMetaData indexData = entry.value;
        if (patternString == null || Regex.simpleMatch(patternString, indexData.name())) {
            table.startRow();
            table.addCell(indexData.name());
            table.addCell("[" + String.join(", ", indexData.patterns()) + "]");
            table.addCell(indexData.getOrder());
            table.addCell(indexData.getVersion());
            table.endRow();
        }
    }
    return table;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:RestTemplatesAction.java

示例3: isPatternMatchingAllIndices

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
/**
 * Identifies whether the first argument (an array containing index names) is a pattern that matches all indices
 *
 * @param indicesOrAliases the array containing index names
 * @param concreteIndices  array containing the concrete indices that the first argument refers to
 * @return true if the first argument is a pattern that maps to all available indices, false otherwise
 */
boolean isPatternMatchingAllIndices(MetaData metaData, String[] indicesOrAliases, String[] concreteIndices) {
    // if we end up matching on all indices, check, if its a wildcard parameter, or a "-something" structure
    if (concreteIndices.length == metaData.getConcreteAllIndices().length && indicesOrAliases.length > 0) {

        //we might have something like /-test1,+test1 that would identify all indices
        //or something like /-test1 with test1 index missing and IndicesOptions.lenient()
        if (indicesOrAliases[0].charAt(0) == '-') {
            return true;
        }

        //otherwise we check if there's any simple regex
        for (String indexOrAlias : indicesOrAliases) {
            if (Regex.isSimpleMatchPattern(indexOrAlias)) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:IndexNameExpressionResolver.java

示例4: filterSettings

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
private static Settings filterSettings(Iterable<String> patterns, Settings settings) {
    Settings.Builder builder = Settings.builder().put(settings);
    List<String> simpleMatchPatternList = new ArrayList<>();
    for (String pattern : patterns) {
        if (Regex.isSimpleMatchPattern(pattern)) {
            simpleMatchPatternList.add(pattern);
        } else {
            builder.remove(pattern);
        }
    }
    if (!simpleMatchPatternList.isEmpty()) {
        String[] simpleMatchPatterns = simpleMatchPatternList.toArray(new String[simpleMatchPatternList.size()]);
        Iterator<Entry<String, String>> iterator = builder.internalMap().entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> current = iterator.next();
            if (Regex.simpleMatch(simpleMatchPatterns, current.getKey())) {
                iterator.remove();
            }
        }
    }
    return builder.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:SettingsFilter.java

示例5: masterOperation

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
@Override
protected void masterOperation(GetIndexTemplatesRequest request, ClusterState state, ActionListener<GetIndexTemplatesResponse> listener) {
    List<IndexTemplateMetaData> results;

    // If we did not ask for a specific name, then we return all templates
    if (request.names().length == 0) {
        results = Arrays.asList(state.metaData().templates().values().toArray(IndexTemplateMetaData.class));
    } else {
        results = new ArrayList<>();
    }

    for (String name : request.names()) {
        if (Regex.isSimpleMatchPattern(name)) {
            for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : state.metaData().templates()) {
                if (Regex.simpleMatch(name, entry.key)) {
                    results.add(entry.value);
                }
            }
        } else if (state.metaData().templates().containsKey(name)) {
            results.add(state.metaData().templates().get(name));
        }
    }

    listener.onResponse(new GetIndexTemplatesResponse(results));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:TransportGetIndexTemplatesAction.java

示例6: match

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
public boolean match(Task task) {
    if (getActions() != null && getActions().length > 0 && Regex.simpleMatch(getActions(), task.getAction()) == false) {
        return false;
    }
    if (getTaskId().isSet()) {
        if(getTaskId().getId() != task.getId()) {
            return false;
        }
    }
    if (parentTaskId.isSet()) {
        if (parentTaskId.equals(task.getParentTaskId()) == false) {
            return false;
        }
    }
    return true;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:BaseTasksRequest.java

示例7: extractFieldAndBoost

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
private void extractFieldAndBoost(QueryParseContext parseContext, XContentParser parser, Map<String, Float> fieldNameWithBoosts) throws IOException {
    String fField = null;
    Float fBoost = null;
    char[] fieldText = parser.textCharacters();
    int end = parser.textOffset() + parser.textLength();
    for (int i = parser.textOffset(); i < end; i++) {
        if (fieldText[i] == '^') {
            int relativeLocation = i - parser.textOffset();
            fField = new String(fieldText, parser.textOffset(), relativeLocation);
            fBoost = Float.parseFloat(new String(fieldText, i + 1, parser.textLength() - relativeLocation - 1));
            break;
        }
    }
    if (fField == null) {
        fField = parser.text();
    }

    if (Regex.isSimpleMatchPattern(fField)) {
        for (String field : parseContext.mapperService().simpleMatchToIndexNames(fField)) {
            fieldNameWithBoosts.put(field, fBoost);
        }
    } else {
        fieldNameWithBoosts.put(fField, fBoost);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:MultiMatchQueryParser.java

示例8: PatternAnalyzerProvider

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
@Inject
public PatternAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, Environment env, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);

    Version esVersion = Version.indexCreated(indexSettingsService.getSettings());
    final CharArraySet defaultStopwords;
    if (esVersion.onOrAfter(Version.V_1_0_0_RC1)) {
        defaultStopwords = CharArraySet.EMPTY_SET;
    } else {
        defaultStopwords = StopAnalyzer.ENGLISH_STOP_WORDS_SET;
    }
    boolean lowercase = settings.getAsBoolean("lowercase", true);
    CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);

    String sPattern = settings.get("pattern", "\\W+" /*PatternAnalyzer.NON_WORD_PATTERN*/);
    if (sPattern == null) {
        throw new IllegalArgumentException("Analyzer [" + name + "] of type pattern must have a `pattern` set");
    }
    Pattern pattern = Regex.compile(sPattern, settings.get("flags"));

    analyzer = new PatternAnalyzer(pattern, lowercase, stopWords);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:PatternAnalyzerProvider.java

示例9: isPatternMatchingAllIndices

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
/**
 * Identifies whether the first argument (an array containing index names) is a pattern that matches all indices
 *
 * @param indicesOrAliases the array containing index names
 * @param concreteIndices  array containing the concrete indices that the first argument refers to
 * @return true if the first argument is a pattern that maps to all available indices, false otherwise
 */
boolean isPatternMatchingAllIndices(MetaData metaData, String[] indicesOrAliases, String[] concreteIndices) {
    // if we end up matching on all indices, check, if its a wildcard parameter, or a "-something" structure
    if (concreteIndices.length == metaData.concreteAllIndices().length && indicesOrAliases.length > 0) {

        //we might have something like /-test1,+test1 that would identify all indices
        //or something like /-test1 with test1 index missing and IndicesOptions.lenient()
        if (indicesOrAliases[0].charAt(0) == '-') {
            return true;
        }

        //otherwise we check if there's any simple regex
        for (String indexOrAlias : indicesOrAliases) {
            if (Regex.isSimpleMatchPattern(indexOrAlias)) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:27,代码来源:IndexNameExpressionResolver.java

示例10: filterSettings

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
public static Settings filterSettings(String patterns, Settings settings) {
    String[] patternArray = Strings.delimitedListToStringArray(patterns, ",");
    Settings.Builder builder = Settings.settingsBuilder().put(settings);
    List<String> simpleMatchPatternList = new ArrayList<>();
    for (String pattern : patternArray) {
        if (Regex.isSimpleMatchPattern(pattern)) {
            simpleMatchPatternList.add(pattern);
        } else {
            builder.remove(pattern);
        }
    }
    if (!simpleMatchPatternList.isEmpty()) {
        String[] simpleMatchPatterns = simpleMatchPatternList.toArray(new String[simpleMatchPatternList.size()]);
        Iterator<Entry<String, String>> iterator = builder.internalMap().entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> current = iterator.next();
            if (Regex.simpleMatch(simpleMatchPatterns, current.getKey())) {
                iterator.remove();
            }
        }
    }
    return builder.build();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:SettingsFilter.java

示例11: assertAllShardsOnNodes

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
/**
 * Asserts that all shards are allocated on nodes matching the given node pattern.
 */
public Set<String> assertAllShardsOnNodes(final String index, final String... pattern) {
    final Set<String> nodes = new HashSet<>();
    final ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    for (final IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (final IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (final ShardRouting shardRouting : indexShardRoutingTable) {
                if (shardRouting.currentNodeId() != null && index.equals(shardRouting.getIndex())) {
                    final String name = clusterState.nodes().get(shardRouting.currentNodeId()).name();
                    nodes.add(name);
                    assertThat("Allocated on new node: " + name, Regex.simpleMatch(pattern, name), is(true));
                }
            }
        }
    }
    return nodes;
}
 
开发者ID:salyh,项目名称:elasticsearch-sample-plugin-audit,代码行数:20,代码来源:ElasticsearchIntegrationTest.java

示例12: buildRemoteWhitelist

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
/**
 * Build the {@link CharacterRunAutomaton} that represents the reindex-from-remote whitelist and make sure that it doesn't whitelist
 * the world.
 */
static CharacterRunAutomaton buildRemoteWhitelist(List<String> whitelist) {
    if (whitelist.isEmpty()) {
        return new CharacterRunAutomaton(Automata.makeEmpty());
    }
    Automaton automaton = Regex.simpleMatchToAutomaton(whitelist.toArray(Strings.EMPTY_ARRAY));
    automaton = MinimizationOperations.minimize(automaton, Operations.DEFAULT_MAX_DETERMINIZED_STATES);
    if (Operations.isTotal(automaton)) {
        throw new IllegalArgumentException("Refusing to start because whitelist " + whitelist + " accepts all addresses. "
                + "This would allow users to reindex-from-remote any URL they like effectively having Elasticsearch make HTTP GETs "
                + "for them.");
    }
    return new CharacterRunAutomaton(automaton);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:TransportReindexAction.java

示例13: assertAllShardsOnNodes

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
/**
 * Asserts that all shards are allocated on nodes matching the given node pattern.
 */
public Set<String> assertAllShardsOnNodes(String index, String... pattern) {
    Set<String> nodes = new HashSet<>();
    ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
    for (IndexRoutingTable indexRoutingTable : clusterState.routingTable()) {
        for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) {
            for (ShardRouting shardRouting : indexShardRoutingTable) {
                if (shardRouting.currentNodeId() != null && index.equals(shardRouting.getIndexName())) {
                    String name = clusterState.nodes().get(shardRouting.currentNodeId()).getName();
                    nodes.add(name);
                    assertThat("Allocated on new node: " + name, Regex.simpleMatch(pattern, name), is(true));
                }
            }
        }
    }
    return nodes;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:ESIntegTestCase.java

示例14: completionStats

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
/**
 * Returns total in-heap bytes used by all suggesters.  This method has CPU cost <code>O(numIndexedFields)</code>.
 *
 * @param fieldNamePatterns if non-null, any completion field name matching any of these patterns will break out its in-heap bytes
 * separately in the returned {@link CompletionStats}
 */
public static CompletionStats completionStats(IndexReader indexReader, String ... fieldNamePatterns) {
    long sizeInBytes = 0;
    ObjectLongHashMap<String> completionFields = null;
    if (fieldNamePatterns != null  && fieldNamePatterns.length > 0) {
        completionFields = new ObjectLongHashMap<>(fieldNamePatterns.length);
    }
    for (LeafReaderContext atomicReaderContext : indexReader.leaves()) {
        LeafReader atomicReader = atomicReaderContext.reader();
        try {
            Fields fields = atomicReader.fields();
            for (String fieldName : fields) {
                Terms terms = fields.terms(fieldName);
                if (terms instanceof CompletionTerms) {
                    // TODO: currently we load up the suggester for reporting its size
                    long fstSize = ((CompletionTerms) terms).suggester().ramBytesUsed();
                    if (fieldNamePatterns != null && fieldNamePatterns.length > 0 && Regex.simpleMatch(fieldNamePatterns, fieldName)) {
                        completionFields.addTo(fieldName, fstSize);
                    }
                    sizeInBytes += fstSize;
                }
            }
        } catch (IOException ioe) {
            throw new ElasticsearchException(ioe);
        }
    }
    return new CompletionStats(sizeInBytes, completionFields == null ? null : new FieldMemoryStats(completionFields));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:CompletionFieldStats.java

示例15: innerDelete

import org.elasticsearch.common.regex.Regex; //导入依赖的package包/类
ClusterState innerDelete(DeletePipelineRequest request, ClusterState currentState) {
    IngestMetadata currentIngestMetadata = currentState.metaData().custom(IngestMetadata.TYPE);
    if (currentIngestMetadata == null) {
        return currentState;
    }
    Map<String, PipelineConfiguration> pipelines = currentIngestMetadata.getPipelines();
    Set<String> toRemove = new HashSet<>();
    for (String pipelineKey : pipelines.keySet()) {
        if (Regex.simpleMatch(request.getId(), pipelineKey)) {
            toRemove.add(pipelineKey);
        }
    }
    if (toRemove.isEmpty() && Regex.isMatchAllPattern(request.getId()) == false) {
        throw new ResourceNotFoundException("pipeline [{}] is missing", request.getId());
    } else if (toRemove.isEmpty()) {
        return currentState;
    }
    final Map<String, PipelineConfiguration> pipelinesCopy = new HashMap<>(pipelines);
    for (String key : toRemove) {
        pipelinesCopy.remove(key);
    }
    ClusterState.Builder newState = ClusterState.builder(currentState);
    newState.metaData(MetaData.builder(currentState.getMetaData())
            .putCustom(IngestMetadata.TYPE, new IngestMetadata(pipelinesCopy))
            .build());
    return newState.build();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:PipelineStore.java


注:本文中的org.elasticsearch.common.regex.Regex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。