Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search Liferay 6.2自定义全文搜索portlet实现_Search_Liferay 6 - Fatal编程技术网

Search Liferay 6.2自定义全文搜索portlet实现

Search Liferay 6.2自定义全文搜索portlet实现,search,liferay-6,Search,Liferay 6,我想实现自定义搜索portlet,以便可以搜索自定义结构中的属性。 假设我制作了一个名为“文学”的结构,它包含作者、内容、标题、注释、章节等属性。 我想创建“高级”搜索,在那里我可以选择特定的结构类型(文献、判决或立法)、用这些结构类型的另一个属性表示的特定部分(例如,仅选择具有PPV部分的文献或具有APS部分的文献)等 我尝试使用分面搜索,但没有找到如何将这些结构的属性包含到查询中: 这是我的“搜索”代码: SearchContext SearchContext=SearchContextFa

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

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

SearchContext SearchContext=SearchContextFactory.getInstance(httpServletRequest);
Map attributes=newhashmap();
attributes.put(Field.TITLE,“some word”);
attributes.put(“分页类型”、“常规”);
searchContext.setAttributes(attributes);
刻面assetEntriesFacet=新assetEntriesFacet(搜索上下文);
assetEntriesFacet.setStatic(真实);
searchContext.addFacet(assetEntriesFacet);
Facet scopeFacet=新的scopeFacet(searchContext);
scopeFacet.setStatic(true);
addFacet(scopeFacet);
String[]entryClassNames={JournalArticle.class.getName()};
setEntryClassNames(entryClassNames);
hits=FacetedSearcher.getInstance().search(searchContext);
列表文档=hits.toList();
所以,如何在facet搜索中包含特定于结构的属性,如“section”等

我的另一个问题是标点符号有问题。假设标题中包含“Právo”一词。当我使用单词“pravo”运行搜索时,它将显示0个结果,但当我使用“právo”运行搜索时,它将显示somw结果。使用标点符号搜索是否有解决方法

谢谢,
Patrik

在6.2中搜索FT索引是相当混乱的,我用这种方法(groovy)做到了:


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

部分回答您的问题:如果您将结构字段保持为可索引字段,那么Lucene/solr将以名称为前缀,以“web\u content/”存储它。您可以使用web\u content/fieldnameHi在查询中添加结构字段,您可以写更多详细信息吗?我试图像这样向查询中添加结构字段:attributes.put(“web_内容/部分”,“某些部分”);但是它返回了所有的日志文章,不仅仅是具有指定结构字段和值的日志文章。很好,我将这段代码重写为java,它似乎返回了我想要的内容。谢谢Krzysztof。嗨,关于这个主题我还有一个问题:我怎样才能在这个搜索中包含按类别ID进行的搜索?我曾尝试将categories数组添加到searchContext中,并作为Boolean子句添加,但没有任何效果。它忽略了这些类别。你能给我一些建议吗?sc.setCategoryId(ID);=>无法工作BooleanClauseCategoryId=BooleanClauseFactoryUtil.create(sc,Field.ASSET_CATEGORY_id,“48472”,BooleanClauseOccur.MUST.getName());=>不起作用
 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();
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"))}"
}