Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jonathan Lloyd
Faceted Searching in 6.1
April 4, 2012 8:54 AM
Answer

Jonathan Lloyd

Rank: New Member

Posts: 4

Join Date: January 30, 2012

Recent Posts

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.

 1
 2SearchContext searchContext = SearchContextFactory.getInstance(PortalUtil.getHttpServletRequest(request));
 3searchContext.setKeywords(searchForm.getKeyword());
 4
 5StringBundler sb = new StringBundler(6);
 6sb.append("{facets: [");
 7sb.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},");
 8sb.append("]}");
 9
10List<FacetConfiguration> fcs = FacetConfigurationUtil.load(sb.toString());
11   
12for (FacetConfiguration fc : fcs) {
13    searchContext.addFacet(FacetFactoryUtil.create(searchContext, fc));
14}
15   
16Indexer indexer = FacetedSearcher.getInstance();
17Hits hits = indexer.search(searchContext);
18String[] queryTerms = hits.getQueryTerms();
19List<Document> docs = hits.toList();
20for (Document d : docs) {
21    logger.debug("showSearch() - d: " + d.toString());
22}
Brian Scott Schupbach
RE: Faceted Searching in 6.1
May 2, 2013 2:20 PM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 331

Join Date: October 23, 2008

Recent Posts

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
Brian Scott Schupbach
RE: Faceted Searching in 6.1
June 12, 2013 11:30 AM
Answer

Brian Scott Schupbach

Rank: Expert

Posts: 331

Join Date: October 23, 2008

Recent Posts

FYI: This has been confirmed to be a bug in liferay 6.1 GA2
Florencia Gadea
RE: Faceted Searching in 6.1
July 5, 2013 5:37 AM
Answer

Florencia Gadea

Rank: Regular Member

Posts: 159

Join Date: March 27, 2012

Recent Posts

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.
Sai Sriharsha Kasturi
RE: Faceted Searching in 6.1
March 11, 2014 2:55 AM
Answer

Sai Sriharsha Kasturi

Rank: New Member

Posts: 6

Join Date: October 21, 2012

Recent Posts

Please try to search based on assetCategoryIds not assetCategoryNames, then it'll work
Meera Prince
RE: Faceted Searching in 6.1
March 11, 2014 3:07 AM
Answer

Meera Prince

Rank: Liferay Master

Posts: 814

Join Date: February 8, 2011

Recent Posts

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