掲示板

Case sensitive Dynamic query

thumbnail
14年前 に Rishi Dev Gupta によって更新されました。

Case sensitive Dynamic query

Expert 投稿: 255 参加年月日: 08/11/23 最新の投稿
hi
I have created a dynamic query to search Groups based on group name. The query is doing case sensitive search only. Is there a way to search every thing without alphabetic case.

My code is some thing like

DynamicQuery query = DynamicQueryFactoryUtil.forClass(Group.class, "group") 
     	   .add(restrictionsFactory.and(PropertyFactoryUtil.forName("group.companyId").eq(themeDisplay.getCompanyId()),
     			PropertyFactoryUtil.forName("group.name").like([b]tempSearch[/b]))) 
     		.add(restrictionsFactory.in("group.groupId", objArr));
     		;



Here "tempSearch" is the search term I am looking for. The like clause to search group.name should not be case sensitive.
Please reply.
thumbnail
14年前 に Aritz Galdos によって更新されました。

RE: Case sensitive Dynamic query

Expert 投稿: 416 参加年月日: 07/05/15 最新の投稿
Hi,

Did you try ilike instead of like? (note "I" before like)

It stands for Insensitive like

Hope It helps!
thumbnail
14年前 に Rishi Dev Gupta によって更新されました。

RE: Case sensitive Dynamic query

Expert 投稿: 255 参加年月日: 08/11/23 最新の投稿
Thanks Aritz, it worked like a charm.
thumbnail
14年前 に Rishi Dev Gupta によって更新されました。

RE: Case sensitive Dynamic query

Expert 投稿: 255 参加年月日: 08/11/23 最新の投稿
Another option I am wondering for is, Can we have sub queries here. Suppose I have to return matching record from group table based on some query or values that are fetched from some other table.

or

Like earlier we can use Expression.sql() to directly insert the sub queries but now its a depriciated api.

so do we have any alternatives for these functionalities in LFR 5.2.3.
thumbnail
14年前 に Faris Abdulla によって更新されました。

RE: Case sensitive Dynamic query

Regular Member 投稿: 183 参加年月日: 09/09/02 最新の投稿
Hi Rishi Dev Gupta ,

You can use Expression.sql() for joining the queries using DetachedCriteria. Like this:

DetachedCriteria dCriteria = DetachedCriteria.forClass(Group.class);
dCriteria.add(Expression.sql(companyId + " in ("10141")"));

DynamicQuery query = new DynamicQueryImpl(dCriteria);



Thanks and regards,


Faris Abdulla
thumbnail
14年前 に Rishi Dev Gupta によって更新されました。

RE: Case sensitive Dynamic query

Expert 投稿: 255 参加年月日: 08/11/23 最新の投稿
Thanks Faris

My concern is that org.hibernate.criterion.Expression is depreciated as of now, so are we having any other alternative in LFR similar to that.
thumbnail
14年前 に Faris Abdulla によって更新されました。

RE: Case sensitive Dynamic query

Regular Member 投稿: 183 参加年月日: 09/09/02 最新の投稿
Hai Rishi Dev Gupta,

Did you get the DynamicQuery . If yes let me know please.

Thanks and Regards,

Faris Abdulla
thumbnail
13年前 に Michael Charles によって更新されました。

RE: Case sensitive Dynamic query

New Member 投稿: 15 参加年月日: 11/01/20 最新の投稿
I'm running 6.0.6 and "ilike(..)" is not available for me.

I get the following error when trying to use it as well.


Caused by: java.lang.Error: Unresolved compilation problem:
        The method ilike(String) is undefined for the type Property


When looking through Liferay i am using the following.

// Compiled from DynamicQueryFactoryUtil.java (version 1.5 : 49.0, super bit)



Anyone out there can help?


Aritz Galdos:
Hi,

Did you try ilike instead of like? (note "I" before like)

It stands for Insensitive like

Hope It helps!
thumbnail
13年前 に Hitoshi Ozawa によって更新されました。

RE: Case sensitive Dynamic query

Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
Is your database case sensitive? There should be a message about this in the console when starting up Liferay.

Also, pasting your code would help.
thumbnail
13年前 に Michael Charles によって更新されました。

RE: Case sensitive Dynamic query

New Member 投稿: 15 参加年月日: 11/01/20 最新の投稿
In the line below "PropertyFactoryUtil.forName("EngTask.taskDescription").like" is where I'd like it to be case insensitive. Thanks in advanced for your help.



public List<engtask> getEngTaskList(long groupId, Map<string, string> data) throws SystemException {
		
		
		DynamicQuery query = DynamicQueryFactoryUtil.forClass(EngTask.class, "EngTask");
		
		
		query.add(PropertyFactoryUtil.forName("EngTask.groupId").eq( groupId ));
		
		if(data.containsKey("taskDescription")) {
			query.add(PropertyFactoryUtil.forName("EngTask.taskDescription").like( data.get("taskDescription") ));
		}
		
...
		
		List<engtask> engTaskList = EngTaskLocalServiceUtil.dynamicQuery(query);
		
		return engTaskList;
			
			
	}
</engtask></string,></engtask>
thumbnail
12年前 に Kishore Kumar Singamsetty によって更新されました。

RE: Case sensitive Dynamic query

New Member 投稿: 4 参加年月日: 12/02/01 最新の投稿
the ilike is existing in RestrictionsFactoryUtil, hence use that.

Syntax will be : RestrictionsFactoryUtil.ilike("group.name",tempsearch)