gpt4 book ai didi

search - Liferay searchContext 按 AssetTags 和关键词搜索

转载 作者:行者123 更新时间:2023-12-02 22:03:46 25 4
gpt4 key购买 nike

我正在尝试通过 AssetEntries 实现自定义搜索 portlet。目前 AssetEntryQuery 不允许使用关键字进行搜索。我正在尝试通过 FacetedSearcher 进行搜索。按关键字搜索似乎还可以。但是当我尝试通过 AssetTagNames 进行搜索时

searchContext.setAssetTagNames(assetTagNames)

它根本不起作用。这是我的一段代码

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

/*MultiValueFacet multiValueFacet=new MultiValueFacet(searchContext);
multiValueFacet.setFieldName("assetTagNames");
multiValueFacet.setStatic(false);
searchContext.addFacet(multiValueFacet);*/

searchContext.setCompanyId(themeDisplay.getCompanyId());
String []assetTagNames=new String[1];
assetTagNames[0]= assetTagName;
searchContext.setAssetTagNames(assetTagNames);
searchContext.setKeywords(keywords);
String[] entryClassName = {JournalArticle.class.getName()};
searchContext.setEntryClassNames(entryClassName);

Indexer indexer = FacetedSearcher.getInstance();
// searchContext.setAndSearch(true);
Hits hits = indexer.search(searchContext);
System.out.println("Hits: " + hits.getLength());

请求的结果查询搜索关键字:key1key1 Assets 标签名称:一些标签

+(+(companyId:1) +((+(entryClassName:com.liferay.portlet.journal.model.JournalArticle) +(status:0)))) +(assetCategoryTitles:*key1key1* assetCategoryTitles_en_US:*key1key1* assetTagNames:*key1key1* comments:key1key1 content:key1key1 description:key1key1 properties:key1key1 title:key1key1 url:key1key1 userName:*key1key1* classPK:key1key1 content_en_US:key1key1 description_en_US:key1key1 entryClassPK:key1key1 title_en_US:key1key1 type:key1key1)

如您所见,AssetTag 未应用于查询。我已经尝试过设置了

searchContext.setAttribute("assetTagNames",assetTagName);

并注释了 MultiValueFacet 代码但没有结果。为了进一步,我需要按日期范围和类别进行搜索。有人知道吗?

最佳答案

幸运的是解决了这个问题。

如果您想通过标签进行搜索,您必须为此使用一个单独的方面,例如

        MultiValueFacet assetTagsFacet = new MultiValueFacet(searchContext);
assetTagsFacet.setFieldName(Field.ASSET_TAG_NAMES);
searchContext.addFacet(assetTagsFacet);

同时使用 searchContext.setAttribute("assetTagNames", assetTagName); 而不是 searchContext.setAssetTagNames(assetTagName);

通过类别搜索相同的东西:

        MultiValueFacet assetCategoriesFacet = new MultiValueFacet(searchContext);
assetCategoriesFacet.setFieldName("assetCategoryTitles");
searchContext.addFacet(assetCategoriesFacet);
searchContext.setAttribute("assetCategoryTitles", assetCategoryName);

我还想按 JournalArticle 的自定义类型进行搜索,我为此创建了分面,但在查询中得到了两次“类型”。作为解决方案,我在设置 entryClassName 期间使用 MultiValueFacet 而不是 AssetEntriesFacet

    MultiValueFacet assetEntriesFacet = new MultiValueFacet(searchContext);
assetEntriesFacet.setFieldName("entryClassName");
searchContext.setAttribute("entryClassName",JournalArticle.class.getName());
searchContext.addFacet(assetEntriesFacet);

关于search - Liferay searchContext 按 AssetTags 和关键词搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16440482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com