001
014
015 package com.liferay.portal.kernel.search;
016
017 import com.liferay.portal.kernel.util.LocaleUtil;
018 import com.liferay.portal.util.PortletKeys;
019
020 import java.util.Locale;
021
022
026 public class QueryIndexingHitsProcessor implements HitsProcessor {
027
028 @Override
029 public boolean process(SearchContext searchContext, Hits hits)
030 throws SearchException {
031
032 QueryConfig queryConfig = searchContext.getQueryConfig();
033
034 if (!queryConfig.isQueryIndexingEnabled()) {
035 return true;
036 }
037
038 if (hits.getLength() >= queryConfig.getQueryIndexingThreshold()) {
039 addDocument(
040 searchContext.getCompanyId(), searchContext.getKeywords(),
041 searchContext.getLocale());
042 }
043
044 return true;
045 }
046
047 public void setDocument(Document document) {
048 _document = document;
049 }
050
051 protected void addDocument(long companyId, String keywords, Locale locale)
052 throws SearchException {
053
054 Document document = (Document)_document.clone();
055
056 document.addKeyword(Field.COMPANY_ID, companyId);
057 document.addKeyword(Field.KEYWORD_SEARCH, keywords);
058 document.addKeyword(Field.LANGUAGE_ID, LocaleUtil.toLanguageId(locale));
059 document.addKeyword(Field.PORTLET_ID, PortletKeys.SEARCH);
060
061 SearchEngineUtil.addDocument(
062 SearchEngineUtil.getDefaultSearchEngineId(), companyId, document);
063 }
064
065 private Document _document;
066
067 }