@Override protected void indexKeyword( SearchContext searchContext, long groupId, String languageId, String keyword, float weight, String keywordFieldName, String typeFieldValue, int maxNGramLength) throws Exception { Document document = createDocument( searchContext.getCompanyId(), groupId, languageId, keyword, weight, keywordFieldName, typeFieldValue, maxNGramLength); addDocument(typeFieldValue, searchContext, document); }
searchContext.getCompanyId(), groupId, languageId, dictionaryEntry.getWord(), dictionaryEntry.getWeight(), keywordFieldName, typeFieldValue, maxNGramLength);
private BooleanFilter _getFacetBooleanFilter( String className, SearchContext searchContext) throws Exception { BooleanFilter facetBooleanFilter = new BooleanFilter(); facetBooleanFilter.addTerm(Field.ENTRY_CLASS_NAME, className); if (searchContext.getUserId() > 0) { SearchPermissionChecker searchPermissionChecker = SearchEngineHelperUtil.getSearchPermissionChecker(); facetBooleanFilter = searchPermissionChecker.getPermissionBooleanFilter( searchContext.getCompanyId(), searchContext.getGroupIds(), searchContext.getUserId(), className, facetBooleanFilter, searchContext); } return facetBooleanFilter; }
protected void addSearchExpandoKeywords( BooleanQuery searchQuery, SearchContext searchContext, String keywords, String className) throws Exception { ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge( searchContext.getCompanyId(), className); Set<String> attributeNames = SetUtil.fromEnumeration( expandoBridge.getAttributeNames()); for (String attributeName : attributeNames) { UnicodeProperties properties = expandoBridge.getAttributeProperties( attributeName); int indexType = GetterUtil.getInteger( properties.getProperty(ExpandoColumnConstants.INDEX_TYPE)); if (indexType != ExpandoColumnConstants.INDEX_TYPE_NONE) { String fieldName = getExpandoFieldName( searchContext, expandoBridge, attributeName); if (searchContext.isAndSearch()) { searchQuery.addRequiredTerm(fieldName, keywords); } else { searchQuery.addTerm(fieldName, keywords); } } } }
@Override protected Hits doSearch(SearchContext searchContext) throws SearchException { try { searchContext.setSearchEngineId(getSearchEngineId()); BooleanFilter queryBooleanFilter = new BooleanFilter(); queryBooleanFilter.addRequiredTerm( Field.COMPANY_ID, searchContext.getCompanyId()); Query fullQuery = createFullQuery( queryBooleanFilter, searchContext); if (!fullQuery.hasChildren()) { BooleanFilter preBooleanFilter = fullQuery.getPreBooleanFilter(); fullQuery = new MatchAllQuery(); fullQuery.setPreBooleanFilter(preBooleanFilter); } QueryConfig queryConfig = searchContext.getQueryConfig(); fullQuery.setQueryConfig(queryConfig); return IndexSearcherHelperUtil.search(searchContext, fullQuery); } catch (Exception e) { throw new SearchException(e); } }
@Override protected void indexKeyword( SearchContext searchContext, long groupId, String languageId, String keyword, float weight, String keywordFieldName, String typeFieldValue, int maxNGramLength) throws Exception { Document document = createDocument( searchContext.getCompanyId(), groupId, languageId, keyword, weight, keywordFieldName, typeFieldValue, maxNGramLength); addDocument(typeFieldValue, searchContext, document); }
searchContext.getCompanyId(), false);
private void _addPermissionFilter( BooleanFilter booleanFilter, String entryClassName, SearchContext searchContext) { if (searchContext.getUserId() == 0) { return; } Optional<String> optional = _getParentEntryClassNameOptional( entryClassName); String permissionedEntryClassName = optional.orElse(entryClassName); searchPermissionChecker.getPermissionBooleanFilter( searchContext.getCompanyId(), searchContext.getGroupIds(), searchContext.getUserId(), permissionedEntryClassName, booleanFilter, searchContext); }
@Override public BooleanFilter getFacetBooleanFilter( String className, SearchContext searchContext) throws Exception { BooleanFilter facetBooleanFilter = new BooleanFilter(); facetBooleanFilter.addTerm( Field.ENTRY_CLASS_NAME, DDMFormInstanceRecord.class.getName()); if (searchContext.getUserId() > 0) { facetBooleanFilter = searchPermissionChecker.getPermissionBooleanFilter( searchContext.getCompanyId(), searchContext.getGroupIds(), searchContext.getUserId(), DDMFormInstance.class.getName(), facetBooleanFilter, searchContext); } return facetBooleanFilter; }
try { Document document = createDocument( searchContext.getCompanyId(), groupId, languageId, dictionaryEntry.getWord(), dictionaryEntry.getWeight(), keywordFieldName,
private void _addInactiveGroupsBooleanFilter( BooleanFilter booleanFilter, SearchContext searchContext) { List<Group> inactiveGroups = groupLocalService.getActiveGroups( searchContext.getCompanyId(), false); if (ListUtil.isEmpty(inactiveGroups)) { return; } TermsFilter groupIdTermsFilter = new TermsFilter(Field.GROUP_ID); groupIdTermsFilter.addValues( ArrayUtil.toStringArray( ListUtil.toArray(inactiveGroups, Group.GROUP_ID_ACCESSOR))); booleanFilter.add(groupIdTermsFilter, BooleanClauseOccur.MUST_NOT); }
@Override public boolean process(SearchContext searchContext, Hits hits) throws SearchException { QueryConfig queryConfig = searchContext.getQueryConfig(); if (!queryConfig.isQueryIndexingEnabled()) { return true; } if (hits.getLength() >= queryConfig.getQueryIndexingThreshold()) { addDocument( searchContext.getCompanyId(), searchContext.getKeywords(), searchContext.getLocale()); } return true; }
@Override public void postProcessContextBooleanFilter( BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception { addStatus(contextBooleanFilter, searchContext); contextBooleanFilter.addRequiredTerm( Field.COMPANY_ID, searchContext.getCompanyId()); contextBooleanFilter.addRequiredTerm( Field.GROUP_ID, GetterUtil.getLong(searchContext.getAttribute(Field.GROUP_ID))); Serializable type = searchContext.getAttribute(Field.TYPE); if (type != null) { contextBooleanFilter.addRequiredTerm( Field.TYPE, GetterUtil.getInteger(type)); } }
@Override public void contribute( String keywords, BooleanQuery booleanQuery, KeywordQueryContributorHelper keywordQueryContributorHelper) { SearchContext searchContext = keywordQueryContributorHelper.getSearchContext(); ExpandoQueryContributorHelper expandoQueryContributorHelper = new ExpandoQueryContributorHelper( expandoBridgeFactory, expandoBridgeIndexer, expandoColumnLocalService, getLocalization()); expandoQueryContributorHelper.setAndSearch(searchContext.isAndSearch()); expandoQueryContributorHelper.setBooleanQuery(booleanQuery); expandoQueryContributorHelper.setClassNamesStream( keywordQueryContributorHelper.getSearchClassNamesStream()); expandoQueryContributorHelper.setCompanyId( searchContext.getCompanyId()); expandoQueryContributorHelper.setKeywords(keywords); expandoQueryContributorHelper.setLocale(searchContext.getLocale()); expandoQueryContributorHelper.contribute(); }
@Override protected Hits doSearch(SearchContext searchContext) throws SearchException { String keywords = StringUtil.trim(searchContext.getKeywords()); if (Validator.isBlank(keywords) && !GetterUtil.getBoolean( searchContext.getAttribute( SearchContextAttributes.ATTRIBUTE_KEY_EMPTY_SEARCH))) { return new HitsImpl(); } try { searchContext.setSearchEngineId(getSearchEngineId()); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.addRequiredTerm( Field.COMPANY_ID, searchContext.getCompanyId()); Query query = _getFinalQuery( createFullQuery(booleanFilter, searchContext)); QueryConfig queryConfig = searchContext.getQueryConfig(); query.setQueryConfig(queryConfig); return _indexSearcherHelper.search(searchContext, query); } catch (Exception e) { throw new SearchException(e); } }