Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Search expressions
Message
De
17/09/2003 07:23:34
 
 
À
16/09/2003 17:39:43
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00829666
Message ID:
00829783
Vues:
18
>We have an application for our help desk people internal. They want to have it modified to provide a better search solutions. I already talked to them about Regular Expressions and they didn't care for that. They wanted something on how some of the internet searches work. For Example they want to enter
>
>
>(video or display) and blinking
>
>
>I looked at the NORMALIZE function in foxpro which returns
>
>(VIDEO.OR.DISPLAY).AND.BLINKING
>
>
>Since we only have one field that needs to be checked all I would need to change is something like
>
>(ATC('VIDEO', problem)>0.OR.ATC('DISPLAY', problem)>0).AND.ATC('BLINKING',problem)>0
>
>It started to look easy but it's more work than I initaly thinking. Before I take too much time is there something else I could use. API? Website? that would help in converting these types of querys into Foxpro commands.

Chuck,

this should be a starting point.
#define TRUE .t.
#define FALSE .f.
*---------------------------------------------------------------------------
function do_it()

	local Entered, Result
	Entered = '(video or display) and blinking'
	
	if( !Convert(Entered, @Result) )
		? 'Bad expression'
	else
		? Result
                select * from Table where (&Result)
	endif
endfunc
*---------------------------------------------------------------------------
function Convert(src, xx)

	local RegExp, Match, i, s
	RegExp	= CreateObject('VBScript.RegExp')
	RegExp.IgnoreCase = TRUE
	RegExp.Global = TRUE
	RegExp.Pattern = '([_a-zA-Z][_a-zA-Z0-9]*)'
	
	&& (1) Need all the words
	&&     if not in ('and', 'or', 'not')
	&&        change
	
	Match = RegExp.Execute(src)
	for i = Match.Count-1 to 0 step -1
		do case
		case inlist(upper(Match.Item[i].Value), 'AND', 'OR', 'NOT')
			&& skip
		
		otherwise
			s = [!empty(atc('] + Match.Item[i].Value + [', problem))]
			src = stuff(src, Match.Item[i].FirstIndex+1, Match.Item[i].Length, s)
			
		endcase
	endfor
	
	&& (2) check syntax
	private ExprError
	ExprError = FALSE
	s = on('error')
	on error ExprError = TRUE
	xx = normalize(src)
	on error &s
	return !ExprError
	
endfunc
*---------------------------------------------------------------------------
See also http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting051099.asp
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform