Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Search Suggestions
Message
 
À
01/07/2004 08:14:24
Steven Dyke
Safran Seats USA
Texas, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00919578
Message ID:
00919743
Vues:
7
>I need some advise on a search soultion.
>
>The user will put a specifc description of an item in the database(memo field).
>Example: BASEFRAME OFFSET F/R DBL 40.6
>Example: BASEFRAME F/R DBL 40.6
>Example: BASEFRAME F/R TPL 40.6
>
>Now I need to set up a search function that the user can type any part of the description or some combination and get the results.
>
>Any ideas?

I did something like this for a client. I give them a textbox in which to type their search string. Then there's an option group in which they specify if they want results that contain all of the words or any of the words. There's also an option to pick which field the search is for. Here's the code that does the search:
LOCAL lnWordCount, lnI, lcWords, lcFiltCond, lcFieldName

IF thisform.opgFields.Visible AND thisform.opgFields.Value <> 0 AND NOT EMPTY(ALLTRIM(thisform.txtKeywords.Value))
   * Put each keyword entered into an array
   lcWords = UPPER(ALLTRIM(thisform.txtKeywords.Value))
   lnWordCount = OCCURS(' ',lcWords)+1
   DIMENSION laWords[lnWordCount]
   IF lnWordCount = 1
      laWords[1] = lcWords
   ELSE
      FOR lnI = 1 TO lnWordCount
         IF lnI = 1
            laWords[lnI] = LEFT(lcWords,AT(' ',lcWords)-1)
         ELSE 
            laWords[lnI] = STREXTRACT(lcWords,' ',' ',lnI-1,2)
         ENDIF 
      ENDFOR 
   ENDIF

   * Figure out which field we're filtering on
   lcFieldName = thisform.aFields[thisform.opgFields.Value]
	
   * Build the filter condition
   lcFiltCond = ''
   FOR lnI = 1 TO lnWordCount
      IF thisform.opgKeywords.Value = 1		&& All keywords
         IF lnI > 1
            lcFiltCond = lcFiltCond+" and "
         ENDIF
      ELSE       && Any keyword
         IF lnI > 1
            lcFiltCond = lcFiltCond+" or "
         ENDIF
      ENDIF
      DO CASE 
      CASE TYPE(lcFieldName) = "C"
         lcFiltCond = lcFiltCond+"["+laWords[lni]+"] $ UPPER("+lcFieldName+")"
      CASE TYPE(lcFieldName) = "N"
         lcFiltCond = lcFiltCond++laWords[lni]+" = "+lcFieldName+" OR "+lcFieldName+" = "+laWords[lni]
      ENDCASE 
   ENDFOR
	
   SET FILTER TO &lcFiltCond
   COUNT TO lnI
   WAIT WINDOW NOWAIT TRANSFORM(lnI)+" records met your filter criteria" TIMEOUT 5
   GOTO TOP
   RETURN .T.
ELSE
   RETURN .F.
ENDIF
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform