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


Java Fuzziness类代码示例

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


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

示例1: testForClient

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
@Test
public void testForClient() throws Exception {

    /**
     * @see <a href='https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-multi-match-query.html'></a>
     * MultiMatchQuery依赖于match query ,也就是其核心是基于MatchQuery构建的
     *
     */

    MultiMatchQueryBuilder multiMatchQueryBuilder = QueryBuilders.multiMatchQuery("elasticsearch match query","title", "descrption");

    multiMatchQueryBuilder.analyzer("standard");
    multiMatchQueryBuilder.cutoffFrequency(0.001f);
    multiMatchQueryBuilder.field("title",20);
    multiMatchQueryBuilder.fuzziness(Fuzziness.TWO);
    multiMatchQueryBuilder.maxExpansions(100);
    multiMatchQueryBuilder.prefixLength(10);
    multiMatchQueryBuilder.tieBreaker(20);
    multiMatchQueryBuilder.type(MultiMatchQueryBuilder.Type.BEST_FIELDS);
    multiMatchQueryBuilder.boost(20);



   SearchResponse searchResponse =  client.prepareSearch()
            .setIndices("blogs")
            .setTypes("blog")
            .setQuery(multiMatchQueryBuilder)
            .execute()
            .actionGet();

}
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:32,代码来源:MultiMatchQueryDemo.java

示例2: testThatFuzzySuggesterSupportsTranspositions

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
public void testThatFuzzySuggesterSupportsTranspositions() throws Exception {
    createIndexAndMapping(completionMappingBuilder);

    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
            .startObject().startObject(FIELD)
            .startArray("input").value("Nirvana").endArray()
            .endObject().endObject()
    ).get();

    refresh();

    SearchResponse searchResponse = client().prepareSearch(INDEX).suggest(
        new SuggestBuilder().addSuggestion("foo",
            SuggestBuilders.completionSuggestion(FIELD).prefix("Nriv", FuzzyOptions.builder().setTranspositions(false).build()).size(10))
    ).execute().actionGet();
    assertSuggestions(searchResponse, false, "foo");

    searchResponse = client().prepareSearch(INDEX).suggest(
        new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion(FIELD).prefix("Nriv", Fuzziness.ONE).size(10))
    ).execute().actionGet();
    assertSuggestions(searchResponse, false, "foo", "Nirvana");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:CompletionSuggestSearchIT.java

示例3: getFuzzyQuerySingle

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
private Query getFuzzyQuerySingle(String field, String termStr, String minSimilarity) throws ParseException {
    currentFieldType = context.fieldMapper(field);
    if (currentFieldType != null) {
        try {
            BytesRef term = termStr == null ? null : getAnalyzer().normalize(field, termStr);
            return currentFieldType.fuzzyQuery(term, Fuzziness.build(minSimilarity),
                getFuzzyPrefixLength(), settings.fuzzyMaxExpansions(), FuzzyQuery.defaultTranspositions);
        } catch (RuntimeException e) {
            if (settings.lenient()) {
                return null;
            }
            throw e;
        }
    }
    return super.getFuzzyQuery(field, termStr, Float.parseFloat(minSimilarity));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MapperQueryParser.java

示例4: MultiMatchQueryBuilder

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
/**
 * Read from a stream.
 */
public MultiMatchQueryBuilder(StreamInput in) throws IOException {
    super(in);
    value = in.readGenericValue();
    int size = in.readVInt();
    fieldsBoosts = new TreeMap<>();
    for (int i = 0; i < size; i++) {
        fieldsBoosts.put(in.readString(), in.readFloat());
    }
    type = Type.readFromStream(in);
    operator = Operator.readFromStream(in);
    analyzer = in.readOptionalString();
    slop = in.readVInt();
    fuzziness = in.readOptionalWriteable(Fuzziness::new);
    prefixLength = in.readVInt();
    maxExpansions = in.readVInt();
    minimumShouldMatch = in.readOptionalString();
    fuzzyRewrite = in.readOptionalString();
    useDisMax = in.readOptionalBoolean();
    tieBreaker = in.readOptionalFloat();
    lenient = in.readBoolean();
    cutoffFrequency = in.readOptionalFloat();
    zeroTermsQuery = MatchQuery.ZeroTermsQuery.readFromStream(in);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:MultiMatchQueryBuilder.java

示例5: MatchQueryBuilder

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
/**
 * Read from a stream.
 */
public MatchQueryBuilder(StreamInput in) throws IOException {
    super(in);
    fieldName = in.readString();
    value = in.readGenericValue();
    type = MatchQuery.Type.readFromStream(in);
    operator = Operator.readFromStream(in);
    slop = in.readVInt();
    prefixLength = in.readVInt();
    maxExpansions = in.readVInt();
    fuzzyTranspositions = in.readBoolean();
    lenient = in.readBoolean();
    zeroTermsQuery = MatchQuery.ZeroTermsQuery.readFromStream(in);
    // optional fields
    analyzer = in.readOptionalString();
    minimumShouldMatch = in.readOptionalString();
    fuzzyRewrite = in.readOptionalString();
    fuzziness = in.readOptionalWriteable(Fuzziness::new);
    cutoffFrequency = in.readOptionalFloat();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:MatchQueryBuilder.java

示例6: testThatFuzzySuggesterWorks

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
public void testThatFuzzySuggesterWorks() throws Exception {
    createIndexAndMapping(completionMappingBuilder);

    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
            .startObject().startObject(FIELD)
            .startArray("input").value("Nirvana").endArray()
            .endObject().endObject()
    ).get();

    refresh();

    SearchResponse searchResponse = client().prepareSearch(INDEX).suggest(
        new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion(FIELD).prefix("Nirv").size(10))
    ).execute().actionGet();
    assertSuggestions(searchResponse, false, "foo", "Nirvana");

    searchResponse = client().prepareSearch(INDEX).suggest(
        new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion(FIELD).prefix("Nirw", Fuzziness.ONE).size(10))
    ).execute().actionGet();
    assertSuggestions(searchResponse, false, "foo", "Nirvana");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:CompletionSuggestSearchIT.java

示例7: testThatFuzzySuggesterSupportsEditDistances

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
public void testThatFuzzySuggesterSupportsEditDistances() throws Exception {
    createIndexAndMapping(completionMappingBuilder);

    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder()
            .startObject().startObject(FIELD)
            .startArray("input").value("Nirvana").endArray()
            .endObject().endObject()
    ).get();

    refresh();

    // edit distance 1
    SearchResponse searchResponse = client().prepareSearch(INDEX).suggest(
        new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion(FIELD).prefix("Norw", Fuzziness.ONE).size(10))
    ).execute().actionGet();
    assertSuggestions(searchResponse, false, "foo");

    // edit distance 2
    searchResponse = client().prepareSearch(INDEX).suggest(
        new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion(FIELD).prefix("Norw", Fuzziness.TWO).size(10))
    ).execute().actionGet();
    assertSuggestions(searchResponse, false, "foo", "Nirvana");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:CompletionSuggestSearchIT.java

