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


Java TermQuery类代码示例

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


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

示例1: buildGroupsCondition

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
/**
 * Add groups condition.
 * 
 * @throws ParseException
 */
protected void buildGroupsCondition()
	throws ParseException {

	long[] groupIds = _queryParams.getGroupIds();

	if (groupIds.length > 0) {

		BooleanQueryImpl query = new BooleanQueryImpl();

		for (long l : groupIds) {
			TermQuery condition = new TermQueryImpl(Field.SCOPE_GROUP_ID, String.valueOf(l)); 
			query.add(condition, BooleanClauseOccur.SHOULD);
		}
		addAsQueryFilter(query);
	}
}
 
开发者ID:peerkar,项目名称:liferay-gsearch,代码行数:22,代码来源:QueryFilterBuilderImpl.java

示例2: addDLFileEntryClassCondition

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
/**
 * Add DLFileEntry class condition
 * 
 * @param query
 * @param dedicatedTypeQuery
 * @throws ParseException
 */
protected void addDLFileEntryClassCondition(BooleanQuery query, boolean dedicatedTypeQuery) throws ParseException {

	TermQuery condition = new TermQueryImpl(Field.ENTRY_CLASS_NAME, DLFileEntry.class.getName()); 
	query.add(condition, BooleanClauseOccur.SHOULD);

	// Format and type conditions (apply only when this is a single type filtered query)

	if (dedicatedTypeQuery) {
	
		buildDocumentFormatCondition();
		buildDocumentTypeCondition();
	}
}
 
开发者ID:peerkar,项目名称:liferay-gsearch,代码行数:21,代码来源:QueryFilterBuilderImpl.java

示例3: buildClassesCondition

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
/**
 * Add classes condition.
 * 
 * @throws ParseException
 */
protected void buildClassesCondition()
	throws ParseException {

	List<String> classNames = _queryParams.getClassNames();

	BooleanQuery query = new BooleanQueryImpl();

	// Is this a single asset type targeted query
	
	boolean dedicatedTypeQuery = classNames.size() == 1;
	
	for (String className : classNames) {

		// Handle journal article and DLFileEntry separately.

		if (className.equals(JournalArticle.class.getName())) {
			addJournalArticleClassCondition(query, dedicatedTypeQuery);
		}
		else if (className.equals(DLFileEntry.class.getName())) {
			addDLFileEntryClassCondition(query, dedicatedTypeQuery);
		}
		else {
			
			TermQuery condition = new TermQueryImpl(Field.ENTRY_CLASS_NAME, className); 
			query.add(condition, BooleanClauseOccur.SHOULD);
		}
	}
	addAsQueryFilter(query);
}
 
开发者ID:peerkar,项目名称:liferay-gsearch,代码行数:35,代码来源:QueryFilterBuilderImpl.java

