in reply to Search Categories - Most efficient way

Actually there is alot you can do by creating categories for the search criteria. E.g., create radio buttons for an age categories: or geographical categories: Unfortunately, it appears that since your database only contains "age" as in number of years instead of a birthdate, you're not going to be able to generate very meaningful results. OTOH if you were storing birthdate, you could calculate their age and wouldn't have to rely on the users keeping it current.

Doing anything of this sort will require a good deal of work (either in requesting additional information from your users or in adding new categorization fields and keeping those fields updated). If you periodically calculate the categorization data and store it in files or databases it will decrease the amount of time it takes to process the searches. People move occasionally and so you would also need to periodically check their geographical categorization.

Once you've decided how to categorize your data, you can use either method suggested by dws or belg4mit to implement your searches.

--Jim

  • Comment on Re: Search Categories - Most efficient way

Replies are listed 'Best First'.
Re: Re: Search Categories - Most efficient way
by perleager (Pilgrim) on Dec 09, 2001 at 04:59 UTC
    Hello:

    I forgot to add that the data of the members are in a DBM file.

    ixtangxi|anthony|19|US|male|MA|
    lancerlotz|mark|21|US|male|AK|

    Heres how my coding looks like:

    ############## ###retrieve member list opendir(MEMBERS, "$free_path"); @memberz = grep !/\.\.?/, readdir MEMBERS; closedir (MEMBERS); &memhead; ######## @members = sort @memberz; if ($start eq "") { $start = 1; } for $members (@members) { if ($members eq "total.dat") { next; } $c++; # count all items if($c >= $start){ # if $c count is = or greater than where to star +t $d++; # count items that match first test unless($d > $show){ # unless $d count is greater than how many + to show #$action = $INPUT{'action'}; #$membername = $INPUT{'name'}; #$username = $INPUT{'username'}; #$cityx = $INPUT{'city'}; #$genderx = $INPUT{'gender'}; #$countryx = $INPUT{'country'}; #$statex = $INPUT{'state'}; #$agex = $INPUT{'age'}; #$start = $INPUT{'start'}; #$show = $INPUT{'show'}; #coollect info use DB_File; # optional; overrides default tie %cata, "DB_File", "$path/accounts" or die "Can't open FILENAME: $! +\n"; my $acc_data = $cata{$members}; untie(%cata); ($email,$name,$pwd,$size,$creation,$last_log,$size_added,$hf_on, $website_name,$website_des,$numdirs,$www_of,$www_name,$www_bgcolor +, $www_bgimage,$www_text,$www_link,$www_vlink,$onhold,$address,$city +, $state,$zip,$country,$telephone,$gender,$age,$icq,$education, $income,$occupation,$d_o_b,$moderator,$gbook_of,$op_in,$icon_url, $file_types,$ftp_per,$session_str,$num_dirs,$num_files, $custom_1,$custom_2,$custom_3,$custom_4,$custom_5,$custom_6,$custo +m_7, $custom_8,$custom_9,$custom_10,$marital,$signup_ip,$last_ip,$formm +ail_of) = split(/\|/,$acc_data); ($month,$day,$year1,$year2) = split (/\,/,$d_o_b); #end collect info

    Can I still use the hash suggestion by dws

    Anthony
      Yes, you can still use the method suggested by dws (or my variant thereof) but you'll have to restructure your user hash like my  %users:
      use strict; my %users = (); my %matches = (); my %search = ( sex => 'F', age => 19, st => 'FL' ); ## load users hash foreach (<DATA>) { chomp; my ($user, $sex, $age, $st) = split /\|/; $users{$user}{sex} = $sex; $users{$user}{age} = $age; $users{$user}{st} = $st; } ## Perform searches foreach my $user (keys %users) { my $match = 1; foreach my $key (keys %search) { $match = 0, last if $users{$user}{$key} ne $search{$key}; } $matches{$user}++ if $match; } ## Print out the matches (if any) foreach (keys %matches) { print "user: '", $_, "' sex: '", $users{$_}{sex}, "' age: '", $users{$_}{age}, "' st: '", $users{$_}{st}, "'\n"; } print "No matches found!\n" if not %matches; __DATA__ JOE|M|18|AL SUE|F|18|MS BOB|M|19|CA EVE|F|20|FL PAM|F|19|FL ABE|M|18|FL NAN|F|19|CA
      Note that this could be very slow if you have a large number of users and/or a large number of criteria to match. Worst case is criteria count * user count iterations. I'm not the greatest at optimizing code, so no doubt there are more efficient ways to do it (TAMEWTDI).

      --Jim