【问题标题】:Liferay 6.2 custom fulltext search portlet implementationLiferay 6.2 自定义全文搜索 portlet 实现
【发布时间】:2014-07-02 05:45:31
【问题描述】:

我想实现自定义搜索portlet,以便可以搜索属于自定义结构的属性。 假设我创建了一个名为“文学”的结构,其中包含作者、内容、标题、注释、章节等属性。 我想创建“高级”搜索,我可以在哪里选择特定的结构类型(文学、裁决或立法),用这些结构类型的另一个属性表示的特定部分(例如,仅选择带有 PPV 部分的文献或带有 APS 部分的文献)等等

我尝试使用分面搜索,但不知道如何将这些结构的属性包含到查询中: 这是我的“搜索”代码:

 SearchContext searchContext = SearchContextFactory.getInstance(httpServletRequest);
 Map<String, Serializable> attributes =    new HashMap<String, Serializable>();
 attributes.put(Field.TITLE, "some word");
 attributes.put("paginationType", "regular");
 searchContext.setAttributes(attributes);

 Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
 assetEntriesFacet.setStatic(true);            
 searchContext.addFacet(assetEntriesFacet);

 Facet scopeFacet = new ScopeFacet(searchContext);
 scopeFacet.setStatic(true);            
 searchContext.addFacet(scopeFacet);

 String[] entryClassNames = { JournalArticle.class.getName() };
 searchContext.setEntryClassNames(entryClassNames);

 hits = FacetedSearcher.getInstance().search(searchContext);
 List<Document> docs = hits.toList();

那么如何在构面搜索中包含我的结构特定属性,例如“部分”等...

我的另一个问题是标点符号有问题。假设标题包含单词“Právo”。当我使用单词“pravo”运行搜索时,它会带来 0 个结果,但是当我使用“právo”运行搜索时,它会找到我的结果。有没有标点符号搜索的解决方法?

谢谢, 帕特里克

【问题讨论】:

  • 对您的问题的部分回答:如果您将结构字段保持为可索引,那么 Lucene/solr 将以“web_content/”为前缀的名称存储它。您可以使用 web_content/fieldname 在查询中添加结构字段
  • 嗨,你能写更多细节吗?我试图像这样添加结构字段来查询:attributes.put("web_content/section", "some section");但它返回所有期刊文章,不仅是具有指定结构字段和值的期刊文章。

标签: search liferay-6


【解决方案1】:

在 6.2 中搜索 FT 索引非常混乱,我设法做到了(groovy):

Indexer indexer = IndexerRegistryUtil.getIndexer(JournalArticle.class.name);

SearchContext sc = new SearchContext([
        companyId: PortalUtil.defaultCompanyId,
        groupIds: groupId
]);

String testText = DDMIndexerUtil.encodeName(
        structureId, "custom-field-name", LocaleUtil.fromLanguageId("pl_PL"));

BooleanClause testTextClause = BooleanClauseFactoryUtil.create(
        sc, testText, "Search term", BooleanClauseOccur.MUST.getName())

sc.setBooleanClauses(testTextClause)

sc.setStart(QueryUtil.ALL_POS);
sc.setEnd(QueryUtil.ALL_POS);

sc.setAttribute("paginationType", "none");

hits = indexer.search(sc);

hits.toList().each { Document doc ->
    JournalArticle ja = JournalArticleLocalServiceUtil.getArticle(groupId, doc.get("articleId"))
    println "${ja.getTitle(LocaleUtil.fromLanguageId("pl_PL"))}"
}

要运行它,您需要拥有structureId(检查journalarticle 表)和groupId。

【讨论】:

  • 很好,我将这段代码重写为java,似乎它正在返回我想要的。谢谢 Krzysztof。
  • 您好,我对此主题还有一个问题:如何将按 categoryId 的搜索包含在此搜索中?我尝试将类别数组添加到 searchContext 并作为 BooleanClause 但没有任何效果。它忽略了这些 categoryIds。你能给我什么建议吗? sc.setCategoryIds(ids); => 不工作 BooleanClause categoryId = BooleanClauseFactoryUtil.create(sc, Field.ASSET_CATEGORY_IDS, "48472", BooleanClauseOccur.MUST.getName()); => 不工作
猜你喜欢
  • 2023-03-26
  • 2014-03-21
  • 2015-10-10
  • 1970-01-01
  • 2014-01-26
  • 2021-02-06
  • 1970-01-01
  • 2013-06-17
  • 1970-01-01
相关资源
最近更新 更多