Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Jonathan Lloyd
Faceted Searching in 6.1
4 aprile 2012 8.54
Risposta

Jonathan Lloyd

Punteggio: New Member

Messaggi: 5

Data di Iscrizione: 30 gennaio 2012

Messaggi recenti

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
2 maggio 2013 14.20
Risposta

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 329

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

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
12 giugno 2013 11.30
Risposta

Brian Scott Schupbach

Punteggio: Expert

Messaggi: 329

Data di Iscrizione: 23 ottobre 2008

Messaggi recenti

FYI: This has been confirmed to be a bug in liferay 6.1 GA2
Florencia Gadea
RE: Faceted Searching in 6.1
5 luglio 2013 5.37
Risposta

Florencia Gadea

Punteggio: Regular Member

Messaggi: 146

Data di Iscrizione: 27 marzo 2012

Messaggi recenti

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
11 marzo 2014 2.55
Risposta

Sai Sriharsha Kasturi

Punteggio: Junior Member

Messaggi: 29

Data di Iscrizione: 21 ottobre 2012

Messaggi recenti

Please try to search based on assetCategoryIds not assetCategoryNames, then it'll work
Meera Prince
RE: Faceted Searching in 6.1
11 marzo 2014 3.07
Risposta

Meera Prince

Punteggio: Liferay Legend

Messaggi: 1110

Data di Iscrizione: 8 febbraio 2011

Messaggi recenti

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
Zdeněk Zdeněk
RE: Faceted Searching in 6.1
21 luglio 2015 2.43
Risposta

Zdeněk Zdeněk

Punteggio: New Member

Messaggi: 12

Data di Iscrizione: 4 giugno 2014

Messaggi recenti

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:

 1
 2
 3 HttpServletRequest httpRequest = PortalUtil.getOriginalServletRequest(PortalUtil
 4        .getHttpServletRequest(renderRequest));
 5    SearchContext searchContext = SearchContextFactory.getInstance(httpRequest);
 6
 7    searchContext.setKeywords(hledanyVyraz);
 8    searchContext.setEnd(2000);
 9    searchContext.setStart(0);
10
11    long[] categoryIds = { 846405 };
12    searchContext.setCategoryIds(categoryIds);
13
14    Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
15
16    assetEntriesFacet.setStatic(true);
17
18    searchContext.addFacet(assetEntriesFacet);
19
20    Facet scopeFacet = new ScopeFacet(searchContext);
21
22scopeFacet.setStatic(true);
23
24    searchContext.addFacet(scopeFacet);
25
26    Indexer indexer = FacetedSearcher.getInstance();
27
28    Hits hits = indexer.search(searchContext);
29
30    List<com.liferay.portal.kernel.search.Document> documents = hits.toList();