留言板
Search on custom attribute
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,
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,
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.
I don't have right now an example to you but you can find it on the web.
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 ?
The search portlet use this code :
Indexer indexer = FacetedSearcher.getInstance();
Hits hits = indexer.search(searchContext);
LuceneSearcher is used or not ?
I'm sorry, I was thinking in other thing.
¿You have an expando attribute?
¿You have an expando attribute?
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.
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.
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?
Goto Custom Fields > and Edit your custom field to change this property.
Or do you have other specific need?
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.
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.
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.
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.
Faceted Search in Liferay 6.1
http://www.liferay.com/web/raymond.auge/blog/-/blogs/faceted-search-in-liferay-6-1
http://www.liferay.com/web/raymond.auge/blog/-/blogs/faceted-search-in-liferay-6-1
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,
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,修改在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.
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.
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.
But now I want to use regex string as my_value.
I have tried with below given code But no luck.
Is there any way to use regex as my_value?
Thanks.
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.