示例4: buildCTQuery

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
@Override
public BooleanQuery buildCTQuery(
	PortletRequest portletRequest)
	throws Exception {

	if (portletRequest.getAttribute("userSegmentIds") == null) {
		return null;
	}
	
	long[] userSegmentIds = (long[])portletRequest.getAttribute("userSegmentIds");

	if (_log.isDebugEnabled()) {
		_log.debug("Found " + userSegmentIds.length + " user segments.");
	}

	BooleanQuery query = new BooleanQueryImpl();
	
	for (int i = 0; i < userSegmentIds.length; i++) {

		long ctCategoryId = _userSegmentLocalService.getUserSegment(userSegmentIds[i]).getAssetCategoryId();

		TermQuery condition = new TermQueryImpl(Field.ASSET_CATEGORY_IDS, String.valueOf(ctCategoryId)); 
		query.add(condition, BooleanClauseOccur.SHOULD);
	}
			
	query.setBoost(_gSearchConfiguration.audienceTargetingBoost());

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

示例5: createBooleanQueries

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
public static List<BooleanQuery> createBooleanQueries(
			List<String> subQueries, List<Object> params,
			List<String> paramNames, SearchContext searchContext)
			throws ParseException {
		List<BooleanQuery> booleanQueries = new ArrayList<BooleanQuery>();
		if (subQueries != null) {
			for (String subQuery : subQueries) {
				String[] terms = StringUtil.split(subQuery);
				if (terms != null && terms.length > 0) {
					BooleanQuery query = BooleanQueryFactoryUtil
							.create(searchContext);
					for (int t = 0; t < terms.length; t++) {
						int paramPossition = subQueries.indexOf(subQuery)
								* terms.length + t;
						// String term = terms[t].trim().toLowerCase();
						String term = terms[t].trim();
						String key = StringPool.BLANK;
						if (term.contains((StringPool.EQUAL.toLowerCase()))) {
							key = term
									.substring(
											0,
											term.indexOf(StringPool.EQUAL
													.toLowerCase())).trim();
							// addExactTerm(query, key,
							// params.get(paramPossition));

							TermQuery termQuery = null;

							Object tempValue = params.get(paramPossition);

							if (tempValue instanceof Long) {
								termQuery = TermQueryFactoryUtil.create(
										searchContext, key, (long) tempValue);
							} else {
								termQuery = TermQueryFactoryUtil.create(
										searchContext, key,
										String.valueOf(tempValue));
							}

							if (termQuery != null) {
								query.add(termQuery, BooleanClauseOccur.MUST);
							}
						} else if (term.contains(StringPool.LIKE.toLowerCase())) {
							key = term
									.substring(
											0,
											term.indexOf(StringPool.LIKE
													.toLowerCase())).trim();

							query.addTerm(key, params.get(paramPossition)
									.toString(), true);

						} else if (term.contains(StringPool.BETWEEN
								.toLowerCase())) {
							key = term.substring(
									0,
									term.indexOf(StringPool.BETWEEN
											.toLowerCase())).trim();
//							query = addRangeTerm(query, key,
//									params.get(paramPossition));
						}

						if (Validator.isNotNull(key)) {
							paramNames.add(key);
						}

					}

					booleanQueries.add(query);
				}
			}
		}
		return booleanQueries;
	}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:75,代码来源:DeliverableLocalServiceImpl.java

示例6: buildQuerySearch

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
/**
 * @param pattern
 * @param params
 * @param searchContext
 * @return
 */

public static BooleanQuery buildQuerySearch(String pattern,
		List<Object> params, SearchContext searchContext) {
	searchContext
			.setEntryClassNames(new String[] { Dossier.class.getName() });

	Indexer indexer = IndexerRegistryUtil.getIndexer(Dossier.class
			.getName());

	searchContext.setSearchEngineId(indexer.getSearchEngineId());

	BooleanQuery query = BooleanQueryFactoryUtil.create(searchContext);
	List<String> subQueries = new ArrayList<String>();
	try {
		pattern = validPattern(pattern);

		if (Validator.isNull(pattern)) {
			throw new Exception();
		}
		getSubQueries(pattern, subQueries);

		if (subQueries != null && !subQueries.isEmpty()) {
			List<BooleanQuery> booleanQueries = createBooleanQueries(
					subQueries, params, searchContext);

			List<BooleanClauseOccur> conditions = getBooleanClauseOccurs(
					pattern, subQueries);

			if (booleanQueries.size() - 1 != conditions.size()) {
				throw new Exception();
			}
			int count = 0;
			for (BooleanQuery booleanQuery : booleanQueries) {
				if (count == 0) {
					query.add(booleanQuery, BooleanClauseOccur.MUST);
				} else {
					query.add(booleanQuery, conditions.get(count - 1));
				}

				count++;
			}
		}

		TermQuery entryClassNameTerm = TermQueryFactoryUtil.create(
				searchContext, "entryClassName", Dossier.class.getName());

		query.add(entryClassNameTerm, BooleanClauseOccur.MUST);

	} catch (Exception e) {
		_log.error(e);
	}

	return query;
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:61,代码来源:LuceneQueryUtil.java

示例7: createBooleanQueries

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
/**
 * @param subQueries
 * @param params
 * @param searchContext
 * @return
 * @throws ParseException
 */
public static List<BooleanQuery> createBooleanQueries(
		List<String> subQueries, List<Object> params,
		SearchContext searchContext) throws ParseException {
	List<BooleanQuery> booleanQueries = new ArrayList<BooleanQuery>();
	if (subQueries != null) {
		for (String subQuery : subQueries) {
			String[] terms = StringUtil.split(subQuery);
			if (terms != null && terms.length > 0) {
				BooleanQuery query = BooleanQueryFactoryUtil
						.create(searchContext);
				for (int t = 0; t < terms.length; t++) {
					int paramPossition = subQueries.indexOf(subQuery)
							* terms.length + t;
					// String term = terms[t].trim().toLowerCase();
					String term = terms[t].trim();
					String key = StringPool.BLANK;
					if (term.contains((StringPool.EQUAL.toLowerCase()))) {
						key = term
								.substring(
										0,
										term.indexOf(StringPool.EQUAL
												.toLowerCase())).trim();
						// addExactTerm(query, key,
						// params.get(paramPossition));
						TermQuery termQuery = null;

						Object tempValue = params.get(paramPossition);

						if (tempValue instanceof Long) {
							termQuery = TermQueryFactoryUtil.create(
									searchContext, key, (long) tempValue);
						} else if (tempValue instanceof String) {
							termQuery = TermQueryFactoryUtil.create(
									searchContext, key,
									String.valueOf(tempValue));
						}

						if (termQuery != null) {
							query.add(termQuery, BooleanClauseOccur.MUST);
						}

					} else if (term.contains(StringPool.LIKE.toLowerCase())) {
						key = term
								.substring(
										0,
										term.indexOf(StringPool.LIKE
												.toLowerCase())).trim();

						query.addTerm(key, params.get(paramPossition)
								.toString(), true);

					} else if (term.contains(StringPool.BETWEEN
							.toLowerCase())) {
						key = term.substring(
								0,
								term.indexOf(StringPool.BETWEEN
										.toLowerCase())).trim();
						query = addRangeTerm(query, key,
								params.get(paramPossition));
					}

				}

				booleanQueries.add(query);
			}
		}
	}
	return booleanQueries;
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:77,代码来源:LuceneQueryUtil.java

示例8: buildFacetConditions

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
protected void buildFacetConditions() {
	Map<String, String[]> facetParams = _queryParams.getFacets();

	if (facetParams == null) {
		return;
	}

	BooleanQueryImpl facetQuery = new BooleanQueryImpl();

	for (Entry<String, String[]>entry : facetParams.entrySet()) {

		BooleanQueryImpl query = new BooleanQueryImpl();

		for (String value : entry.getValue()) {
			
			TermQuery condition = new TermQueryImpl(entry.getKey(), value); 
			query.add(condition, BooleanClauseOccur.SHOULD);
			
		}
		
		facetQuery.add(query, BooleanClauseOccur.MUST);
	}
	addAsQueryFilter(facetQuery);
}
 
开发者ID:peerkar,项目名称:liferay-gsearch,代码行数:25,代码来源:QueryFilterBuilderImpl.java

示例9: create

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
@Override
public TermQuery create(String field, long value) {
    return new TermQueryImpl(field, value);
}
 
开发者ID:R-Knowsys,项目名称:elasticray,代码行数:5,代码来源:TermQueryFactoryImpl.java

示例10: addJournalArticleClassCondition

import com.liferay.portal.kernel.search.TermQuery; //导入依赖的package包/类
/**
 * Add journal article class condition.
 * 
 * @param query
 * @throws ParseException
 */
protected void addJournalArticleClassCondition(BooleanQuery query, boolean dedicatedTypeQuery) throws ParseException {
	
	BooleanQuery journalArticleQuery = new BooleanQueryImpl();

	// Classname condition.
	
	TermQuery classNamecondition = new TermQueryImpl(Field.ENTRY_CLASS_NAME, JournalArticle.class.getName()); 
	journalArticleQuery.add(classNamecondition, BooleanClauseOccur.MUST);

	// Add display date limitation.

	Date now = new Date();

	journalArticleQuery.addRangeTerm(
		"displayDate_sortable", Long.MIN_VALUE, now.getTime());

	journalArticleQuery.addRangeTerm(
		"expirationDate_sortable", now.getTime(), Long.MAX_VALUE);

	// Add version limitation.
	
	TermQuery versionQuery = new TermQueryImpl("head", Boolean.TRUE.toString());
	journalArticleQuery.add(versionQuery, BooleanClauseOccur.MUST);
	
	query.add(journalArticleQuery, BooleanClauseOccur.SHOULD);		
	
	// Structure condition (apply only when this is a single type filtered query)

	if (dedicatedTypeQuery) {
		buildWebContentStructureCondition();
	}
}
 
开发者ID:peerkar,项目名称:liferay-gsearch,代码行数:39,代码来源:QueryFilterBuilderImpl.java


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