Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- FAST TEXT SEARCH for Clipper v.2.0 - <b>searching multiple fields</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   Searching Multiple Fields

   Using CFTS to search multiple fields solves the problem of finding 
   items in a .DBF when you do not know with certainty in which field the 
   data is to be found. For example, imagine a file in which four fields 
   have been reserved for medical diagnoses. Each field contains a 
   diagnosis. To find all records containing the diagnosis heart disease 
   without using CFTS you would probably resort to a slow sequential 
   search using the LOCATE command.

   locate for upper( diag1 ) = heart disease
   .or. upper( diag2 ) = heart disease
   .or. upper( diag3 ) = heart disease
   .or. upper( diag4 ) = heart disease

   In contrast, CFTS provides a quick solution. Assuming you create an 
   index consisting of all the fields you intend to search by 
   concatenating the fields;

   trim( diag1 ) + trim( diag2 ) + trim( diag3 ) + trim( diag4)

   and then passing the resulting string to CftsAdd(); a search for all 
   instances of heart disease becomes:

   use diagnos
   xhandle = CftsOpen(diag.ia, 10 , .T.)
   tstring = heart disease
   CftsSet( xhandle,srchtstring )
   xrec = CftsNext( xhandle )          && get first hit
   do while xrec > 0                   && get all the records 
       goto xrec                       && get record in .DBF 
       sstring = trim(diag1)+" "+trim(diag2)+" "+trim(diag3)+" "+trim(diag4)
       if CftsVeri( xhandle, sstring, tstring, 3 ) = 1
           .
           < process verified hit >
           .
       endif
       xrec = CftsNext( xhandle )      && get next 'hit'
   enddo

   Although the code is somewhat more complicated than using LOCATE, 
   CFTS's speed and generality lets you create applications that are 
   easier to use and which certainly execute much more quickly.


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson