Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
DXP Search Customization with ModelPreFilterContributor
Gopal Prasad Satapathy, modified 5 Years ago.
Junior Member
Posts: 51
Join Date: 3/29/18
Recent Posts
Hello,
Following is the ModelPreFilterContributor code which has been written to restrict images from showing up in the search result.
But the problem that we see now is, it even restricts the images to appear in the search result when we try to search for an image in the search bar that is available inside Site->Document and Media.
Is there a way possible to restrict the file from the search result when we search from the normal search bar but to allow from the search bar that is available in Document and Media?
@Component(
immediate = true, property = "indexer.class.name=com.liferay.document.library.kernel.model.DLFileEntry",
service = com.liferay.portal.search.spi.model.query.contributor.ModelPreFilterContributor.class
)
public class ModelPreFilterContributor
implements com.liferay.portal.search.spi.model.query.contributor.
ModelPreFilterContributor {
@Override
public void contribute(
BooleanFilter booleanFilter, ModelSearchSettings modelSearchSettings,
SearchContext searchContext) {
TermsFilter filter = new TermsFilter("extension");
filter.addValues("jpeg", "jpg", "png","tif","gif","bmp","psd");
booleanFilter.add(filter, BooleanClauseOccur.MUST_NOT);
}}
Thanks,
Gopal
Following is the ModelPreFilterContributor code which has been written to restrict images from showing up in the search result.
But the problem that we see now is, it even restricts the images to appear in the search result when we try to search for an image in the search bar that is available inside Site->Document and Media.
Is there a way possible to restrict the file from the search result when we search from the normal search bar but to allow from the search bar that is available in Document and Media?
@Component(
immediate = true, property = "indexer.class.name=com.liferay.document.library.kernel.model.DLFileEntry",
service = com.liferay.portal.search.spi.model.query.contributor.ModelPreFilterContributor.class
)
public class ModelPreFilterContributor
implements com.liferay.portal.search.spi.model.query.contributor.
ModelPreFilterContributor {
@Override
public void contribute(
BooleanFilter booleanFilter, ModelSearchSettings modelSearchSettings,
SearchContext searchContext) {
TermsFilter filter = new TermsFilter("extension");
filter.addValues("jpeg", "jpg", "png","tif","gif","bmp","psd");
booleanFilter.add(filter, BooleanClauseOccur.MUST_NOT);
}}
Thanks,
Gopal
That filter is not selective. If you tell it to exclude, it is going to exclude.
Instead I'd be move this elsewhere, like maybe tacked onto the keyword contributor or even decorate the portlet itself.
Instead I'd be move this elsewhere, like maybe tacked onto the keyword contributor or even decorate the portlet itself.
Gopal Prasad Satapathy, modified 5 Years ago.
Junior Member
Posts: 51
Join Date: 3/29/18
Recent Posts
Hello David,Thanks for your reply.My requirement is to restrict images from showing up in the search result when search is performed only from the default search bar module , but not from any other search available like searching in Document and Media.
Thanks,Gopal
Thanks,Gopal
Gopal Prasad Satapathy, modified 5 Years ago.
Junior Member
Posts: 51
Join Date: 3/29/18
Recent Posts
Hello,Can i get any help on this.My requirement is to restrict images from showing up in the search result when search is performed only from the default search bar module , but not from any other search available like searching in Document and Media.
Thanks,Gopal
Thanks,Gopal
Gopal Prasad Satapathy, modified 5 Years ago.
Junior Member
Posts: 51
Join Date: 3/29/18
Recent Posts
Hello,
Am still looking for an answer. Any pointer would be of great help.
Thanks,
Gopal
Am still looking for an answer. Any pointer would be of great help.
Thanks,
Gopal
Gopal Prasad Satapathy, modified 4 Years ago.
Junior Member
Posts: 51
Join Date: 3/29/18
Recent Posts
How can this be added to only the default search bar module ?
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™