Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Antoine Comble
Search on custom attribute
January 22, 2013 8:15 AM
Answer

Antoine Comble

Rank: Regular Member

Posts: 210

Join Date: September 7, 2012

Recent Posts

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
January 22, 2013 8:21 AM
Answer

Octavio Sánchez

Rank: Junior Member

Posts: 80

Join Date: March 31, 2009

Recent Posts

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
January 22, 2013 8:28 AM
Answer

Antoine Comble

Rank: Regular Member

Posts: 210

Join Date: September 7, 2012

Recent Posts

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
January 22, 2013 8:51 AM
Answer

Octavio Sánchez

Rank: Junior Member

Posts: 80

Join Date: March 31, 2009

Recent Posts

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

¿You have an expando attribute?
Antoine Comble
RE: Search on custom attribute
January 22, 2013 8:59 AM
Answer

Antoine Comble

Rank: Regular Member

Posts: 210

Join Date: September 7, 2012

Recent Posts

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
January 22, 2013 9:14 AM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 141

Join Date: January 31, 2011

Recent Posts

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
January 22, 2013 9:19 AM
Answer

Antoine Comble

Rank: Regular Member

Posts: 210

Join Date: September 7, 2012

Recent Posts

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
January 22, 2013 10:36 AM
Answer

Gaurav Jain

Rank: Regular Member

Posts: 141

Join Date: January 31, 2011

Recent Posts

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
January 22, 2013 11:13 AM
Answer

Gwowen Fu

Rank: Expert

Posts: 280

Join Date: December 27, 2010

Recent Posts

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
January 23, 2013 2:09 AM
Answer

Antoine Comble

Rank: Regular Member

Posts: 210

Join Date: September 7, 2012

Recent Posts

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
January 23, 2013 5:25 AM
Answer

Antoine Comble

Rank: Regular Member

Posts: 210

Join Date: September 7, 2012

Recent Posts

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.