Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search with / without didractis signs. 2

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,

I would like to have a search procedure which will find names even if they have diactric signs,

So when I search for Aäron, I would like to find Aaron Cohen and also Aäron Baruch,
an when I search for Aaron, I would like to find Aaron Cohen and also Aäron Baruch
and the best thing would be to have a setting which would find only the Aäron Baruch for a search on Aäron

I cant think of anything else than to put an extra field in my dbf where the names are without the diactric signs, also believe there should be a procedure to accomplish this, only how?

Stay healthy,

Koen
 
You could search for something like

Code:
locate for upper(strtran(m.MySearch,"ä","a"))$upper(strtran(MyTable.MySearchField,"ä","a"))

That would work

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Koen,

I think you will find that SYS(15), in conjunction with EUROPEAN.MEM, will do exactly what you want.

EDIT: I just checked the Help for SYS(15), and I see it is flagged "for backward compatibility". It says to use SET COLLATE instead. But I'm not sure that will do what you want. Setting the collating sequence doesn't necessarily allow you to search form Aäron and find Aaron.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
GriffMG
Dont be mistaken my Aäron was just an example,
We have áàä and than for aeiou and ç also lucky I dont have scandinavians in my dbf :) I believe your solution is a lengthy one. Will try with Mike's proposal.
Sorry Mike the Set Collate does not help with this.
Stay healthy,
Koen
 
So using SYS(15) you would restore european.mem additively, then search like this:

Code:
locate for upper(sys(15,european,m.MySearch))$upper(sys(15,european,MyTable.MySearchField))

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Griff,

That errors "variable European" is not found.

So I followed the Help
And I gave
Code:
INDEX ON SYS(15, european, Fullname) TO european
MYsEARCH = "Joël"
locate for upper(sys(15,EUROPEAN,m.MySearch))$upper(sys(15,european,Names.Fullname))
still variable not not found ;)
Stay healthy,
Koen

P.S. I do have a european.mem file on my HD, in the VFP default folder dated from back 2004 and several others from earlier dates. Have also copied one to the folder where my data resides, no luck
 
You need to find the mem file, and restore it additively
Code:
RESTORE FROM (HOME()+"european.mem") ADDITIVE

That will add a variable EUROPEAN to your variables.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
You know what, that doesn't seem to work at all, not the restore, that works, the comparison using Sys(15)

Code:
? "Aaron"$SYS(15,european,"Aäron")

Yields false.

I think you would need a function of your own. I will investigate further.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
This works:

Code:
FUNCTION ANGLISIZE
	PARAMETERS m.STRING
	PRIVATE m.STRING
	m.STRING = CHRTRAN(m.STRING,"ÀÁÂÃÄÅÆ","AAAAAAA")
	m.STRING = CHRTRAN(m.STRING,"Ç","C")
	m.STRING = CHRTRAN(m.STRING,"ÈÉÊË","EEEE")
	m.STRING = CHRTRAN(m.STRING,"ÌÍÎÏÐÑ","IIIIII")
	m.STRING = CHRTRAN(m.STRING,"ÒÓÔÕÖ×Ø","OOOOOOO")
	m.STRING = CHRTRAN(m.STRING,"ÙÚÛÜÝÞß","UUUUUUU")

	m.STRING = CHRTRAN(m.STRING,"àáâãäåæ","aaaaaaa")
	m.STRING = CHRTRAN(m.STRING,"ç","c")
	m.STRING = CHRTRAN(m.STRING,"èéêë","eeee")
	m.STRING = CHRTRAN(m.STRING,"ìíîïðñ","iiiiii")
	m.STRING = CHRTRAN(m.STRING,"òóôõö÷ø","ooooooo")
	m.STRING = CHRTRAN(m.STRING,"ùúûüýþÿ","uuuuuuu")

RETURN(m.STRING)

Oddly TT is messing with the code slightly, you may need to handball the Ò etc..

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
FUNCTION ANGLISIZE
PARAMETERS m.STRING
PRIVATE m.STRING
m.STRING = CHRTRAN(m.STRING,"ÀÁÂÃÄÅÆ","AAAAAAA")
m.STRING = CHRTRAN(m.STRING,"Ç","C")
m.STRING = CHRTRAN(m.STRING,"ÈÉÊË","EEEE")
m.STRING = CHRTRAN(m.STRING,"ÌÍÎÏÐÑ","IIIIII")
m.STRING = CHRTRAN(m.STRING,"ÒÓÔÕÖ×Ø","OOOOOOO")
m.STRING = CHRTRAN(m.STRING,"ÙÚÛÜÝÞß","UUUUUUU")

