Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Retrive words from a string and compare

Posted on 2003-11-28
7
Medium Priority
?
229 Views
Last Modified: 2012-05-07
FILENAME       KEYWORD
xxx.doc      abc,caa,funny
xyz.txt      abc,cba,funnys
sdfetll.txt      ball,basketball,players,court,
d.doc      bryan,name,hobbies,male,boy

above is a datasets, fields are filename,keyword. store in a ms access table. both filename and keyword fields are string.   i.e.   'xxx.doc'  is a string,  'abc,caa,funny' is a string

if a user input "abc", the program should return filename associated with it , i.e.  xxx.doc and xyz.txt

since the datasets may be very large, the algorithim to retrive the keywords from keyword string and then compare in order to get the associated filename should be efficient.

anyone has the script or can provide some idea? like what data types., method i should use....etc

thank you for enlightening.

0
Comment
Question by:plovel
  • 4
  • 2
7 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 9837867
hi, plovel :)
just use SQL:
SELECT FILENAME FROM TABLE1 WHERE ','+KEYWORD+',' LIKE '%,abc,%'

delphi example:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ADOQuery1.SQL.Text := 'SELECT FILENAME FROM TABLE2 WHERE '',''+KEYWORD+'','' LIKE ''%,'
    + Edit1.Text + ',%''';
  ADOQuery1.Open;
  if ADOQuery1.RecordCount = 0 then
    ShowMessage('No result found!')
  else
    ShowMessage('FileName: '+ ADOQuery1.FieldByName('FILENAME').AsString);
  ADOQuery1.Close;
end;

wbr, mo.
0
 
LVL 9

Expert Comment

by:mocarts
ID: 9837893
caution - you must check for empty search string, otherwise you will get all records where KEYWORD field ends with comma.
0
 
LVL 3

Expert Comment

by:ahll
ID: 9838061
I agree with mocarts, but you have to include in the KEYWORD field a comma at the beginind and at the end. If not, you will lose the first and the last word.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
mocarts earned 600 total points
ID: 9838129
not actually - that can be overcome in SQL by "quoting" keyword field in commas - what is actually done in my example.
SELECT FILENAME FROM TABLE1 WHERE ','+KEYWORD+',' LIKE '%,abc,%'

also comment to my example - plovel - you should additionally implement loop (while not eof) for retrieving all selected records (filenames):
var
  sFiles: string;
begin
...
 ADOQuery1.Open;
  if ADOQuery1.RecordCount = 0 then
    ShowMessage('No result found!')
  else begin
    while not ADOQuery1.eof do begin
      sFIles := sFiles + ',' + ADOQuery1.FieldByName('FILENAME').AsString;
      ADOQuery1.Next;
    end;
    if sFiles <> '' then Delete(sFiles, 1);
    ShowMessage(sFiles);
  end;
...
0
 
LVL 1

Expert Comment

by:cerdal
ID: 9887682
You'd have much faster access if you split the list up and inserted one record for each keyword. That way you could just do a straight "select filename from Table1 where keyword = :MyKeyWord".

If the table has other fields in it, which would mean too many duplicates, add an AutoIncrement field to Table1 and fill a second table with KeyWord + Tbl1AutoIncValue in Table1's AfterPost event. You could then do:

Select TABLENAME from TABLE1, TABLE2
Where TABLE2.KEYWORD = :MyKeyWord
And TABLE1.AutoIncValue = TABLE2.Tbl1AutoIncValue

If you need more detail, just ask.

Chris.
0
 
LVL 9

Expert Comment

by:mocarts
ID: 9965421
thanks, plovel :)
small comment on Chris comment..
that will be only a little bit faster, but will take more room to store all data. and if to be truly formal then there must be three tables - one for keywords, one for filenames and last one to link previous tables i.e.
Kyeword table (KT): IDKeyword, Keyword
Filename table (FT): IDFile, FileName
Link table (LT): IDKeyword, IDFile
and select would be SELECT FT.FileName FROM FT, KT, LT WHERE FT.IDFile=LT.IDFile AND KT.IDKeyword=LT.IDKeyword AND KT.Keyword = 'KeywordToSearch'

wbr, mo.
0
 
LVL 1

Expert Comment

by:cerdal
ID: 9967993
reply to mo:

pragmatism is always best :-) If it's good enough, do it that way.

it's another case of horses for courses - I've never worked with Access, but some databases can be orders of magnitude slower matching parts of a field (even if it's indexed) in every record from start to finish rather than going straight to the only ones whose keyfield matches what's needed exactly.

It might be an idea for plovel to compare the 2 methods and let us know how much faster it actually is in his situation...

As for the extent of normalising that's required, I agree it's pretty rare to find a case where 100% is optimum.

Chris.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question