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


Java Query类代码示例

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


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

示例1: search

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
@Override
public Hits search(SearchContext searchContext, Query query) throws SearchException {
    try {
        int end = searchContext.getEnd();
        int start = searchContext.getStart();
        if (isFilterSearch(searchContext)) {
            if (end > INDEX_FILTER_SEARCH_LIMIT) {
                end = end - INDEX_FILTER_SEARCH_LIMIT + 5;
            }
            if ((start < 0) || (start > end) || end < 0) {
                return new HitsImpl();
            }
        }
        query = getPermissionQuery(searchContext, query);

        return doSearch(searchContext, query, start, end);
    } catch (Exception e) {
        throw new SearchException(e);
    }
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:21,代码来源:ElasticsearchIndexSearcher.java

示例2: doSearch

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
private Hits doSearch(SearchContext searchContext, Query query, int start, int end) {
    Client client = getClient();

    SearchRequestBuilder searchRequestBuilder = prepareSearchBuilder(searchContext, query, client, start, end);
    _log.debug("Current lucene version:  " + Version.LUCENE_CURRENT);
    _log.debug("Search query String  " + searchRequestBuilder.toString());
    SearchRequest searchRequest = searchRequestBuilder.request();
    _log.debug("Time Before request to ES: " + System.currentTimeMillis());
    ActionFuture<SearchResponse> future = client.search(searchRequest);
    SearchResponse searchResponse = future.actionGet();
    _log.debug("Time After response from ES: " + System.currentTimeMillis());
    updateFacetCollectors(searchContext, searchResponse);
    Hits hits = processSearchHits(
            searchResponse, query.getQueryConfig());
    _log.debug("Total responseCount  " + searchResponse.getHits().getTotalHits());
    _log.debug("Time After processSearchHits: " + System.currentTimeMillis());

    hits.setQuery(query);

    TimeValue timeValue = searchResponse.getTook();

    hits.setSearchTime((float) timeValue.getSecondsFrac());
    return hits;
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:25,代码来源:ElasticsearchIndexSearcher.java

示例3: addHighlights

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
private void addHighlights(Query query, SearchRequestBuilder searchRequestBuilder) {
    QueryConfig queryConfig = query.getQueryConfig();
    if (queryConfig.isHighlightEnabled()) {

        String localizedContentName = DocumentImpl.getLocalizedName(
                queryConfig.getLocale(), Field.CONTENT);

        String localizedTitleName = DocumentImpl.getLocalizedName(
                queryConfig.getLocale(), Field.TITLE);

        int fragmentSize = queryConfig.getHighlightFragmentSize();
        int numberOfFragments = queryConfig.getHighlightSnippetSize();
        searchRequestBuilder.addHighlightedField(Field.CONTENT, fragmentSize, numberOfFragments);
        searchRequestBuilder.addHighlightedField(Field.TITLE, fragmentSize, numberOfFragments);
        searchRequestBuilder.addHighlightedField(localizedContentName, fragmentSize, numberOfFragments);
        searchRequestBuilder.addHighlightedField(localizedTitleName, fragmentSize, numberOfFragments);

    }
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:20,代码来源:ElasticsearchIndexSearcher.java

示例4: execute

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
/**
 * Execute search.
 * 
 * @param searchContext
 * @param query
 * @return Hits
 * @throws Exception
 */
@SuppressWarnings("unchecked")
protected Hits execute(SearchContext searchContext, Query query)
	throws Exception {

	if (_log.isDebugEnabled()) {
		_log.debug("Executing search with query: " + query.toString());
	}
	
	BooleanClause<?> booleanClause = BooleanClauseFactoryUtil.create(
		query, BooleanClauseOccur.MUST.getName());
	
	searchContext.setBooleanClauses(new BooleanClause[] {
		booleanClause
	});

	Hits hits = _indexSearcherHelper.search(searchContext, query);

	if (_log.isDebugEnabled()) {
		_log.debug("Query: " + hits.getQuery());
		_log.debug("Hits: " + hits.getLength());
		_log.debug("Returned: " + hits.getDocs().length);
		_log.debug("Time:" + hits.getSearchTime());
		_log.debug(
			"Suggestions size: " + hits.getQuerySuggestions().length);
	}
	return hits;
}
 
开发者ID:peerkar,项目名称:liferay-gsearch,代码行数:36,代码来源:GSearchImpl.java

示例5: search

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
@Override
public Hits search(SearchContext searchContext, Query query) throws SearchException {
	if (_log.isInfoEnabled()) {
		_log.info("Search against elasticsearch indexes");
	}

	return _esSearchHelper.getSearchHits(searchContext, query);
}
 
开发者ID:rivetlogic,项目名称:liferay-elasticsearch-integration,代码行数:9,代码来源:ElasticsearchIndexSearcherImpl.java

示例6: getSearchHits

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
/**
   * Gets the search hits.
   *
   * @param searchEngineId the search engine id
   * @param companyId the company id
   * @param query the query
   * @param sort the sort
   * @param start the start
   * @param end the end
   * @return the search hits
   */
  public Hits getSearchHits(String searchEngineId, long companyId, Query query, Sort[] sort, int start, int end) {
      if (_log.isInfoEnabled()) {
          _log.info("Search against Elasticsearch with searchEngineId, companyId, query, sort, start and end parameters");
      }
      Hits hits = new HitsImpl();
      Client client = this._esConnector.getClient();

SearchRequestBuilder searchRequestBuilder = client
		.prepareSearch(
				ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX)
		.setQuery(_esQueryBuilder.doSearch(query));
SearchResponse response = null;
if (getSort(sort) != null) {
	response = searchRequestBuilder.setFrom(start)
								  .setSize(end)
								  .addSort(getSort(sort))
								  .execute().actionGet();
} else {
	response = searchRequestBuilder.setFrom(start)
			  .setSize(end)
			  .execute().actionGet();
}
      SearchHits searchHits = response.getHits();
      hits.setDocs(getDocuments(searchHits));     
      hits.setScores(getScores(searchHits));
      hits.setSearchTime(
              (float)(System.currentTimeMillis() - hits.getStart()) /
                  Time.SECOND);
      hits.setQuery(query);
      hits.setLength((int)searchHits.getTotalHits());
      hits.setStart(hits.getStart());
      
      return hits;
  }
 
开发者ID:rivetlogic,项目名称:liferay-elasticsearch-integration,代码行数:46,代码来源:ElasticsearchHelper.java

示例7: translate

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
public static QueryBuilder translate(Query query) {
    if (query instanceof QueryImpl) {
        return (QueryBuilder) query.getWrappedQuery();
    } else {
        return null;
    }
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:8,代码来源:QueryTranslatorUtil.java

示例8: create

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
@Override
public BooleanClause create(SearchContext searchContext, String field, String value, String occur) {
    String searchEngineId = searchContext.getSearchEngineId();
    SearchEngine searchEngine = SearchEngineUtil.getSearchEngine(searchEngineId);
    TermQueryFactory termQueryFactory = searchEngine.getTermQueryFactory();
    Query query = termQueryFactory.create(field, value);
    BooleanClauseOccur booleanClauseOccur = new BooleanClauseOccurImpl(occur);
    return new BooleanClauseImpl(query, booleanClauseOccur);
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:10,代码来源:BooleanClauseFactoryImpl.java

示例9: add

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
@Override
public void add(Query query, String occur) throws ParseException {
    if (occur.equals(BooleanClauseOccur.MUST.getName())) {
        _boolQueryBuilder = _boolQueryBuilder.must(QueryTranslatorUtil.translate(query));
    } else if (occur.equals(BooleanClauseOccur.MUST_NOT.getName())) {
        _boolQueryBuilder = _boolQueryBuilder.mustNot(QueryTranslatorUtil.translate(query));
    } else if (occur.equals(BooleanClauseOccur.SHOULD.getName())) {
        _boolQueryBuilder = _boolQueryBuilder.should(QueryTranslatorUtil.translate(query));
    }
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:11,代码来源:BooleanQueryImpl.java

示例10: getPermissionQuery

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
private Query getPermissionQuery(SearchContext searchContext, Query query) {
    if (searchContext.getEntryClassNames() == null) {
        return query;
    }
    for (String className : searchContext.getEntryClassNames()) {
        Indexer indexer = IndexerRegistryUtil.getIndexer(className);
        if (indexer != null) {
            if (indexer.isFilterSearch() && indexer.isPermissionAware()) {
                SearchPermissionChecker searchPermissionChecker = SearchEngineUtil.getSearchPermissionChecker();
                query = searchPermissionChecker.getPermissionQuery(searchContext.getCompanyId(), searchContext.getGroupIds(), searchContext.getUserId(), className, query, searchContext);
            }
        }
    }
    return query;
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:16,代码来源:ElasticsearchIndexSearcher.java

示例11: prepareSearchBuilder

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
private SearchRequestBuilder prepareSearchBuilder(SearchContext searchContext, Query query, Client client, int start, int end) {
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(Utilities.getIndexName(searchContext));
    addHighlights(query, searchRequestBuilder);
    //QueryBuilder queryBuilder = com.rknowsys.portal.search.elastic.liferay.QueryTranslatorUtil.translate(query);

    //if (queryBuilder == null) {
        String q=applyCustomESRules(query.toString());
        QueryBuilder queryBuilder = QueryBuilders.queryStringQuery(q);
    //}

    searchRequestBuilder.setQuery(queryBuilder);

    _log.debug("Query String" + queryBuilder.toString());

    searchRequestBuilder.setTypes("documents");

    addFacetCollectorsToSearch(searchContext, searchRequestBuilder);

    addSortToSearch(searchContext.getSorts(), searchRequestBuilder);


    int size = end - start;

    _log.debug("Search Start:  " + start + " Search Size: " + size);
    if((start != QueryUtil.ALL_POS) && (end != QueryUtil.ALL_POS))
    {
      searchRequestBuilder.setFrom(start).setSize(size);
    }
    return searchRequestBuilder;
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:31,代码来源:ElasticsearchIndexSearcher.java

示例12: constructQuery

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
/**
 * Construct query.
 * 
 * Please note that QueryStringQuery type is an
 * extension of Liferay StringQuery. Thus, if you don't want to use
 * the custom search adapter, this falls silently to the default StringQuery.
 * Remember however that with standard adapter you loose the possibility to
 * define target fields or boosts (configuration) - or, they just don't get applied.
 * 
 * @param portletRequest
 * @param queryParams
 * @return
 * @throws Exception
 */
protected BooleanQuery constructQuery(PortletRequest portletRequest, QueryParams queryParams) throws Exception {
	
	BooleanQuery query = new BooleanQueryImpl();
	
	// Build query
	
	JSONArray configurationArray = JSONFactoryUtil.createJSONArray(
		_gSearchConfiguration.searchFieldConfiguration());
	
	Query subQuery;

	for (int i = 0; i < configurationArray.length(); i++) {
		
		JSONObject queryItem = configurationArray.getJSONObject(i);

		subQuery =  null;

		String queryType = queryItem.getString("queryType");
		String occurString = queryItem.getString("queryType");

		BooleanClauseOccur occur;
		if ("MUST".equals(occurString)) {
			occur = BooleanClauseOccur.MUST;
		} else if ("MUST_NOT".equals(occurString)) {
			occur = BooleanClauseOccur.MUST_NOT;
		} else {
			occur = BooleanClauseOccur.SHOULD;
		}
 		
		if ("match".equals(queryType)) {

			boolean isLocalized = queryItem.getBoolean("localized");

			if (isLocalized) {
				subQuery = _matchQueryBuilder.buildLocalizedQuery(queryItem, queryParams);
			} else {
				subQuery =  _matchQueryBuilder.buildQuery(queryItem, queryParams);
			}
		} else if ("wildcard".equals(queryType)) {
			
			String keywordSplitter = queryItem.getString("keywordSplitter");

			if (keywordSplitter != null && keywordSplitter.length() > 0) {

				subQuery = _wildcardQueryBuilder.buildSplittedQuery(queryItem, queryParams);
			} else {
				
				subQuery = _wildcardQueryBuilder.buildQuery(queryItem, queryParams);
			}
			
		} else if ("query_string".equals(queryType)) {
			subQuery = (QueryStringQuery)_queryStringQueryBuilder.buildQuery(queryItem, queryParams);
		}
		
		if (subQuery != null) {
			query.add(subQuery,occur);
		}
	}
	return query;
}
 
开发者ID:peerkar,项目名称:liferay-gsearch,代码行数:75,代码来源:QueryBuilderImpl.java

示例13: BooleanClauseImpl

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
public BooleanClauseImpl(Query query, BooleanClauseOccur booleanClauseOccur) {
    _query = query;
    _booleanClauseOccur = booleanClauseOccur;
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:5,代码来源:BooleanClauseImpl.java

示例14: getQuery

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
@Override
public Query getQuery() {
    return _query;
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:5,代码来源:BooleanClauseImpl.java

示例15: getResults

import com.liferay.portal.kernel.search.Query; //导入依赖的package包/类
/**
 * Get results object.
 * 
 * @return results as a JSON object
 * @throws Exception
 */
protected JSONObject getResults()
	throws Exception {

	Query query = _queryBuilder.buildQuery(_portletRequest, _queryParams);

	// Create SearchContext.

	SearchContext searchContext = getSearchContext();

	// Execute search.

	Hits hits = execute(searchContext, query);
	
	// Process query indexing.
	
	_queryIndexerProcessor.process(searchContext, _queryParams, hits);

	// Process query suggestions and alternative search.
	
	_querySuggestionsProcessor.process(_portletRequest, searchContext, _queryParams, hits);

	// Build results JSON object.

	JSONObject resultsObject = _resultsBuilder.buildResults(
		_portletRequest, _portletResponse, _queryParams, searchContext, hits);

	return resultsObject;
}
 
开发者ID:peerkar,项目名称:liferay-gsearch,代码行数:35,代码来源:GSearchImpl.java


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