Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Regex and multiple word search
Message
 
 
À
09/07/2009 09:58:19
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01411109
Message ID:
01411151
Vues:
26
>>>This is from my memory, this solution is very clean and easy to implement. And it really works...!
>>>
>>>lcTextToFind='mouse trap living toom'
>>>lcWord=GetWordNum(lcTextToFind,1)
>>>Select * from yourtable where lcWord$yourfield into cursor curdummy readwrite 
>>>if _tally>0 and GetWordCount(lcTextToFind)>1
>>>   For lnX=2 to GetWordCount(lcTextToFind)
>>>      lcWord=GetWordNum(lcTextToFind,lnX)
>>>      Select * from curDummy where lcWord$yourfield into cursor curdummy readwrite
>>>   EndFor 
>>>EndIf
>>>
>>>
>>
>>Hi Tore,
>>
>>Just curious, if you have time, could you please compare this solution with Borislav's solution on big tables and see which one would outperform?
>>
>>Also, I'm guessing, you need to add spaces before and after if we want to check for the word, not the part of the word. That's minor detail, though.
>
>This a very different job than the thread you refer to. This solution is usable where you want to find all records where one or more words are inside a field. I use $, but it may be possible that AT() or some other funcion is faster.

I don't see that much of a difference.
Create cursor WordsToSearch(Word C(50))

insert into WordsToSearch values ('Word1')
insert into WordsToSearch values ('Another Word')
insert into WordsToSearch values ('Yet another')
lnI = 0
scan
  lnI = lnI + 1
  
   lcWord = ' ' + WordsToSearch.Word + ' '
   if lnI = 1
    select * from myTable where ' ' + myFieldToSearch + '  '  LIKE '%' + lcWord + '%' into cursor OurTempResult nofilter
   else
        select * from OurTempResult where ' ' + myFieldToSearch + '  '  LIKE '%' + lcWord + '%' into cursor OurTempResult nofilter
    endif
   ** Or alternatively

       select * from myTable where lcWord $ '  ' + myFieldToSearch + '  '
endscan
vs. one Select solution. (this is from the top of my head - your idea of searching for each word in a loop)
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform