當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryStringQueryBuilder類代碼示例

本文整理匯總了Java中org.elasticsearch.index.query.QueryStringQueryBuilder的典型用法代碼示例。如果您正苦於以下問題:Java QueryStringQueryBuilder類的具體用法?Java QueryStringQueryBuilder怎麽用?Java QueryStringQueryBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


QueryStringQueryBuilder類屬於org.elasticsearch.index.query包,在下文中一共展示了QueryStringQueryBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: urlParamsToQueryBuilder

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
public static QueryBuilder urlParamsToQueryBuilder(RestRequest request) {
    String queryString = request.param("q");
    if (queryString == null) {
        return null;
    }
    QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
    queryBuilder.defaultField(request.param("df"));
    queryBuilder.analyzer(request.param("analyzer"));
    queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
    queryBuilder.lenient(request.paramAsBoolean("lenient", null));
    String defaultOperator = request.param("default_operator");
    if (defaultOperator != null) {
        queryBuilder.defaultOperator(Operator.fromString(defaultOperator));
    }
    return queryBuilder;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:RestActions.java

示例2: getTopicByCateAndUser

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
@Override
public FacetedPage<Topic> getTopicByCateAndUser(String cate  , String q , String user ,final int p , final int ps) {

	FacetedPage<Topic> pages  = null ;
	NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(termQuery("cate" , cate)).withQuery(termQuery("creater" , user)).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC));
	
	if(!StringUtils.isBlank(q)){
	   	searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
	}
	SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps));
	if(elasticsearchTemplate.indexExists(Topic.class)){
    	
		if(!StringUtils.isBlank(q)){
    		pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class, new UKResultMapper());
    	}else{
    		pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class);
    	}
    }
    return pages ; 
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:21,代碼來源:TopicRepositoryImpl.java

