List of usage examples for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK
String ENTRY_CLASS_PK
To view the source code for com.liferay.portal.kernel.search Field ENTRY_CLASS_PK.
Click Source Link
From source file:com.liferay.document.library.repository.external.ExtRepositoryAdapter.java
License:Open Source License
@Override public Hits search(SearchContext searchContext, Query query) throws SearchException { long startTime = System.currentTimeMillis(); List<ExtRepositorySearchResult<?>> extRepositorySearchResults = null; try {/*ww w . j a va2 s . co m*/ extRepositorySearchResults = _extRepository.search(searchContext, query, new ExtRepositoryQueryMapperImpl(this)); } catch (PortalException | SystemException e) { throw new SearchException("Unable to perform search", e); } QueryConfig queryConfig = searchContext.getQueryConfig(); List<Document> documents = new ArrayList<>(); List<String> snippets = new ArrayList<>(); List<Float> scores = new ArrayList<>(); int total = 0; for (ExtRepositorySearchResult<?> extRepositorySearchResult : extRepositorySearchResults) { try { ExtRepositoryObjectAdapter<?> extRepositoryEntryAdapter = _toExtRepositoryObjectAdapter( ExtRepositoryObjectAdapterType.OBJECT, extRepositorySearchResult.getObject()); Document document = new DocumentImpl(); document.addKeyword(Field.ENTRY_CLASS_NAME, extRepositoryEntryAdapter.getModelClassName()); document.addKeyword(Field.ENTRY_CLASS_PK, extRepositoryEntryAdapter.getPrimaryKey()); document.addKeyword(Field.TITLE, extRepositoryEntryAdapter.getName()); documents.add(document); if (queryConfig.isScoreEnabled()) { scores.add(extRepositorySearchResult.getScore()); } else { scores.add(1.0F); } snippets.add(extRepositorySearchResult.getSnippet()); total++; } catch (PortalException | SystemException e) { if (_log.isWarnEnabled()) { _log.warn("Invalid entry returned from search", e); } } } float searchTime = (float) (System.currentTimeMillis() - startTime) / Time.SECOND; Hits hits = new HitsImpl(); hits.setDocs(documents.toArray(new Document[documents.size()])); hits.setLength(total); hits.setQueryTerms(new String[0]); hits.setScores(ArrayUtil.toFloatArray(scores)); hits.setSearchTime(searchTime); hits.setSnippets(snippets.toArray(new String[snippets.size()])); hits.setStart(startTime); return hits; }
From source file:com.liferay.document.library.service.test.DLAppServiceTest.java
License:Open Source License
protected static void search(FileEntry fileEntry, String keywords, boolean expected) throws Exception { SearchContext searchContext = new SearchContext(); searchContext.setAttribute("paginationType", "regular"); searchContext.setCompanyId(fileEntry.getCompanyId()); searchContext.setFolderIds(new long[] { fileEntry.getFolderId() }); searchContext.setGroupIds(new long[] { fileEntry.getRepositoryId() }); searchContext.setKeywords(keywords); QueryConfig queryConfig = searchContext.getQueryConfig(); queryConfig.setHighlightEnabled(false); queryConfig.setScoreEnabled(false);/*from www . j av a 2s . c o m*/ Indexer<DLFileEntry> indexer = IndexerRegistryUtil.getIndexer(DLFileEntryConstants.getClassName()); Hits hits = indexer.search(searchContext); boolean found = false; for (Document document : hits.getDocs()) { long fileEntryId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); if (fileEntryId == fileEntry.getFileEntryId()) { found = true; break; } } Assert.assertEquals(hits.toString(), expected, found); }
From source file:com.liferay.dynamic.data.lists.internal.search.DDLRecordIndexer.java
License:Open Source License
public DDLRecordIndexer() { setDefaultSelectedFieldNames(Field.COMPANY_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.UID); setDefaultSelectedLocalizedFieldNames(Field.DESCRIPTION, Field.TITLE); setPermissionAware(true);//from w ww.j a v a 2 s. co m }
From source file:com.liferay.dynamic.data.lists.internal.search.DDLRecordSetIndexer.java
License:Open Source License
public DDLRecordSetIndexer() { setDefaultSelectedFieldNames(Field.COMPANY_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.UID); setPermissionAware(true); }
From source file:com.liferay.dynamic.data.mapping.internal.search.DDMFormInstanceIndexer.java
License:Open Source License
public DDMFormInstanceIndexer() { setDefaultSelectedFieldNames(Field.COMPANY_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.UID); setPermissionAware(true); }
From source file:com.liferay.dynamic.data.mapping.internal.search.DDMFormInstanceRecordIndexer.java
License:Open Source License
public DDMFormInstanceRecordIndexer() { setDefaultSelectedFieldNames(Field.COMPANY_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.UID); setDefaultSelectedLocalizedFieldNames(Field.DESCRIPTION, Field.TITLE); setPermissionAware(true);/*from w ww . ja v a 2 s .co m*/ }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMFormInstanceRecordLocalServiceImpl.java
License:Open Source License
protected List<DDMFormInstanceRecord> getFormInstanceRecords(Hits hits) throws PortalException { List<DDMFormInstanceRecord> formInstanceRecords = new ArrayList<>(); for (Document document : hits.toList()) { long recordId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); try {//from w w w .j a v a2 s . co m DDMFormInstanceRecord formInstanceRecord = getFormInstanceRecord(recordId); formInstanceRecords.add(formInstanceRecord); } catch (NoSuchFormInstanceRecordException nsfire) { if (_log.isWarnEnabled()) { _log.warn("DDM form instance record index is stale and" + "contains record " + recordId, nsfire); } long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); Indexer<DDMFormInstanceRecord> indexer = getDDMFormInstanceRecordIndexer(); indexer.delete(companyId, document.getUID()); } } return formInstanceRecords; }
From source file:com.liferay.experts.questions.util.QuestionsIndexer.java
License:Open Source License
@Override protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) { String title = document.get(Field.TITLE); String content = snippet;/*w w w .j av a 2 s . c o m*/ if (Validator.isNull(snippet)) { content = StringUtil.shorten(document.get(Field.CONTENT), 200); } String questionId = document.get(Field.ENTRY_CLASS_PK); portletURL.setParameter("mvcPath", "/question/view_question.jsp"); portletURL.setParameter("questionId", questionId); return new Summary(title, content, portletURL); }
From source file:com.liferay.experts.questions.util.QuestionsUtil.java
License:Open Source License
public static List<Question> getQuestions(Hits hits) throws PortalException, SystemException { List<Question> questions = new ArrayList<Question>(); List<Document> documents = hits.toList(); for (Document document : documents) { long questionId = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK)); try {/*from ww w .j a v a 2 s . co m*/ Question question = QuestionLocalServiceUtil.getQuestion(questionId); questions.add(question); } catch (NoSuchQuestionException nsae) { Indexer indexer = IndexerRegistryUtil.getIndexer(Question.class); long companyId = GetterUtil.getLong(document.get(Field.COMPANY_ID)); indexer.delete(companyId, String.valueOf(questionId)); } } return questions; }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
public JournalArticleIndexer() { setDefaultSelectedFieldNames(Field.ASSET_TAG_NAMES, Field.ARTICLE_ID, Field.COMPANY_ID, Field.DEFAULT_LANGUAGE_ID, Field.ENTRY_CLASS_NAME, Field.ENTRY_CLASS_PK, Field.GROUP_ID, Field.MODIFIED_DATE, Field.SCOPE_GROUP_ID, Field.VERSION, Field.UID); setDefaultSelectedLocalizedFieldNames(Field.CONTENT, Field.DESCRIPTION, Field.TITLE); setFilterSearch(true);//www. j a v a2 s. c o m setPermissionAware(true); setSelectAllLocales(true); }