32 users online (0 members and 32 guests)  


  Results 1 to 8 of 8

Related

  1. Replies: 0
  2. Help w/ Search Script    Forum: CGI Perl Forum
    Replies: 0
  3. Hello, need help with a script I'm making    Forum: CGI Perl Forum
    Replies: 2
  4. SEARCH script not aligning in table correctly    Forum: Website Scripts Forum
    Replies: 4
  5. Making changes    Forum: HTML Forum
    Replies: 6
  1. #1
    phill2000sta's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    4

    Need help making a search script

    Hiya!

    This is my first post on this site, and I wouldn't say I'm fairly new to Perl, just that I need a little help.

    I've been asked by an owner of a record shop to design him a website with an online stock viewing facility. The type of site where people can search by their favourite artists / tracks to buy vinyl and cd's. Now as this is a small shop and he doesn't wish to go overkill on his first site, he understandably wants to keep the costs down. As the catalogue is no larger than 400 products, we have decided to go along the flat delimited ascii file database, and using Perl to add / modify / delete and search entries.

    I have got the "add new record" and "view database" programs written, and they are working fine, with the exception of a few more additions to be made, but now I have the basis sorted, I have started working on the search facility. I've scoured the Internet for examples on search utilities, but can't seem to get the grasp of this!

    What we are wanting is a search field where people can say for example type in "Michael Jackson" and it will search the flat database and pull up all references to the search. The second thing we need is to be able to do a search, for example "Michael Jackson" and it will pull all references to "Michael" and "Jackson".

    Is this possible to do in Perl. I'm pressuming it is, but the second problem I have is that the hosting company don't want us installing and modules for Perl as they want to have complete control (Understandably).

    If anyone could point out the addresses of some damb good tutorials, or sites that have a walkthrough, or if people could even give me snippets of the code i will need, it would be a great help.

    Im on MSN under the name email removed if people feel they could talk ot me on there to help me.

    Again, many thanx for any help anyone can give me!

    Phill

    Last edited by HTML; 03-12-2005 at 07:54 PM. Reason: IM email removed - please set up in profile.

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hiya, welcome to the forums.

    This seems a pretty simple (maybe too simple) way of searching text files:

    http://www.faqts.com/knowledge_base/view.phtml/aid/32883/fid/200

    Uses the <> operator and a regular expression. Hope it helps.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    phill2000sta's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    4

    Solution still not working correctly!?!?

    Hiya,

    thanks for the info. I've kind of got this working, and works fairly well. There are still a few problems with it, and if people could take a look at it and let me know what to do? Heres the code we have so far.

    Code:
    #!/usr/local/bin/perl
    
    use CGI ':standard'; 
    use CGI::Carp qw(fatalsToBrowser);
    
    require "formparse.lib"; # <- .lib to parse forms
    require "template.lib";	   # <- .lib for HTML page
    
    $dirCgi = "//directory_to_this_on_server/htdocs/cgi-bin/";
    $database = "//directory_to_this_on_server/htdocs/cgi-bin/dBase.dat";
    
    &parseform; # Parse the form data sent to us
    
    # Open the dbase and populate an array (@records) with the data.
    open(DBASE, $database) || die("Could not open file!");
    @records=<DBASE>;
    close(DBASE);
    
    # get what to search from our form data
    $searchString=$formdata{search};;
    
    # print our header
    
    print "Content-type: text/html\n\n";
    print "<HTML><BODY>\n";
    print "<b>Search String - </b>$searchString<br>\n";
    print "<b>Found Items</b><br>\n";
    print "<table width=\"100%\" border=\"1\">\n";
    
    foreach $line (@records)
    	{
    	if ($line =~ /$searchString/i)
    		{
    		(@fields)=split(/\||/,$line);
    		print <<End_of_line;
    		Your search returned: <tr><td>$fields[0]</td><td>$fields[1]</td><td>$fields[2]</td><td>$fields[3]</td><td>$fields[4]</td><td>$fields[5]</td><td>$fields[6]</td><td>$fields[7]</td><td>$fields[8]</td></tr><br>
    End_of_line
    
    print "</table>\n";
    print "</html>\n";


    The Problem

    It is good for single word searches, or searching for a term that is entered EXACTLY in the database (excluding case). The problem we have is we want to let people search for multiple words. For example -

    Database Content

    ID||ARTIST||TITLE||COST||FORMAT||QTY||CATNO
    000001||Elton John||Rocket Man||7.99||CD||1||VIRGEJ01
    000002||Elton John||Candle In The Wind||3.99||CD||1||VIRGEJ12
    000003||Elton John||I Need Love||7.99||CD||3||VIRGEJ23

    Search String

    "Elton an"

    Now we want this search to bring up the results "Elton John - Rocket Man" and "Elton John - Candle In The Wind".

    The only way I can think of doing this is by splitting the search string up into different words using...

    Code:
    (@searchTerms)=split(/\ /,$searchString);
    So that the whole of the string entered in the search field is split on the spaces, and each of the keywords are searched seperatley and the results put into a temporary array. Then when the search has been performed on all the terms, the array will no doubt have multiple entries. In our example the following results will be populated into the temporary array.

    Temporary Array

    Results from search for "Elton"
    000001||Elton John||Rocket Man||7.99||CD||1||VIRGEJ01
    000002||Elton John||Candle In The Wind||3.99||CD||1||VIRGEJ12
    000003||Elton John||I Need Love||7.99||CD||3||VIRGEJ23

    Results from search for "an"
    000001||Elton John||Rocket Man||7.99||CD||1||VIRGEJ01
    000002||Elton John||Candle In The Wind||3.99||CD||1||VIRGEJ12

    So we can see the temporary array has 5 entries in it. I think these 5 lines now need to be filtered out, so that only the entries that are duplicated are kept, with the duplicate deleted. If you get what I mean? Im really stuck at this point and don't know how to do this, and what things I need to do, so if anyone can help me.....please do so!...

    But what if the search string contains 9 keywords. Do i need to write code so that it accounts for all eventualities, or resctrict the search to only 5 terms? Can I get away with doing an if () statement to repeat searches / code for multiple keywords etc.


    Another problem I have thought about is how do I know what kind of strain this will put on the server, how long will searches take, and how big should the database get before it really starts to run slow? Again guys, any help is greatly appreciated!!

    Phill =o)
    Last edited by phill2000sta; 03-12-2005 at 06:55 AM.

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Wow, you flew with that tidbit! Good work.

    Perl.com to the rescue, how to extract unique array elements:
    http://www.perl.com/doc/FAQs/FAQ/oldfaq-html/Q5.4.html

    However, have a look at this sf.net project: http://xpt.sourceforge.net/old_home/...ocs/phrase.htm

    Phrase.pl is a text searching script, might be worth looking over it.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    phill2000sta's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    4

    Help received so far

    Thanx muchly QuietDean!

    Ill have a look at them over today, and see what I can come up with.

    With regards to the "tidbit" I know how frustrating it is for people trying to give help without the person with the problem putting as much information for people to look at as possible.

    How can you answer a question if you dont have all the information!!



    Ill keep ya informed!

    Phill =o)

  6. #6
    phill2000sta's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    4

    Still none the wiser.

    After looking at the links you posted QuietDan, I am still none the wiser. I think I'm partly there with the script I have so far, just need a little help in my working out.

    Can I get the script to run a secondary search on the line it has taken from the database, and if that line ALSO contains the second search term THEN put it into the temp array?

    Or is it still better to run a complet search, run the second complete search, and then filter out the results from that?

    ooohh.... my brain hurts!?!

    Phill =o)

  7. #7
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    Looks like you have a pretty good working knowledge of perl, it would be nice if you stuck around after your problems are solved so that you could help others.

    Dave

  8. #8
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Yes, Daves right. My knowledge of Perl is lacking, so we could do with you helping out if you have time.

    As to your question,

    If you use the first option, a two-tier search as it were, then its the equivalent of searching for the first item AND the second item. If an item only contains the second term, then it wont be picked at all. If thats what you prefer, go with option 1. If you prefer a fuller search (basically OR instead of AND) then go with the second option.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread