RE: Searching a full name
RE: Searching a full name
- Subject: RE: Searching a full name
- From: <email@hidden>
- Date: Mon, 27 Sep 2004 14:14:24 +0200
- Thread-topic: Searching a full name
Jonathan,
I don't get what you are trying to achieve using the NSArray. You are pulling out values in the exact same order you put them in. The way I read it, your code is equivalent to the following:
StringTokenizer st = new StringTokenizer(allFields, " ," );
try {
if (st.hasMoreTokens()) {
takeValueForKey(tkn, "firstName");
}
if (st.hasMoreTokens()) {
takeValueForKey(tkn, "lastName");
}
}
catch(Exception e){
NSLog.out.appendln("===\r show me what happened!!!");
e.printStackTrace();
}
You are thus missing out on any token beyond the second one. Thus my suggestion:
int commaIndex = allFields.indexOf(',');
NSMutableArray couples = new NSMutableArray();
if (commaIndex > 0)
{
couples.addObject(
new String[] {
allFields.substring(0, commaIndex),
allFields.substring(commaIndex + 1, allFields.length())
}
);
}
else
{
NSArray words = NSArray.componentsSeparatedByString(allFields, " ");
int count = words.count();
for (int = 0; i < count - 1; i++)
{
StringBuffer one = new StringBuffer();
StringBuffer two = new StringBuffer();
for (int j = 0; j < i; j++)
{
if (j > 0)
{
one.append(" ");
}
one.append(words.objectAtIndex(j);
}
for (int j = i; j < count; j++)
{
if (j > 0)
{
two.append(" ");
}
two.append(words.objectAtIndex(j);
}
couples.addObject(
new String[] {
one.toString(),
two.toString()
}
);
}
}
int cCount = couples.count();
NSMutableArray qualifiers = new NSMutableArray(cCount * 2);
for (int c = 0; c < cCount; c++)
{
String[] couple = (String[]) couples.objectAtIndex(c);
EOQualifier variantOne = new EOAndQualifier(new NSArray(new EOQualifier[] {
new EOKeyValueQualifier(
"firstName",
EOQualifier.QualifierOperatorCaseInsensitiveLike,
couple[0]),
new EOKeyValueQualifier(
"lastName",
EOQualifier.QualifierOperatorCaseInsensitiveLike,
couple[1])
}));
EOQualifier variantTow = new EOAndQualifier(new NSArray(new EOQualifier[] {
new EOKeyValueQualifier(
"firstName",
EOQualifier.QualifierOperatorCaseInsensitiveLike,
couple[1]),
new EOKeyValueQualifier(
"lastName",
EOQualifier.QualifierOperatorCaseInsensitiveLike,
couple[0])
}));
qualifiers.addObject(variantOne);
qualifiers.addObject(variantTwo);
}
return new EOOrQualifier(qualifiers);
Back to work.
Pierre
P.S: There might be odd cases like having two commas in the search string, or a wild card not attached to any word...
-----Original Message-----
From: Jonathan Fleming [mailto:email@hidden]
Sent: Monday, September 27, 2004 12:39 PM
To: Pierre Bernard
Cc: email@hidden
Subject: RE: Searching a full name
Hi Pierre,
Thanks for your response.
What I have ended up doing on the java side. I've used an NSMutableArray
because I can get the tokens in, in order (left to right), whereas the token
count or index system seems to go right to left:
NSMutableArray searchTokens = new NSMutableArray();
StringTokenizer st = new StringTokenizer(allFields, " ," );
try {
while (st.hasMoreTokens()) {
searchTokens.addObject(st.nextToken());
}
NSLog.out.appendln("===\r... searchTokens mutable array " +
searchTokens);
for (int index=0; index<searchTokens.count(); index++)
{
String tkn =
String.valueOf(searchTokens.objectAtIndex(index));
if (index==0)takeValueForKey(tkn, "firstName");
if (index==1)takeValueForKey(tkn, "lastName");
}
}
catch(Exception e){
NSLog.out.appendln("===\r show me what happened!!!");
e.printStackTrace();
}
NSLog.out.appendln("===\r first two words populating name
fields\r"+
" firstName = "+firstName+"\r"+
" lastName = "+lastName);
...
As for the qualifier issue, I suppose I best just hard code in four
container variables to be safe and have them search for either first or last
names... As for the whitespace and comma issue, StringTokenizer is sorting that out through the delimiter constructor.
If you or any one has any better suggestions for doing this sort of thing, I'd like to learn of them
Kind regards
Jonathan :^)
>From: <email@hidden>
>To: <email@hidden>, <email@hidden>
>CC: <email@hidden>
>Subject: RE: Searching a full name
>Date: Mon, 27 Sep 2004 11:36:33 +0200
>
>Jonathan,
>
>Java question: you are calling st.nextToken() repeatedly in your loop and >thus skipping tokens.
>
> while (st.hasMoreTokens()) {
> String token = st.nextToken();
> NSLog.out.appendln("===\r"+ token +
> "... token index = "
>+st.countTokens());
> if (st.countTokens()==1) takeValueForKey(token, >"firstName");
> if (st.countTokens()==2) takeValueForKey(token, >"lastName");
> }
>
>Root question: I think you'll have to account for the possibility of names >including spaces. Thus "word1 word2 word3" would turn into a query like >this:
>
>(firstName like 'word1 word2 word3)) or
>((firstName like 'word1') and (lastName like 'word2 word3')) or
>((firstName like 'word1 word2') and (lastName like 'word3')) or
>(lastName like 'word1 word2 word3') or
>((firstName like 'word3') and (lastName like 'word1 word2')) or
>((firstName like 'word2 word3') and (lastName like 'word1'))
>
>If you get a comma in the input you'd have an obvious separator: "word1
>word2, word3 word4"
>
>((firstName like 'word1 word2') and (lastName like 'word3 word4')) or
>((firstName like 'word3 word4') and (lastName like 'word1 word2'))
>
>Just my 2 cents.
>
>Pierre
>
>-----Original Message-----
>From: webobjects-dev-bounces+pierre.bernard=email@hidden
>[mailto:webobjects-dev-bounces+pierre.bernard=email@hidden]On
>Behalf Of Jonathan Fleming
>Sent: Sunday, September 26, 2004 2:29 PM
>To: email@hidden
>Cc: email@hidden
>Subject: Re: Searching a full name
>
>
>Hi William,
>I've done what was needed but I have a tiny problem that comes down to my >lack of knoledge of the Java Classes I think: I want to populate the first
>and last name iVars but this code isn't doing that too well... populates >one
>but not the other.
>
>Any ideas?
>
> StringTokenizer st = new StringTokenizer(allFields, " ," );
> try {
> while (st.hasMoreTokens()) {
> NSLog.out.appendln("===\r"+ st.nextToken() +
> "... token index = "
>+st.countTokens());
> if (st.countTokens()==1)
>takeValueForKey(st.nextToken(),
>"firstName");
> if (st.countTokens()==2)
>takeValueForKey(st.nextToken(),
>"lastName");
> }
> }
> catch(Exception e){
> NSLog.out.appendln("===\r show me what happened!!!");
> e.printStackTrace();
> }
>
>
>TIA Jonathan :^)
>
>
> >From: William Norris <email@hidden>
> >Reply-To: William Norris <email@hidden>
> >To: Jonathan Fleming <email@hidden>, "WebObjects (Group)"
> ><email@hidden>
> >Subject: Re: Searching a full name
> >Date: Sat, 25 Sep 2004 13:19:17 -0500
> >
> >On Sat, 25 Sep 2004 18:48:56 +0100, Jonathan Fleming
> ><email@hidden> wrote:
> >it's this what is my problem:
> > > ((firstName like $tradingName) and (lastName like $tradingName)) but
> >could
> > > make it function correctly so started to add the whitespace column but
>I
> > > know for sure that I'm doing something seriously back to front, I just
> >cant
> > > think so... I need someone's fresh head 'cause mine's is still awash
> >with
> > > sleep deprivationform this week.... silly me.
> >
> >
> >(I'm guessing you have a single input box where the user can enter
> >their full name). When the form is submitted, $tradingName
> >potentially holds two pieces of information -- both the user's
> >firstname as well as their last name. The easiest (and probably most
> >logical) thing to do would be to split $tradingName wherever their is
> >a whitespace and treat each substring as an individual token. They
> >might have entered last name first, so you'll want to check each token
> >against each database field.
> >
> >for example, if $tradingName had one space in it, and you split it
> >into two strings, $tn1 and $tn2, your qualifier would look something
> >like... (((firstName like $tn1) or (lastName like $tn1)) and
> >((firstName like $tn2) or (lastName like $tn2))).
> >
> >This could (and probably should) be expanded a bit to account for
> >multiple spaces, commas between last and first name, etc.
>
>_________________________________________________________________
>It's fast, it's easy and it's free. Get MSN Messenger today!
>http://www.msn.co.uk/messenger
>
> _______________________________________________
>Do not post admin requests to the list. They will be ignored.
>Webobjects-dev mailing list (email@hidden)
>Help/Unsubscribe/Update your Subscription:
>
>This email sent to email@hidden
>
>
>**********************************************************************
>This email and any files transmitted with it are intended solely for
>the use of the individual or entity to whom they are addressed.
>If you have received this email in error please notify the sender
>of this message. (email@hidden)
>This email message has been checked for the presence of computer
>viruses; however this protection does not ensure this message is
>virus free.
>Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
>**********************************************************************
>
_________________________________________________________________
Want to block unwanted pop-ups? Download the free MSN Toolbar now!
http://toolbar.msn.co.uk/
**********************************************************************
This email and any files transmitted with it are intended solely for
the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the sender
of this message. (email@hidden)
This email message has been checked for the presence of computer
viruses; however this protection does not ensure this message is
virus free.
Banque centrale du Luxembourg; Tel ++352-4774-1; http://www.bcl.lu
**********************************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden