掲示板
Faceted Searching in 6.1
Hello,
I am trying to create a basic faceted search using the 6.1 search API, but have been running into some issues. I'm fairly new to using Liferay and there doesn't seem to be any real documentation on how to do this. I basically want the user to search based on a keyword, category, subcategory, and added date range. I've looked over Ray Auge's blog post and I'm still confused as to what does what.
It seems that whenever I provide a keyword to the SearchContext object that always overrides whatever categoryIds I set using searchContext.setCategoryIds(new long[]{ 11702 }). Also, when trying to use the JSON facet configuration to search a category it seems to have no effect at all. Does setting values in the SearchContext object take precedence over the facet configuration?
In short, I'm totally lost as to what does what. Any help is greatly appreciated.
Here is a snippet of my code. What I'm trying to accomplish here is search for a keyword in any asset in the 'DOC' category.
I am trying to create a basic faceted search using the 6.1 search API, but have been running into some issues. I'm fairly new to using Liferay and there doesn't seem to be any real documentation on how to do this. I basically want the user to search based on a keyword, category, subcategory, and added date range. I've looked over Ray Auge's blog post and I'm still confused as to what does what.
It seems that whenever I provide a keyword to the SearchContext object that always overrides whatever categoryIds I set using searchContext.setCategoryIds(new long[]{ 11702 }). Also, when trying to use the JSON facet configuration to search a category it seems to have no effect at all. Does setting values in the SearchContext object take precedence over the facet configuration?
In short, I'm totally lost as to what does what. Any help is greatly appreciated.
Here is a snippet of my code. What I'm trying to accomplish here is search for a keyword in any asset in the 'DOC' category.
SearchContext searchContext = SearchContextFactory.getInstance(PortalUtil.getHttpServletRequest(request));
searchContext.setKeywords(searchForm.getKeyword());
StringBundler sb = new StringBundler(6);
sb.append("{facets: [");
sb.append("{className: 'com.liferay.portal.kernel.search.facet.MultiValueFacet', data: {displayStyle: 'list', frequencyThreshold: 0, maxTerms: 10, showAssetCount: true, values: ['DOC']}, displayStyle: 'asset_tags', fieldName: 'assetCategoryNames', label: 'category', order: 'OrderHitsDesc', static: false, weight: 1.3},");
sb.append("]}");
List<facetconfiguration> fcs = FacetConfigurationUtil.load(sb.toString());
for (FacetConfiguration fc : fcs) {
searchContext.addFacet(FacetFactoryUtil.create(searchContext, fc));
}
Indexer indexer = FacetedSearcher.getInstance();
Hits hits = indexer.search(searchContext);
String[] queryTerms = hits.getQueryTerms();
List<document> docs = hits.toList();
for (Document d : docs) {
logger.debug("showSearch() - d: " + d.toString());
}
</document></facetconfiguration>
10年前 に Brian Scott Schupbach によって更新されました。
RE: Faceted Searching in 6.1
Expert 投稿: 329 参加年月日: 08/10/23 最新の投稿
I'm having the same issue. Filtering by categories doesn't work if I add a keyword... My code looks almost exactly like yours. If you've figured it out, I would be very interested in hearing how you did it.
Thanks,
Brian
Thanks,
Brian
10年前 に Brian Scott Schupbach によって更新されました。
RE: Faceted Searching in 6.1
Expert 投稿: 329 参加年月日: 08/10/23 最新の投稿
FYI: This has been confirmed to be a bug in liferay 6.1 GA2
10年前 に Florencia Gadea によって更新されました。
RE: Faceted Searching in 6.1
Regular Member 投稿: 146 参加年月日: 12/03/27 最新の投稿
Hi!
I'm trying to search by categoryId in Liferay 6.1 GA 1 and it doesn't work either. Is it a bug in that version too?
Cheers,
Flor.
I'm trying to search by categoryId in Liferay 6.1 GA 1 and it doesn't work either. Is it a bug in that version too?
Cheers,
Flor.
10年前 に Sai Sriharsha Kasturi によって更新されました。
RE: Faceted Searching in 6.1
Junior Member 投稿: 34 参加年月日: 12/10/21 最新の投稿
Please try to search based on assetCategoryIds not assetCategoryNames, then it'll work
10年前 に meera prince によって更新されました。
RE: Faceted Searching in 6.1
Liferay Legend 投稿: 1111 参加年月日: 11/02/08 最新の投稿
Hi
Please have a look into Jukebox portlet there you can find faced search related stuff
https://github.com/liferay-labs/jukebox-portlet
Regards,
Meera Prince
Please have a look into Jukebox portlet there you can find faced search related stuff
https://github.com/liferay-labs/jukebox-portlet
Regards,
Meera Prince
8年前 に Zdeněk Zdeněk によって更新されました。
RE: Faceted Searching in 6.1
New Member 投稿: 12 参加年月日: 14/06/04 最新の投稿
Hello.
Does anybody have a solution to this problem?
I'm trying to find items over SearchContext using keywords and filtering across categories. Unfortunately method searchContext.setCategoryIds(categoryIds); has no effect on the search :-(
I have installed Liferay 6.2 GA 4
Thank you very much for help
Zdeněk
my code:
Does anybody have a solution to this problem?
I'm trying to find items over SearchContext using keywords and filtering across categories. Unfortunately method searchContext.setCategoryIds(categoryIds); has no effect on the search :-(
I have installed Liferay 6.2 GA 4
Thank you very much for help
Zdeněk
my code:
HttpServletRequest httpRequest = PortalUtil.getOriginalServletRequest(PortalUtil
.getHttpServletRequest(renderRequest));
SearchContext searchContext = SearchContextFactory.getInstance(httpRequest);
searchContext.setKeywords(hledanyVyraz);
searchContext.setEnd(2000);
searchContext.setStart(0);
long[] categoryIds = { 846405 };
searchContext.setCategoryIds(categoryIds);
Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
assetEntriesFacet.setStatic(true);
searchContext.addFacet(assetEntriesFacet);
Facet scopeFacet = new ScopeFacet(searchContext);
scopeFacet.setStatic(true);
searchContext.addFacet(scopeFacet);
Indexer indexer = FacetedSearcher.getInstance();
Hits hits = indexer.search(searchContext);
List<com.liferay.portal.kernel.search.document> documents = hits.toList();
</com.liferay.portal.kernel.search.document>