Reduce by search: using multiple items you wish to exclude?

Questions, tips and tricks and techniques for scripting in Servoy

Reduce by search: using multiple items you wish to exclude?

Postby paulc » Thu Feb 25, 2010 12:06 am

Hi

I searched the forums and the user manual and not seen an example of how I can perform a search for items with a criteria I don't want.

eg I have a list of 5 records. I want to perform a search for items that aren't 2 and 4.
PID
1
2
3
4
5

I can use !2 to reduce the list to
PID
1
3
4
5

What I can't figure out is how to incorporate the other criteria. I have tried the following...all of which don't work...
!2||!4
!(2||4)
Last edited by paulc on Thu Feb 25, 2010 7:38 pm, edited 1 time in total.
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: How do you search for items not in a list your foundset?

Postby ptalbot » Thu Feb 25, 2010 1:02 am

Don't know either but have you tried
!2&&!4 maybe?

Otherwise you will have to make a second search to restrain the foundset.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1659
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: How do you search for items not in a list your foundset?

Postby paulc » Thu Feb 25, 2010 7:22 pm

hello ptalbot,

thanks for the info. I ended up going with a second search to filter out the other option. Doesn't seem like the most efficient method, but it works for now.

If you have any other suggestions, I would be really happy to hear them.

Thank you
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: Reduce by search: using multiple items you wish to exclude?

Postby jcompagner » Fri Feb 26, 2010 12:17 am

i think there is another way with just one query..

use foundset.addFoundSetFilterParam(dataprovider, "not in", new Array(2,4), "notin");

but then you have to remember that after that you have to remove it...

foundset.removeFoundSetFilterParam("notin");

but it could be nice that you also have this support in normal find mode.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8884
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Reduce by search: using multiple items you wish to exclude?

Postby rgansevles » Fri Feb 26, 2010 1:04 pm

Another option may be to use invertRecords:

Code: Select all
if (foundset.find()
{
   pid = 2
   foundset.newRecord()
   pid = 5   
   foundset.search() // 2||5
   foundset.invertRecords()  // !(2||5)
}


It does have the disadvantage of a double query.

If you want you can file a feature request for support of something like !(2||5) directly.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1929
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Reduce by search: using multiple items you wish to exclude?

Postby ptalbot » Fri Feb 26, 2010 3:43 pm

rgansevles wrote:Another option may be to use invertRecords:

Code: Select all
if (foundset.find()
{
   pid = 2
   foundset.newRecord()
   pid = 5   
   foundset.search() // 2||5
   foundset.invertRecords()  // !(2||5)
}


It does have the disadvantage of a double query.

If you want you can file a feature request for support of something like !(2||5) directly.

Rob

Then you can do this:
Code: Select all
if (foundset.find()
{
   pid = "2||5'";
   foundset.search(); // 2||5
   foundset.invertRecords();  // !(2||5)
}

don't you? No double query!
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1659
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Reduce by search: using multiple items you wish to exclude?

Postby rgansevles » Fri Feb 26, 2010 3:47 pm

Patrick,

That is the same as my code.

The first query is triggered by the search() call, the second by the invertRecords() call.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1929
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Reduce by search: using multiple items you wish to exclude?

Postby ptalbot » Fri Feb 26, 2010 3:55 pm

rgansevles wrote:Patrick,

That is the same as my code.

The first query is triggered by the search() call, the second by the invertRecords() call.

Rob

Silly me :roll:
Thanks for clarifying!
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1659
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Reduce by search: using multiple items you wish to exclude?

Postby paulc » Mon Mar 01, 2010 8:27 pm

HI
thanks for the posts. I went to try the suggestions, but I run into an issue where the user has already provided another filter. I failed to mention that the user will now have another filter they can set and the invert records method will return the inverted records of the other filter parameter as well.

eg I have a list of 5 records. I want to perform a search for items where pid != 2, 4 and category = 2,3.
PID Category
1 1
2 2
3 2
4 3
5 2

I can use !2 to reduce the list to
PID
1
3
4
5

OR
I can use PID = !2 and category = 2||3to reduce the list to
3
4
5

What I can't figure out is how to incorporate the other criteria. I have tried the following...all of which don't work...
!2||!4
!(2||4)
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: Reduce by search: using multiple items you wish to exclude?

Postby rgansevles » Mon Mar 01, 2010 8:46 pm

You can use some combinations with invertrecords() and search(clearLastResults=false) but that may get very hairy very quickly.

Code: Select all
if (foundset.find())
{
   pid = '2||5'
   foundset.search()
   foundset.invertRecords()  // pid = !(2||5)
   foundset.find()
   category = '2||3'
   foundset.search(false, true) // pid = !(2||5) && category = 2||3
}


As i said, quite hairy...

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1929
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Reduce by search: using multiple items you wish to exclude?

Postby victor.rojo » Fri Sep 10, 2010 2:47 pm

jcompagner wrote:use foundset.addFoundSetFilterParam(dataprovider, "not in", new Array(2,4), "notin");


Is the "not in" a valid operator?
I'm trying to use it and doesn´t work...
Best regards/Un saludo,

Victor Rojo
Developer

NeoCursar, S.L. - Developers Team
--
Servoy 5.2.8 - build 1016 / Version: 6.0.2 - build 1222
Mac OS X 10.7
victor.rojo
 
Posts: 74
Joined: Mon Jan 11, 2010 1:49 pm

Re: Reduce by search: using multiple items you wish to exclude?

Postby rgansevles » Fri Sep 10, 2010 6:29 pm

Victor,

This is actually not working correctly, I have fixed that for release 5.2.2.

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1929
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: Reduce by search: using multiple items you wish to exclude?

Postby victor.rojo » Mon Sep 13, 2010 8:22 am

Ok, thanks Rob.
Best regards/Un saludo,

Victor Rojo
Developer

NeoCursar, S.L. - Developers Team
--
Servoy 5.2.8 - build 1016 / Version: 6.0.2 - build 1222
Mac OS X 10.7
victor.rojo
 
Posts: 74
Joined: Mon Jan 11, 2010 1:49 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests