- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Liferay 6.2 中实现基于 Lucene 的索引和搜索。我有一个自定义服务生成器实体,我希望能够搜索该实体的所有字段。但问题是它不会搜索所有索引字段,除非我明确键入 field:value
在搜索框中。看起来它只是在 liferay 默认值上搜索
Field.ASSET_CATEGORY_TITLES, Field.ASSET_TAG_NAMES, Field.COMMENTS,
Field.CONTENT, Field.DESCRIPTION, Field.PROPERTIES, Field.TITLE,
Field.URL, Field.USER_NAME
这是我的实体
<entity name="Sample" local-service="true" remote-service="true" table="sample">
<column name="uuid_" type="String" />
<column name="sampleDbId" type="long" primary="true" />
<column name="sampleCollectionDbId" type="long" />
<column name="biobankDbId" type="long" />
<column name="hashedSampleId" type="String" />
<column name="hashedIndividualId" type="String" />
<column name="materialType" type="String" />
<column name="container" type="String" />
<column name="storageTemperature" type="String" />
<column name="sampledTime" type="Date"/>
<column name="anatomicalPartOntology" type="String" />
<column name="anatomicalPartOntologyVersion" type="String" />
<column name="anatomicalPartOntologyCode" type="String" />
<column name="anatomicalPartOntologyDescription" type="String" />
<column name="anatomicalPartFreeText" type="String" />
<column name="sex" type="String" />
<column name="ageLow" type="long" />
<column name="ageHigh" type="long" />
<column name="ageUnit" type="String" />
<column name="diseaseOntology" type="String" />
<column name="diseaseOntologyVersion" type="String" />
<column name="diseaseOntologyCode" type="String" />
<column name="diseaseOntologyDescription" type="String" />
<column name="diseaseFreeText" type="String" />
<column name="countryOfOrigin" type="String" />
<finder name="uuid" return-type="Collection">
<finder-column name="uuid_" />
</finder>
</entity>
我已经成功索引了我想要搜索的所有字段,并且可以在 Luke 中看到它。
我在索引器中对其进行索引,如下所示:
@Override
protected Document doGetDocument(Object obj) throws Exception {
// TODO Auto-generated method stub
System.out.println("-----doGetDocument called------");
Sample sample = (Sample)obj;
Document document = getBaseModelDocument(PORTLET_ID, sample);
if(sample.getSampleCollectionDbId() > 0){
document.addText("sampleCollectionName", SampleCollectionLocalServiceUtil.getSampleCollection(sample.getSampleCollectionDbId()).getName());
}
document.add(new Field("biobankName", BiobankGeneralInformationLocalServiceUtil.getBiobankGeneralInformation(sample.getBiobankDbId()).getBiobankName()));
document.add(new Field("materialType", sample.getMaterialType()));
//document.addText("biobankName", BiobankGeneralInformationLocalServiceUtil.getBiobankGeneralInformation(sample.getBiobankDbId()).getBiobankName());
//document.addKeyword("materialType", sample.getMaterialType());
document.addKeyword("container", sample.getContainer());
document.addText("storageTemperature", sample.getStorageTemperature());
document.addDate("sampledTime", sample.getSampledTime());
document.addText("anatomicalPartOntology", sample.getAnatomicalPartOntology());
document.addKeyword("anatomicalPartOntologyVersion", sample.getAnatomicalPartOntologyVersion());
document.addKeyword("anatomicalPartOntologyCode", sample.getAnatomicalPartOntologyCode());
document.addText("anatomicalPartOntologyDescription", sample.getAnatomicalPartOntologyDescription());
document.addText("anatomicalPartFreeText", sample.getAnatomicalPartFreeText());
document.addKeyword("sex", sample.getSex());
document.addNumber("ageLow", sample.getAgeLow());
document.addNumber("ageHigh", sample.getAgeHigh());
document.addText("ageUnit", sample.getAgeUnit());
document.addText("diseaseOntology", sample.getDiseaseOntology());
document.addKeyword("diseaseOntologyVersion", sample.getDiseaseOntologyVersion());
document.addKeyword("diseaseOntologyCode", sample.getDiseaseOntologyCode());
document.addText("diseaseOntologyDescription", sample.getDiseaseOntologyDescription());
document.addText("diseaseFreeText", sample.getDiseaseFreeText());
document.addKeyword("countryOfOrigin", sample.getCountryOfOrigin());
return document;
}
我还在我的 localserviceimpl 类中定义了 Hits 搜索方法:
public Hits search(long companyId, String keywords) throws SearchException{
System.out.println("-----SampleLocalServiceImpl search called------");
SearchContext searchContext = new SearchContext();
searchContext.setAndSearch(false);
Map<String, Serializable> attributes = new HashMap<String, Serializable>();
attributes.put("sampleCollectionName", keywords);
attributes.put("biobankName", keywords);
attributes.put("materialType", keywords);
attributes.put("container", keywords);
attributes.put("storageTemperature", keywords);
attributes.put("sampledTime", keywords);
attributes.put("anatomicalPartOntology", keywords);
attributes.put("anatomicalPartOntologyVersion", keywords);
attributes.put("anatomicalPartOntologyCode", keywords);
attributes.put("anatomicalPartOntologyDescription", keywords);
attributes.put("anatomicalPartFreeText", keywords);
attributes.put("sex", keywords);
attributes.put("ageLow", keywords);
attributes.put("ageHigh", keywords);
attributes.put("ageUnit", keywords);
attributes.put("diseaseOntology", keywords);
attributes.put("diseaseOntologyVersion", keywords);
attributes.put("diseaseOntologyCode", keywords);
attributes.put("diseaseOntologyDescription", keywords);
attributes.put("diseaseFreeText", keywords);
attributes.put("countryOfOrigin", keywords);
searchContext.setAttributes(attributes);
searchContext.setCompanyId(companyId);
searchContext.setKeywords(keywords);
System.out.println(searchContext.getAttributes());
QueryConfig queryConfig = new QueryConfig();
queryConfig.setHighlightEnabled(false);
queryConfig.setScoreEnabled(false);
//searchContext.setAttribute("materialType:", keywords);
searchContext.setQueryConfig(queryConfig);
System.out.println(searchContext.getCompanyId());
Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(
Sample.class);
System.out.println("-----SampleLocalServiceImpl search called------"+indexer.getFullQuery(searchContext));
System.out.println("-----SampleLocalServiceImpl search called------"+indexer);
return indexer.search(searchContext);
}
我通过 localserviceutil 类从我的 jsp 调用此搜索方法。
所以当我输入blood
时在搜索框中,我没有得到任何结果,但是当我输入 materialType:blood
时我得到结果。
+(+((+(entryClassName:com.xxx.portlet.xxx.model.Sample))))
(给出完整的结果集)如果我输入血液,查询日志会告诉我
+(+((+(entryClassName:com.xxx.portlet.xxx.model.Sample)))) +(assetCategoryTitles:*blood* assetTagNames:*blood* comments:blood content:blood description:blood properties:blood title:blood
url:blood userName:*blood*)
(空结果集)
如果我输入materialType:blood,查询日志会给出 +(+((+(entryClassName:com.xxx.portlet.xxx.model.Sample))))
(匹配结果集)
+(materialType:*blood* materialType:blood)
我想要的是用户能够仅在框中键入自由文本并获取匹配结果。但目前这还不起作用,因为自由文本搜索只是在 liferay 默认字段上搜索。我该如何解决这个问题?
问题也发布了here .
最佳答案
在 localserviceimpl
类的 Hits 搜索方法
中设置 searchContext.setAttributes(attributes);
还不够。我还必须重写 indexer
类中的 postProcessSearchQuery
方法。因此,在我的 indexer
类中添加以下方法后,我就开始工作了。
@Override
public void postProcessSearchQuery(BooleanQuery searchQuery, SearchContext searchContext)
throws Exception {
System.out.println("-----postProcessSearchQuery called------");
addSearchTerm(searchQuery, searchContext, "sampleCollectionName", true);
addSearchTerm(searchQuery, searchContext, "biobankName", true);
addSearchTerm(searchQuery, searchContext, "materialType", true);
addSearchTerm(searchQuery, searchContext, "container", true);
addSearchTerm(searchQuery, searchContext, "storageTemperature", true);
.....
.....
LinkedHashMap<String, Object> params =
(LinkedHashMap<String, Object>)searchContext.getAttribute("params");
if (params != null) {
String expandoAttributes = (String)params.get("expandoAttributes");
if (Validator.isNotNull(expandoAttributes)) {
addSearchExpando(searchQuery, searchContext, expandoAttributes);
}
}
}
关于java - liferay lucene 搜索不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33305078/
假设我正在向 Liferay Portal 内的不同 portlet 添加数据。所有这些数据都保存在哪里? 最佳答案 Liferay 附带的大多数开箱即用的 portlet,如博客、论坛、Wiki、W
我需要的是: Administrator-level-1(可以编辑所有2级和3级的简单用户和管理员) Administrator-level-2(可以编辑所有普通用户和3级管理员) 管理员级别 3(甚
我在 liferay 工作。我们在我们的项目中使用一个模块来创建 liferay 主题。我使用命令 ant -Ddeploy.war=true 将它部署在服务器中。 war 文件在 liferay 部
我需要一个简单的 Liferay Web 表单扩展,以增强 Liferay 7 Web 表单中填充的数据的文件附件。 还需要将此文件作为附件随电子邮件发送给注册用户。 我知道如何在 liferay 6
When Local Live staging is enabled for a site, a clone of the site is created containing copies of a
我在 liferay 工作。我们在我们的项目中使用一个模块来创建 liferay 主题。我使用命令 ant -Ddeploy.war=true 将它部署在服务器中。 war 文件在 liferay 部
插件的代码如何访问在其自己的 liferay-plugin-package.properties 文件中设置的属性? 最佳答案 您可以使用 DeployManagerUtil 首先导入以下内容: im
Liferay 7 GA1 刚刚发布,但文档尚未完成。如何将默认的 liferay Logo 更改为公司 Logo ?当然,我希望每个网站都有一个自定义 Logo 。 最佳答案 进入控制面板->配置-
我一直在阅读有关从 liferay 6 迁移到 liferay 7 的 liferay 文档 ( https://dev.liferay.com/develop/tutorials/-/knowled
我想问一个关于是否应该迁移到 Liferay 6.2 的问题。 我和我的团队从 4 个月开始就在使用 Liferay 6.1(CE 版)开发的一个相当大的门户网站上工作,现在,由于项目发布日期仍然提前
我是 liferay 的新手,我几乎确信这非常简单:使用速度标记,我希望能够生成指向 Liferay 网站内页面的链接,并将它们嵌入到不同页面上的 portlet 中。 我对如何完成它有一个模糊的想法
我想知道为用户分配的站点角色名称列表。所以我尝试如下, List userRolesList = RoleLocalServiceUtil.getUserRoles(userid);
同样,我们是否有任何可能的解决方案来避免使用扩展方法/自定义实现/ Hook /插件/扩展将用户信息填充到 liferay 数据库中以进行身份验证? 问候维沙尔 G 最佳答案 无法避免在 Life
只是想知道任何一个与 liferay 集成的 wicket 。 在启用 ajax 的情况下对 wicket portlet 进行编码有多难? 有人在生产中使用 wicket portlet 吗? 最佳
我们在liferay 中有一个叫做嵌套portlet 的东西。我想通过代码动态添加这个 portlet。有谁知道用于添加嵌套 portlet 并在其中添加其他 portlet 的代码? 谢谢 !!!
如何以编程方式获取 Liferay 默认语言或区域设置? 最佳答案 检查 com.liferay.portal.kernel.util.LocaleUtil 类方法: LocaleUtil.getDe
是否可以在 service.xml 文件中不配置任何数据库表的情况下创建 liferay 服务构建器。 实际上这里的目的是使用 liferay 服务构建器创建一个服务层。并且在这个服务层没有直接与数据
众所周知,Liferay 具有创建用户的内置功能。但我希望有一个创建用户的工作流程,其中涉及批准过程。我的意思是,用户将由管理员创建,但它应该由另一个授权人批准,然后只有用户帐户将处于事件状态。 有什
我正在使用liferay6.1 和Java SDK 开发liferay portlet。 当用户登录并单击控制面板时,他们可以看到各种选项。有没有办法隐藏这个选项? 我还是新手,但我认为您可以将它从
我发现了如何使用journalContentUtil.getContent方法将Web Content嵌入Liferay 6.2主题中。我的问题是在Liferay 7中如何做同样的事情? 最佳答案 我
我是一名优秀的程序员,十分优秀!