m.STRING = CHRTRAN(m.STRING,"àáâãäåæ","aaaaaaa")
m.STRING = CHRTRAN(m.STRING,"ç","c")
m.STRING = CHRTRAN(m.STRING,"èéêë","eeee")
m.STRING = CHRTRAN(m.STRING,"ìíîïðñ","iiiiii")
m.STRING = CHRTRAN(m.STRING,"òóôõö÷ø","ooooooo")
m.STRING = CHRTRAN(m.STRING,"ùúûüýþÿ","uuuuuuu")

RETURN(m.STRING)

It should have looked like the above
Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Griff,

Hmmm no luck,

Code:
RESTORE FROM (HOME()+"european.mem") ADDITIVE
MYSEARCH = "Joel"
locate for upper(sys(15,EUROPEAN,m.MySearch))$upper(sys(15,european,Names.Fullname))

gives an eof, I do have a Joël in my dbf
Stay healty
Koen
 
It (SYS(15)) does not seem to do anything, it returns whatever you give it... not sure it would help in an index expression.

The ANGLISIZE() above function works though.

Code:
locate for upper(ANGLISIZE(m.MySearch))$upper(ANGLISIZE(Names.Fullname))


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Yes, I've been trying to get SYS(15) to work as well. It's not working exactly as I understood it. Apologies if I've led you down the wrong path.

Griff, the ANGLISIZE() function looks interesting, but where does it come from? It's not part of VFP.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I wrote it this afternoon, the code is above.
I took the symbols to change from the european variable in european.mem and just guessed what each one should be in english.
So long as the function is visible at runtime, you could index on it.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
for backward compatibility" is probably a clue that it doesn't work

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
OK, here's another idea:

Code:
lcAccents = CHR(192) + CHR(193) + CHR(194) + CHR(195) + CHR(196) + CHR(197) + ;  && Cap A
  CHR(200) + CHR(201) + CHR(202) + CHR(203) + ;                                  && Cap E
  CHR(224) + CHR(225) + CHR(226) + CHR(227) + CHR(228) + CHR(229) + ;            && l.c. a
  CHR(232) + CHR(233) + CHR(234) + CHR(235)                                      && l.c. e
  
lcMask = "AAAAAAEEEEaaaaaaeeee"

LOCATE FOR ALLTRIM(CHRTRAN(MyField, lcAccents, lcMask)) = "Aäron"

This only handles capital A and E and lower-case a and e so far, but it can obviously be extended to handle the rest to the alphabet. I haven't tested it yet, but will do so soon.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hmmm

I don't think your locate will find anything...

LOCATE FOR ALLTRIM(CHRTRAN(MyField, lcAccents, lcMask)) = "Aäron"

this would

LOCATE FOR ALLTRIM(CHRTRAN(MyField, lcAccents, lcMask)) = "Aaron"

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
SYS(15) only handles the problem of sorting letters with diacritics to the similar letters without, so indeed for the case of exact/inexact search this doesn't help.

COLLATIONS also only address that problem, so they are the modern sys(15) version, but both solutions don't address finding ä for a, too. not just better sorting it. So it will sort Jöel as if it was Joel, but not find Joel if there only is Jöel.

SYS(15) does not work for me either, it does not change the string, it may be made for another codepage than 1252, perhaps DOS codepage?

The way a collation sorts should become clear by the example:
Code:
Create Cursor curNames( cName C(20))
Insert into curNames values ('Jöel')
Insert into curNames values ('July')
Insert into curNames values ('Jacob')
Set Collate To "MACHINE" && default
Index On cName Tag machName
Set Collate To "DUTCH"
Index On cName Tag dutchName
browse

Now Jöel is sorted between Jacob and July as if it was Joel. But locate for cName='Joel' won't find Jöel, that was neither a function of Sys(15) nor of collations.

Besides collations being the better solution than sys(15) for the sorting matter, any collation other than machine isn't used by Rushmore optimization, IIRC, or at least not if the general collation setting is machine. And you don't want to index integers in some collation other than machine, at least there once was a bug that affected correct numeric sorting then, as the 4 bytes of an int were treated as if they were ASCII characters, which then led to resorting.

I think Griffs translation function will do the job you need better.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top