RE: RE: Liferay 7.4 Search Portlet -search with only fileextension and expando

Jamie Sammons, modified 2 Years ago. Regular Member Posts: 139 Join Date: 2/22/11 Recent Posts

Hi ,

I am upgrading from 6.2 to 7.4.x and in 6.2 we added some of the custom fileds with extension, expand and added that values to serviceContext. here service context object is created in jsp(main_search.jspf) page and using hook implementd like below. but in 7.4 i am not able to add that because of servicecontext object created in liferay class. for that we don't have option to write the hook to SearchDisplayContext class.

if(Validator.isNotNull(Type) && Type != ""){
		Query pbsubmittalTypeQuery = StringQueryFactoryUtil.create("expando/custom_fields/Type:"+ "\""+Type+"\"");
		BooleanClause pbsubmittalTypeClause = BooleanClauseFactoryUtil.create(searchContext, pbsubmittalTypeQuery, BooleanClauseOccur.MUST.getName());
		booleanClauseList.add(pbsubmittalTypeClause);
	} 
	
if(Validator.isNotNull(fileExtension) && fileExtension != ""){
	Query fileExtensionQuery = StringQueryFactoryUtil.create("entryClassName:com.liferay.portlet.documentlibrary.model.DLFileEntry +extension:"+fileExtension);
	BooleanClause fileExtensionClause = BooleanClauseFactoryUtil.create(searchContext, fileExtensionQuery, BooleanClauseOccur.MUST.getName());
	booleanClauseList.add(fileExtensionClause);
} 
if(booleanClauseList.size()>0){
	BooleanClause[] booleanClause = new BooleanClause[booleanClauseList.size()];
	booleanClause = booleanClauseList.toArray(booleanClause);
	searchContext.setBooleanClauses(booleanClause);
} 

Any suggition how we can add conditions in 7.4?

thumbnail
Jamie Sammons, modified 2 Years ago. Expert Posts: 308 Join Date: 2/13/13 Recent Posts

Hi Srini, first I'm going to suggest that you get away from the long deprecatedsearch portlet and use the search page with its widgets. It's quite possible that on 7.4 you can achieve what you want with a custom filter if you use the search page and widgets--this would eliminate a code customization for you so it's worth exploring.We've documented some custom filter examples to help folks get started.

 

Jamie Sammons, modified 2 Years ago. Regular Member Posts: 139 Join Date: 2/22/11 Recent Posts

But in ,

below ticket Liferay 7.1 - Filtering search results by specific custom field we can add the below code to fileter but  

searchContext object creating in SearchContextFactoryImpl class and how we can add it?

BooleanClause expandoClause = BooleanClauseFactoryUtil.create(<expando field name>, <your value>,BooleanClauseOccur.MUST.toString());
searchContext.setBooleanClauses(new BooleanClause[]{expandoClause});