留言板

Search on custom attribute

thumbnail
Antoine Comble,修改在11 年前。

Search on custom attribute

Regular Member 帖子: 232 加入日期: 12-9-7 最近的帖子
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,修改在11 年前。

RE: Search on custom attribute

Junior Member 帖子: 80 加入日期: 09-3-31 最近的帖子
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.
thumbnail
Antoine Comble,修改在11 年前。

RE: Search on custom attribute

Regular Member 帖子: 232 加入日期: 12-9-7 最近的帖子
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,修改在11 年前。

RE: Search on custom attribute

Junior Member 帖子: 80 加入日期: 09-3-31 最近的帖子
I'm sorry, I was thinking in other thing.

¿You have an expando attribute?
thumbnail
Antoine Comble,修改在11 年前。

RE: Search on custom attribute

Regular Member 帖子: 232 加入日期: 12-9-7 最近的帖子
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.
thumbnail
Gaurav Jain,修改在11 年前。

RE: Search on custom attribute

Regular Member 帖子: 145 加入日期: 11-1-31 最近的帖子
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?
thumbnail
Antoine Comble,修改在11 年前。

RE: Search on custom attribute

Regular Member 帖子: 232 加入日期: 12-9-7 最近的帖子
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.
thumbnail
Gaurav Jain,修改在11 年前。

RE: Search on custom attribute

Regular Member 帖子: 145 加入日期: 11-1-31 最近的帖子
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,修改在11 年前。

RE: Search on custom attribute

Expert 帖子: 315 加入日期: 10-12-27 最近的帖子
Faceted Search in Liferay 6.1
http://www.liferay.com/web/raymond.auge/blog/-/blogs/faceted-search-in-liferay-6-1
thumbnail
Antoine Comble,修改在11 年前。

RE: Search on custom attribute

Regular Member 帖子: 232 加入日期: 12-9-7 最近的帖子
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,
thumbnail
Antoine Comble,修改在11 年前。

RE: Search on custom attribute (答复)

Regular Member 帖子: 232 加入日期: 12-9-7 最近的帖子
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.
thumbnail
Poorav Solanki,修改在6 年前。

RE: Search on custom attribute with REGEX

New Member 帖子: 9 加入日期: 15-7-2 最近的帖子
Hi

Thank you guys this works well with string value.
Code :
searchContext.setKeywords(searchContext.getKeywords() + " AND " + "expando/custom_fields/my_field:" + my_value);


But now I want to use regex string as my_value.
I have tried with below given code But no luck.
Code :
searchContext.setKeywords(searchContext.getKeywords() + " AND " + "expando/custom_fields/Countries:"/^15,|,15,|,15$|^15$/");


Is there any way to use regex as my_value?
Thanks.