Solved

Retrive words from a string and compare

Posted on 2003-11-28
7
218 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Accepted Solution

by:
mocarts earned 150 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A simple description of email encryption using a secure portal service. This is one of the choices offered by The Email Laundry for email encryption. The other choices are pdf encryption which creates an encrypted pdf of your email and any attachmen…
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now