示例3: elasticSearch

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
private static void elasticSearch(JestClient client, String indexName, String type, String query) {
	SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
	QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryStringQuery(query);
	searchSourceBuilder.query(queryStringQueryBuilder);
	Search searchElastic = (Search) new Search.Builder(searchSourceBuilder.toString())
			// multiple index or types can be added.
			.addIndex(indexName).addType(type).build();

	try {
		SearchResult elasticRs = client.execute(searchElastic);

		List<Hit<Article, Void>> hits = elasticRs.getHits(Article.class);
		for (Hit<Article, Void> hit : hits) {
			Article talk = hit.source;
			System.out.println("Elastic hits: " + talk.toString());
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:conorheffron,項目名稱:elastic-tester,代碼行數:21,代碼來源:ElasticApp.java

示例4: parseQuerySource

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
public static QuerySourceBuilder parseQuerySource(RestRequest request) {
    String queryString = request.param("q");
    if (queryString == null) {
        return null;
    }
    QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(queryString);
    queryBuilder.defaultField(request.param("df"));
    queryBuilder.analyzer(request.param("analyzer"));
    queryBuilder.analyzeWildcard(request.paramAsBoolean("analyze_wildcard", false));
    queryBuilder.lowercaseExpandedTerms(request.paramAsBoolean("lowercase_expanded_terms", true));
    queryBuilder.lenient(request.paramAsBoolean("lenient", null));
    String defaultOperator = request.param("default_operator");
    if (defaultOperator != null) {
        if ("OR".equals(defaultOperator)) {
            queryBuilder.defaultOperator(QueryStringQueryBuilder.Operator.OR);
        } else if ("AND".equals(defaultOperator)) {
            queryBuilder.defaultOperator(QueryStringQueryBuilder.Operator.AND);
        } else {
            throw new IllegalArgumentException("Unsupported defaultOperator [" + defaultOperator + "], can either be [OR] or [AND]");
        }
    }
    return new QuerySourceBuilder().setQuery(queryBuilder);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:24,代碼來源:RestActions.java

示例5: findByCon

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public FacetedPage<Serializable> findByCon(Class clazz,NativeSearchQueryBuilder searchQueryBuilder,  String q , final int p , final int ps) {
	FacetedPage<Serializable> pages  = null ;
	if(!StringUtils.isBlank(q)){
	   	searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
	}
   	SearchQuery searchQuery = searchQueryBuilder.build();
    if(elasticsearchTemplate.indexExists(clazz)){
    	if(!StringUtils.isBlank(q)){
    		pages = elasticsearchTemplate.queryForPage(searchQuery, clazz, new UKResultMapper());
    	}else{
    		pages = elasticsearchTemplate.queryForPage(searchQuery, clazz , new UKAggTopResultExtractor("userid" , "top"));
    	}
    }
    return pages ; 
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:18,代碼來源:UKeFuRepositoryImpl.java

示例6: findByCon

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
@Override
public FacetedPage<Topic> findByCon(NativeSearchQueryBuilder searchQueryBuilder,  String q , final int p , final int ps) {
	FacetedPage<Topic> pages  = null ;
	if(!StringUtils.isBlank(q)){
	   	searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
	}
   	SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps));
    if(elasticsearchTemplate.indexExists(Topic.class)){
    	if(!StringUtils.isBlank(q)){
    		pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class  , new UKResultMapper());
    	}else{
    		pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class);
    	}
    }
    return pages ; 
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:17,代碼來源:TopicRepositoryImpl.java

示例7: doQueryString

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
/**
 * query_string-分詞搜索
 * 
 * @param boolQ
 * @param conditions
 * @param conditionType
 */
private void doQueryString(BoolQueryBuilder boolQ, List<Condition> conditions,
        ConditionType conditionType) {
    // 構造查詢語法串
    StringBuilder build = new StringBuilder();
    String filed;
    List<String> words;
    for (Condition condition : conditions) {
        filed = condition.getFiled();
        filed = StringUtils.isBlank(filed) ? "_all" : filed;
        words = KeyWordUtil.processKeyWord(condition.getValue());
        for (String word : words) {
            build.append("(").append(filed).append(":").append(word).append(") ")
                    .append(conditionType.name());
        }
    }
    if (build.length() < 1) {
        return;
    }
    String querystring = build.substring(0, build.lastIndexOf(conditionType.name()));
    QueryStringQueryBuilder queryString = QueryBuilders.queryString(querystring)
            .defaultOperator(default_operator);
    mergeBuilder(boolQ, queryString, conditionType);
}
 
開發者ID:hailin0,項目名稱:es-service-parent,代碼行數:31,代碼來源:EsQueryBuilder.java

示例8: search

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
@Override
public SearchResponse search(SearchRequest searchRequest) throws InvalidSearchException {
  // Wrap the query to also get any meta-alerts.
  QueryBuilder qb = constantScoreQuery(boolQuery()
      .must(boolQuery()
          .should(new QueryStringQueryBuilder(searchRequest.getQuery()))
          .should(nestedQuery(
              ALERT_FIELD,
              new QueryStringQueryBuilder(searchRequest.getQuery()),
              ScoreMode.None
              )
          )
      )
      // Ensures that it's a meta alert with active status or that it's an alert (signified by
      // having no status field)
      .must(boolQuery()
          .should(termQuery(MetaAlertDao.STATUS_FIELD, MetaAlertStatus.ACTIVE.getStatusString()))
          .should(boolQuery().mustNot(existsQuery(MetaAlertDao.STATUS_FIELD)))
      )
      .mustNot(existsQuery(MetaAlertDao.METAALERT_FIELD))
  );
  return elasticsearchDao.search(searchRequest, qb);
}
 
開發者ID:apache,項目名稱:metron,代碼行數:24,代碼來源:ElasticsearchMetaAlertDao.java

示例9: handleFulltextSearchSettings

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
/**
 * @param querySettings
 * @return builder for query, newer null
 */
protected QueryBuilder handleFulltextSearchSettings(QuerySettings querySettings) {
	if (querySettings.getQuery() != null) {
		QueryStringQueryBuilder qb = QueryBuilders.queryString(querySettings.getQuery());
		Map<String, Object> fields = configService.get(ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS);
		if (fields != null) {
			for (String fieldName : fields.keySet()) {
				String value = (String) fields.get(fieldName);
				if (value != null && !value.trim().isEmpty()) {
					try {
						qb.field(fieldName, Float.parseFloat(value));
					} catch (NumberFormatException e) {
						log.warning("Boost value has not valid float format for fulltext field " + fieldName
								+ " in DCP configuration document " + ConfigService.CFGNAME_SEARCH_FULLTEXT_QUERY_FIELDS);
						qb.field(fieldName);
					}
				} else {
					qb.field(fieldName);
				}
			}
		}
		return qb;
	} else {
		return QueryBuilders.matchAllQuery();
	}
}
 
開發者ID:macanhhuy,項目名稱:dcp-api,代碼行數:30,代碼來源:SearchService.java

示例10: addQuery

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
private void addQuery(BoolQueryBuilder boolQuery, boolean positive, String query, String modifier) {
    if (Strings.isNullOrEmpty(query)) {
        return;
    }
    QueryStringQueryBuilder builder = QueryBuilders.queryStringQuery(query)
            .field("title." + modifier)
            .field("text." + modifier)
            .defaultOperator(Operator.AND);
    if (positive) {
        boolQuery.must(builder);
    } else {
        boolQuery.mustNot(builder);
    }
}
 
開發者ID:tokenmill,項目名稱:crawling-framework,代碼行數:15,代碼來源:EsDocumentOperations.java

示例11: findByCon

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
@Override
public FacetedPage<TopicComment> findByCon(NativeSearchQueryBuilder searchQueryBuilder , String field , String aggname,  String q , final int p , final int ps) {
	FacetedPage<TopicComment> pages  = null ;
	if(!StringUtils.isBlank(q)){
	   	searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
	}
   	SearchQuery searchQuery = searchQueryBuilder.build();
    if(elasticsearchTemplate.indexExists(TopicComment.class)){
    	if(!StringUtils.isBlank(q)){
    		pages = elasticsearchTemplate.queryForPage(searchQuery, TopicComment.class  , new UKResultMapper());
    	}else{
    		pages = elasticsearchTemplate.queryForPage(searchQuery, TopicComment.class , new UKAggTopResultExtractor(field , aggname));
    	}
    }
    return pages ; 
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:17,代碼來源:TopicCommentRepositoryImpl.java

示例12: getTopicByCate

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
@Override
public FacetedPage<Topic> getTopicByCate(String cate , String q, final int p , final int ps) {

	FacetedPage<Topic> pages  = null ;
	NativeSearchQueryBuilder searchQueryBuilder = new NativeSearchQueryBuilder().withQuery(termQuery("cate" , cate)).withSort(new FieldSortBuilder("top").unmappedType("boolean").order(SortOrder.DESC)).withSort(new FieldSortBuilder("updatetime").unmappedType("date").order(SortOrder.DESC));
    if(!StringUtils.isBlank(q)){
    	searchQueryBuilder.withQuery(new QueryStringQueryBuilder(q).defaultOperator(Operator.AND)) ;
    }
    searchQueryBuilder.withHighlightFields(new HighlightBuilder.Field("title").fragmentSize(200)) ;
    SearchQuery searchQuery = searchQueryBuilder.build().setPageable(new PageRequest(p, ps)) ;
    if(elasticsearchTemplate.indexExists(Topic.class)){
    	if(!StringUtils.isBlank(q)){
    		pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class , new UKResultMapper());
    	}else{
    		pages = elasticsearchTemplate.queryForPage(searchQuery, Topic.class);
    	}
    }
    return pages ; 
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:20,代碼來源:TopicRepositoryImpl.java

示例13: fullParamer

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
public static ToXContent fullParamer(QueryStringQueryBuilder query, Paramer paramer) {
    if (paramer.analysis != null) {
        query.analyzer(paramer.analysis);
    }

    if (paramer.boost != null) {
        query.boost(paramer.boost);
    }
    return query;
}
 
開發者ID:mazhou,項目名稱:es-sql,代碼行數:11,代碼來源:Paramer.java

示例14: queryBuilder

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
/**
     * construct the only query used by all
     *
     * @param query
     * @return
     */
    private static QueryBuilder queryBuilder(String query) {


        //return QueryBuilders.queryStringQuery(query).defaultOperator(QueryStringQueryBuilder.Operator.AND);

        if (StringUtils.isEmpty(query)) {
            return QueryBuilders.matchAllQuery();
        }

//        return QueryBuilders.multiMatchQuery(query)
//            .operator(MatchQueryBuilder.Operator.AND)
//            .field("name^3")
//            .field("content").field("path").field("version").field("project")
//            ;

        return QueryBuilders.queryStringQuery(query)
            .allowLeadingWildcard(true)
            .defaultOperator(QueryStringQueryBuilder.Operator.AND)
            .field("name^3")
            .field("content").field("path").field("version").field("project").field("extension")

            ;

        //QueryBuilders.queryStringQuery(query)
        //.defaultOperator(QueryStringQueryBuilder.Operator.AND)
        //TODO : attention, si on souhaite que la recherche s'effectue bien sur l'ensemble des champs
        //il faut veuillez à ce qu'il soit tous présent ici
        //en cas d'ajout, penser à les ajouter ici
        //.field("content")



      /*  return QueryBuilders.boolQuery()
            .should(QueryBuilders.termQuery("content", query))
            .should(
                QueryBuilders.queryStringQuery(query)
                    .defaultOperator(QueryStringQueryBuilder.Operator.AND)
            );*/
    }
 
開發者ID:klask-io,項目名稱:klask-io,代碼行數:46,代碼來源:Queries.java

示例15: getTaskLogs

import org.elasticsearch.index.query.QueryStringQueryBuilder; //導入依賴的package包/類
@Override
public List<TaskExecLog> getTaskLogs(String taskId) {
	try {

		QueryBuilder qf = QueryBuilders.matchAllQuery();
		Expression expression = Expression.fromString("taskId='" + taskId + "'");
		qf = expression.getFilterBuilder();

		BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(qf);
		QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery("*");
		BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);

		final SearchRequestBuilder srb = client.prepareSearch(indexName).setQuery(fq).setTypes(TASK_DOC_TYPE);
		SearchResponse response = srb.execute().actionGet();
		SearchHit[] hits = response.getHits().getHits();
		List<TaskExecLog> logs = new ArrayList<>(hits.length);
		for(SearchHit hit : hits) {
			String source = hit.getSourceAsString();
			TaskExecLog tel = om.readValue(source, TaskExecLog.class);			
			logs.add(tel);
		}

		return logs;

	}catch(Exception e) {
		log.error(e.getMessage(), e);
	}

	return null;
}
 
開發者ID:Netflix,項目名稱:conductor,代碼行數:31,代碼來源:ElasticSearchDAO.java


注:本文中的org.elasticsearch.index.query.QueryStringQueryBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。