Message Boards

DXP Search Customization with ModelPreFilterContributor

Gopal Prasad Satapathy, modified 4 Years ago.

DXP Search Customization with ModelPreFilterContributor

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
thumbnail
David H Nebinger, modified 4 Years ago.

RE: DXP Search Customization with ModelPreFilterContributor

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
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.
Gopal Prasad Satapathy, modified 4 Years ago.

RE: DXP Search Customization with ModelPreFilterContributor

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
Gopal Prasad Satapathy, modified 4 Years ago.

RE: DXP Search Customization with ModelPreFilterContributor

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
Gopal Prasad Satapathy, modified 4 Years ago.

RE: DXP Search Customization with ModelPreFilterContributor

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
Gopal Prasad Satapathy, modified 3 Years ago.

RE: DXP Search Customization with ModelPreFilterContributor

Junior Member Posts: 51 Join Date: 3/29/18 Recent Posts

How can this be added to only the default search bar module ?