Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Antoine Comble
Search on custom attribute
22 de enero de 2013 8:15
Respuesta

Antoine Comble

Ranking: Regular Member

Mensajes: 210

Fecha de incorporación: 7 de septiembre de 2012

Mensajes recientes

Hello,

I've created a custom attribute for blog and document and media portlet.
In the search portlet, i want to search the entries which have the custom attribute containing a keyword.
I did find any solution...

Any idea ?

Thanks for advance,
Octavio Sánchez
RE: Search on custom attribute
22 de enero de 2013 8:21
Respuesta

Octavio Sánchez

Ranking: Junior Member

Mensajes: 80

Fecha de incorporación: 31 de marzo de 2009

Mensajes recientes

You have to use the lucene searcher and search "web_content/YOUR-ATTRIBUTE-NAME".

I don't have right now an example to you but you can find it on the web.
Antoine Comble
RE: Search on custom attribute
22 de enero de 2013 8:28
Respuesta

Antoine Comble

Ranking: Regular Member

Mensajes: 210

Fecha de incorporación: 7 de septiembre de 2012

Mensajes recientes

Thanks for your help but i don't find any example....

The search portlet use this code :
Indexer indexer = FacetedSearcher.getInstance();
Hits hits = indexer.search(searchContext);

LuceneSearcher is used or not ?
Octavio Sánchez
RE: Search on custom attribute
22 de enero de 2013 8:51
Respuesta

Octavio Sánchez

Ranking: Junior Member

Mensajes: 80

Fecha de incorporación: 31 de marzo de 2009

Mensajes recientes

I'm sorry, I was thinking in other thing.

¿You have an expando attribute?
Antoine Comble
RE: Search on custom attribute
22 de enero de 2013 8:59
Respuesta

Antoine Comble

Ranking: Regular Member

Mensajes: 210

Fecha de incorporación: 7 de septiembre de 2012

Mensajes recientes

Here's the code used to search :
SearchContainer mainSearchSearchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, portletURL, null, LanguageUtil.format(pageContext, "no-results-were-found-that-matched-the-keywords-x", "<strong>" + HtmlUtil.escape(keywords) + "</strong>"));
SearchContext searchContext = SearchContextFactory.getInstance(request);
searchContext.setAttribute("paginationType", "more");
searchContext.setEnd(mainSearchSearchContainer.getEnd());
searchContext.setStart(mainSearchSearchContainer.getStart());
Facet assetEntriesFacet = new AssetEntriesFacet(searchContext);
assetEntriesFacet.setStatic(true);
searchContext.addFacet(assetEntriesFacet);
Facet scopeFacet = new ScopeFacet(searchContext);
scopeFacet.setStatic(true);
searchContext.addFacet(scopeFacet);
List<FacetConfiguration> facetConfigurations = FacetConfigurationUtil.load(searchConfiguration);
for (FacetConfiguration facetConfiguration : facetConfigurations) {
Facet facet = FacetFactoryUtil.create(searchContext, facetConfiguration);
searchContext.addFacet(facet);
}
Indexer indexer = FacetedSearcher.getInstance();
Hits hits = indexer.search(searchContext);

But i don't know where insert the code you give me in the previous thread.
Gaurav Jain
RE: Search on custom attribute
22 de enero de 2013 9:14
Respuesta

Gaurav Jain

Ranking: Regular Member

Mensajes: 141

Fecha de incorporación: 31 de enero de 2011

Mensajes recientes

If you keep your custom attribute property 'Searchability ' as 'As Text' or 'As Keyword', then search portlet will automatically search your blog entries or documents in this custom attribute also.

Goto Custom Fields > and Edit your custom field to change this property.

Or do you have other specific need?
Antoine Comble
RE: Search on custom attribute
22 de enero de 2013 9:19
Respuesta

Antoine Comble

Ranking: Regular Member

Mensajes: 210

Fecha de incorporación: 7 de septiembre de 2012

Mensajes recientes

My custom attribute is already searchable.

My need is :

i create document or blog and i give a value to the custom attribute.
i go to the search portlet. i hook it adding a dropdown list with possible values for custom attribute.
i want search document or blog containing the keyword put in the text field but results must have custom attribute with value selected in dropdown list.

i hope it's comprehensive.
Gaurav Jain
RE: Search on custom attribute
22 de enero de 2013 10:36
Respuesta

Gaurav Jain

Ranking: Regular Member

Mensajes: 141

Fecha de incorporación: 31 de enero de 2011

Mensajes recientes

I will suggest you to check the implementation of the facets in search.

For a quick management of your custom attribute to behave like tags and category facets,
- open the configuration of search portlet
- select the advance mode
- change the json format setting and add following to the facets:
{
"displayStyle": "asset_tags",
"static": false,
"weight": 1.6,
"order": "OrderHitsDesc",
"data": {
"displayStyle": "list",
"maxTerms": 10,
"frequencyThreshold": 1,
"showAssetCount": true
},
"className": "com.liferay.portal.kernel.search.facet.MultiValueFacet",
"label": "expando",
"fieldName": "expando/custom_fields/custom_field"
}

here custom_field should be your custom field name.

Now when you will search "for ex if you search for test"; then a facet block will appear 'Any expando, etc'

Similarly you can check this implementation in search portlet to tune it for your need.
Gwowen Fu
RE: Search on custom attribute
22 de enero de 2013 11:13
Respuesta

Gwowen Fu

Ranking: Expert

Mensajes: 280

Fecha de incorporación: 27 de diciembre de 2010

Mensajes recientes

Faceted Search in Liferay 6.1
http://www.liferay.com/web/raymond.auge/blog/-/blogs/faceted-search-in-liferay-6-1
Antoine Comble
RE: Search on custom attribute
23 de enero de 2013 2:09
Respuesta

Antoine Comble

Ranking: Regular Member

Mensajes: 210

Fecha de incorporación: 7 de septiembre de 2012

Mensajes recientes

Thanks for your reply.

Gaurav,

i've put the code you give in the advanced search.
in the query, i can see that the search is also done in my custom field.

can i force the value of the custom field and put the search as "andSearch" to search documents contain keyword and custom attribute has a forced value ?

Thanks for advance,
Antoine Comble
RE: Search on custom attribute
23 de enero de 2013 5:25
Respuesta

Antoine Comble

Ranking: Regular Member

Mensajes: 210

Fecha de incorporación: 7 de septiembre de 2012

Mensajes recientes

Finally,

i've found solution to meet my needs. i force the value of the custom attribute as keyword in a hook of the search portlet.

Code :
searchContext.setKeywords(searchContext.getKeywords() + " AND " + "expando/custom_fields/my_field:" + my_value);

The end user continues to see only keywords entered in the input text but the search results are those expected.

Thanks a lot for all replies.