示例8: testToQueryWithStringField

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
public void testToQueryWithStringField() throws IOException {
    assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
    String query = "{\n" +
            "    \"fuzzy\":{\n" +
            "        \"" + STRING_FIELD_NAME + "\":{\n" +
            "            \"value\":\"sh\",\n" +
            "            \"fuzziness\": \"AUTO\",\n" +
            "            \"prefix_length\":1,\n" +
            "            \"boost\":2.0\n" +
            "        }\n" +
            "    }\n" +
            "}";
    Query parsedQuery = parseQuery(query).toQuery(createShardContext());
    assertThat(parsedQuery, instanceOf(BoostQuery.class));
    BoostQuery boostQuery = (BoostQuery) parsedQuery;
    assertThat(boostQuery.getBoost(), equalTo(2.0f));
    assertThat(boostQuery.getQuery(), instanceOf(FuzzyQuery.class));
    FuzzyQuery fuzzyQuery = (FuzzyQuery) boostQuery.getQuery();
    assertThat(fuzzyQuery.getTerm(), equalTo(new Term(STRING_FIELD_NAME, "sh")));
    assertThat(fuzzyQuery.getMaxEdits(), equalTo(Fuzziness.AUTO.asDistance("sh")));
    assertThat(fuzzyQuery.getPrefixLength(), equalTo(1));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:FuzzyQueryBuilderTests.java

示例9: testFuzzyQueryType

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
public void testFuzzyQueryType() throws Exception {
    String mapping = jsonBuilder().startObject().startObject("type1")
            .startObject("properties").startObject("completion")
            .field("type", "completion")
            .endObject().endObject()
            .endObject().endObject().string();

    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
    CompletionFieldMapper completionFieldMapper = (CompletionFieldMapper) fieldMapper;
    Query prefixQuery = completionFieldMapper.fieldType().fuzzyQuery("co",
            Fuzziness.fromEdits(FuzzyCompletionQuery.DEFAULT_MAX_EDITS), FuzzyCompletionQuery.DEFAULT_NON_FUZZY_PREFIX,
            FuzzyCompletionQuery.DEFAULT_MIN_FUZZY_LENGTH, Operations.DEFAULT_MAX_DETERMINIZED_STATES,
            FuzzyCompletionQuery.DEFAULT_TRANSPOSITIONS, FuzzyCompletionQuery.DEFAULT_UNICODE_AWARE);
    assertThat(prefixQuery, instanceOf(FuzzyCompletionQuery.class));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:CompletionFieldMapperTests.java

示例10: innerToXContent

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
@Override
protected XContentBuilder innerToXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
    builder.startObject("fuzzy");

    if (fuzziness != Fuzziness.ONE) {
        fuzziness.toXContent(builder, params);
    }
    if (fuzzyTranspositions != XFuzzySuggester.DEFAULT_TRANSPOSITIONS) {
        builder.field("transpositions", fuzzyTranspositions);
    }
    if (fuzzyMinLength != XFuzzySuggester.DEFAULT_MIN_FUZZY_LENGTH) {
        builder.field("min_length", fuzzyMinLength);
    }
    if (fuzzyPrefixLength != XFuzzySuggester.DEFAULT_NON_FUZZY_PREFIX) {
        builder.field("prefix_length", fuzzyPrefixLength);
    }
    if (unicodeAware != XFuzzySuggester.DEFAULT_UNICODE_AWARE) {
        builder.field("unicode_aware", unicodeAware);
    }

    builder.endObject();
    return builder;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:24,代码来源:CompletionSuggestionFuzzyBuilder.java

示例11: testForClient

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
@Test
    public void testForClient() throws Exception {
        QueryBuilder qb = QueryBuilders.matchQuery("title","quack dog")
                .boost(100.00f)
                .fuzziness(Fuzziness.ONE)
                .prefixLength(0)
//                .operator(Operator.AND)
                ;

        SearchResponse response = client.prepareSearch()
                .setIndices("my_index")
                .setTypes("my_type")
                .setQuery(qb)
                .execute()
                .actionGet();

        println(response);
    }
 
开发者ID:felayman,项目名称:elasticsearch-full,代码行数:19,代码来源:MatchQueryDemo.java

示例12: getMovies

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
public static LinkedList<String> getMovies(LinkedList<String> tokens, Client client) {

        SearchResponse res = null;
        res = client.prepareSearch()
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setIndices("movies")
                .setQuery(QueryBuilders.fuzzyLikeThisFieldQuery("movie").fuzziness(Fuzziness.TWO).likeText(tokens.toString()))
                .setFrom(0).setExplain(true)
                .execute().actionGet();

        SearchHit[] sh = res.getHits().getHits();
        LinkedList<String> toReturn = new LinkedList<String>();

        for (SearchHit hit : sh) {
            toReturn.add(hit.getSource().get("movie").toString());

        }
        return toReturn;
    }
 
开发者ID:ironmanMA,项目名称:continuum,代码行数:19,代码来源:TextHelper.java

示例13: getPlaces

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
public static LinkedList<String> getPlaces(LinkedList<String> tokens, Client client) {

        SearchResponse res = null;
        res = client.prepareSearch()
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setIndices("places")
                .setQuery(QueryBuilders.fuzzyLikeThisFieldQuery("place").fuzziness(Fuzziness.TWO).likeText(tokens.toString()))
                .setFrom(0).setExplain(true)
                .execute().actionGet();

        SearchHit[] sh = res.getHits().getHits();
        LinkedList<String> toReturn = new LinkedList<String>();

        for (SearchHit hit : sh) {
            toReturn.add(hit.getSource().get("place").toString());

        }
        return toReturn;
    }
 
开发者ID:ironmanMA,项目名称:continuum,代码行数:19,代码来源:TextHelper.java

示例14: getFood

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
public static LinkedList<String> getFood(LinkedList<String> tokens, Client client) {

        SearchResponse res = null;
        res = client.prepareSearch()
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setIndices("food")
                .setQuery(QueryBuilders.fuzzyLikeThisFieldQuery("item").fuzziness(Fuzziness.TWO).likeText(tokens.toString()))
                .setFrom(0).setExplain(true)
                .execute().actionGet();

        SearchHit[] sh = res.getHits().getHits();
        LinkedList<String> toReturn = new LinkedList<String>();

        for (SearchHit hit : sh) {
            toReturn.add(hit.getSource().get("item").toString());

        }
        return toReturn;
    }
 
开发者ID:ironmanMA,项目名称:continuum,代码行数:19,代码来源:TextHelper.java

示例15: randomFuzziness

import org.elasticsearch.common.unit.Fuzziness; //导入依赖的package包/类
protected static Fuzziness randomFuzziness(String fieldName) {
    switch (fieldName) {
        case INT_FIELD_NAME:
            return Fuzziness.build(randomIntBetween(3, 100));
        case DOUBLE_FIELD_NAME:
            return Fuzziness.build(1 + randomFloat() * 10);
        case DATE_FIELD_NAME:
            return Fuzziness.build(randomTimeValue());
        default:
            if (randomBoolean()) {
                return Fuzziness.fromEdits(randomIntBetween(0, 2));
            }
            return Fuzziness.AUTO;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:16,代码来源:AbstractQueryTestCase.java


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