Java Code Examples for org.elasticsearch.index.query.QueryBuilders#matchPhrasePrefixQuery()

The following examples show how to use org.elasticsearch.index.query.QueryBuilders#matchPhrasePrefixQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatchPhrasePrefixQueryDemo.java    From elasticsearch-full with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
    String key = "this is a";
    MatchPhrasePrefixQueryBuilder matchPhrasePrefixQueryBuilder = QueryBuilders.matchPhrasePrefixQuery("title",key);

    matchPhrasePrefixQueryBuilder.boost(10);
    matchPhrasePrefixQueryBuilder.analyzer("standard");
    matchPhrasePrefixQueryBuilder.slop(2);
    matchPhrasePrefixQueryBuilder.maxExpansions(100);

    SearchResponse searchResponse = client.prepareSearch()
            .setIndices("my_index")
            .setTypes("my_type")
            .setQuery(matchPhrasePrefixQueryBuilder)
            .execute()
            .actionGet();
}
 
Example 2
Source File: Maker.java    From elasticsearch-sql with Apache License 2.0 4 votes vote down vote up
private ToXContent make(Condition cond, String name, SQLMethodInvokeExpr value) throws SqlParseException {
	ToXContent bqb = null;
	Paramer paramer = null;
	switch (value.getMethodName().toLowerCase()) {
	case "query":
		paramer = Paramer.parseParamer(value);
		QueryStringQueryBuilder queryString = QueryBuilders.queryStringQuery(paramer.value);
		bqb = Paramer.fullParamer(queryString, paramer);
		bqb = fixNot(cond, bqb);
		break;
	case "matchquery":
	case "match_query":
		paramer = Paramer.parseParamer(value);
		MatchQueryBuilder matchQuery = QueryBuilders.matchQuery(name, paramer.value);
		bqb = Paramer.fullParamer(matchQuery, paramer);
		bqb = fixNot(cond, bqb);
		break;
	case "score":
	case "scorequery":
	case "score_query":
		float boost = Float.parseFloat(value.getParameters().get(1).toString());
		Condition subCond = new Condition(cond.getConn(), cond.getName(),null, cond.getOpear(), value.getParameters().get(0),null);
           bqb = QueryBuilders.constantScoreQuery((QueryBuilder) make(subCond)).boost(boost);
		break;
	case "wildcardquery":
	case "wildcard_query":
		paramer = Paramer.parseParamer(value);
		WildcardQueryBuilder wildcardQuery = QueryBuilders.wildcardQuery(name, paramer.value);
		bqb = Paramer.fullParamer(wildcardQuery, paramer);
		break;

	case "matchphrasequery":
	case "match_phrase":
	case "matchphrase":
		paramer = Paramer.parseParamer(value);
		MatchPhraseQueryBuilder matchPhraseQuery = QueryBuilders.matchPhraseQuery(name, paramer.value);
		bqb = Paramer.fullParamer(matchPhraseQuery, paramer);
		break;

       case "multimatchquery":
       case "multi_match":
       case "multimatch":
           paramer = Paramer.parseParamer(value);
           MultiMatchQueryBuilder multiMatchQuery = QueryBuilders.multiMatchQuery(paramer.value);
           bqb = Paramer.fullParamer(multiMatchQuery, paramer);
           break;

       case "spannearquery":
       case "span_near":
       case "spannear":
           paramer = Paramer.parseParamer(value);

           // parse clauses
           List<SpanQueryBuilder> clauses = new ArrayList<>();
           try (XContentParser parser = JsonXContent.jsonXContent.createParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY, true, Collections.emptyList()).getNamedXContents()), LoggingDeprecationHandler.INSTANCE, paramer.clauses)) {
               while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
                   QueryBuilder query = SpanNearQueryBuilder.parseInnerQueryBuilder(parser);
                   if (!(query instanceof SpanQueryBuilder)) {
                       throw new ParsingException(parser.getTokenLocation(), "spanNear [clauses] must be of type span query");
                   }
                   clauses.add((SpanQueryBuilder) query);
               }
           } catch (IOException e) {
               throw new SqlParseException("could not parse clauses: " + e.getMessage());
           }

           //
           SpanNearQueryBuilder spanNearQuery = QueryBuilders.spanNearQuery(clauses.get(0), Optional.ofNullable(paramer.slop).orElse(SpanNearQueryBuilder.DEFAULT_SLOP));
           for (int i = 1; i < clauses.size(); ++i) {
               spanNearQuery.addClause(clauses.get(i));
           }

           bqb = Paramer.fullParamer(spanNearQuery, paramer);
           break;

       case "matchphraseprefix":
       case "matchphraseprefixquery":
       case "match_phrase_prefix":
           paramer = Paramer.parseParamer(value);
           MatchPhrasePrefixQueryBuilder phrasePrefixQuery = QueryBuilders.matchPhrasePrefixQuery(name, paramer.value);
           bqb = Paramer.fullParamer(phrasePrefixQuery, paramer);
           break;

	default:
		throw new SqlParseException("it did not support this query method " + value.getMethodName());

	}

	return bqb;
}
 
Example 3
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
protected MatchPhrasePrefixQueryBuilder regMatchPhrasePrefixQ(String name, Object value) {
    checkEsInvalidQuery(name, value);
    MatchPhrasePrefixQueryBuilder matchQuery = QueryBuilders.matchPhrasePrefixQuery(name, value);
    regQ(matchQuery);
    return matchQuery;
}
 
Example 4
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
protected MatchPhrasePrefixQueryBuilder regMatchPhrasePrefixQ(String name, Object value) {
    checkEsInvalidQuery(name, value);
    MatchPhrasePrefixQueryBuilder matchQuery = QueryBuilders.matchPhrasePrefixQuery(name, value);
    regQ(matchQuery);
    return matchQuery;
}
 
Example 5
Source File: EsAbstractConditionQuery.java    From fess with Apache License 2.0 4 votes vote down vote up
protected MatchPhrasePrefixQueryBuilder regMatchPhrasePrefixQ(String name, Object value) {
    checkEsInvalidQuery(name, value);
    MatchPhrasePrefixQueryBuilder matchQuery = QueryBuilders.matchPhrasePrefixQuery(name, value);
    regQ(matchQuery);
    return matchQuery;
}