View Full Version : Trying to search a .dat w/keywords
Animl
09-25-2006, 12:24 AM
Ran into a snag, as usual. :)
My lame search process.
I have a .dat file which contains some info, I don't think it's worthy of sqlite.
Currently, I get Data from a combobox selection.
Then the data (single word) is used in a String.Find process.
It searches the value names of the .dat file and if the word is found that value name (title) and it's data is added to anther combobox.
My problem is, beside the basic design, is that using only one word it limits the search results of the dat file. Using more then one word in the Data slot of the first combobox also causes limitations.
What I think I should do is put a deliminated string of keywords in the data slot. BUT I can't seem to get the DelimitedStringToTable to work so I can cycle through each keyword. I keep getting errors using the script provided in ams. (scatches head)
Any help, or new ideas, would be appreciated :)
TJ_Tigger
09-25-2006, 07:54 AM
What code are you using currently to perform your search? If you have a delimited string of words and you want to search that string for a key work you don't need to parse it to a table to be able to search it, you can you String.Find to see if your keyword exists in that string.
HTH
Tigg
Animl
09-25-2006, 04:02 PM
What code are you using currently to perform your search? If you have a delimited string of words and you want to search that string for a key work you don't need to parse it to a table to be able to search it, you can you String.Find to see if your keyword exists in that string.
HTH
Tigg
Exactly what I am doing. But if I only use one word it misses a lot of other results. If I use more then one word it searchs for it as a phrase and misses a lot of results. So in my mind it needs to have search for each keyword separately to be accurate. Which is why I was thinking of running through a deliminated string. For some reason I could get that to work.
Maybe it is a job for SQlite?
TJ_Tigger
09-25-2006, 04:44 PM
You could use SQLite, might make searches easier but you can use loops to do the same thing.
for i,v in sectionsfromdat do
for ii,vv in searchwords do
if String.Find(v, vv, 1) ~= -1 then
--was found mark it somehow maybe by putting it in another table
break
end
end
Something like the above would have a table of all the lines you wanted to search from the .dat file. Whether this is an ini or a text file. Then for each line in that file or the returned table, it will look through your search words. If one is found then you will need to mark it somehow maybe by putting it in another table that you can look at later.
HTH
Tigg
P.S. If you can provide a copy of the file I can try to help with a working example.
Can you post the structure of your .dat file?
If your .dat file is just being used to store value pairs, it might be better to follow the .ini format. That way you could use the built-in AMS actions to search just the value names.
If you had a dat file that looked like this:
[Root]
Test One=some data...
Test Two=some data....
Test Three=some data.....
Test Four=some data......
Your code would look something like this (assuming you have added the "DelimitedStringToTable" function to your Global Functions and you are using listboxes to display the results.):
INI = "\\autoplay\\docs\\SearchMe.dat";
-- clear the listboxes
ListBox.DeleteItem("ListBox1", -1);
ListBox.DeleteItem("ListBox2", -1);
-- Get the Value Names from the dat file
tbl_ValueNames = INIFile.GetValueNames(INI, "Root");
-- Break the search text into individual words
tbl_Search = DelimitedStringToTable(Input.GetText("Input1"), " ");
-- Step through the Value Names
for index, value in tbl_ValueNames do
-- for each Value Name, search for each search word
for index1, word in tbl_Search do
WordFound = nil;
WordFound = String.Find(value, word, 1, false);
if WordFound > -1 then
-- If found write the value name to the listbox
ListBox.AddItem("ListBox1", value, "");
-- And write the corresponding value to the listbox
ListBox.AddItem("ListBox2", INIFile.GetValue(INI, "Root", value), "");
end
end
end
Animl
09-25-2006, 06:09 PM
My Dat file is setup exactly how you posted.
I'm trying to get a resizing script working, then going to try your idea. It sound and looks like it's what I need to do.
Thanks for your time and reply.
"I'll be back" :)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.