1
我使用一個搜索容器下面找到的項目是在給定組:如何讓我的lucene在liferay中搜索「全球」(即所有組)?
SearchContext searchContext = SearchContextFactory.getInstance(request);
searchContext.setStart(searchContainer.getStart());
searchContext.setKeywords(keywords);
searchContext.setEnd(searchContainer.getEnd());
results = ProjectLocalServiceUtil.getSearchedProjects(searchContext);
total = ProjectLocalServiceUtil.getSearchedProjectsCount(searchContext);
方法getSearchedProjects從搜索結果翻譯成的項目清單:
public List<Project> getSearchedProjects(SearchContext context) throws SearchException {
Indexer indexer = IndexerRegistryUtil.getIndexer(Project.class);
Hits results = indexer.search(context);
List<Project> projects = new ArrayList<Project>();
for (int i = 0; i < results.getDocs().length; i++) {
com.liferay.portal.kernel.search.Document doc = results.doc(i);
long projectId=GetterUtil.getLong(doc.get(Field.ENTRY_CLASS_PK));
Project project = null;
try {
project = ProjectLocalServiceUtil.getProject(projectId);
projects.add(project);
} catch (Exception e) {
e.printStackTrace();
continue;
}
}
return projects;
}
結果如我期望當搜索portlet被放入在我的projectIndexer的doGetDocument方法中設置的組中引用的組中時:
document.addKeyword(Field.GROUP_ID, groupId);
document.addKeyword(Field.SCOPE_GROUP_ID, groupId);
但我想使用portlet從另一個組搜索。
我試圖設置在portlet組id列表,使用
searchContext.setGroupIds(new long[] {projectHolder.getGroupId()});
,但我仍然沒有獲得在搜索的任何結果。
任何關於如何搜索'跨組'的指針?
Alain