Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Mon Feb 10, 2003 6:08 am   

Database reteriver
 
Hello all, I am trying to find a way to search my database for an item ,but if it is not found to give me the next 2 closes mathces in alphabetical order. any ideas?

would also be nice if it gave it to me as an option so that i could pick from one of them

Thank you

megamog75
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Feb 10, 2003 9:11 am   
 
Seems to me I wrote a decent fuzzy search script a while ago.

Ah that right it was all done through email. Luckily still in my archive. It would take a lot of adapting for the DB since it was written for the Automapper, but the concept is there. The fuzzy matching logic was done in this trigger and alias. Hopefully you can figure out how to make it useful for your needs cause it took nearly 2 weeks of tweaking back and forth through email to get the whole script that is from right.

#ALIAS CompareNames {CurrentCompare=0;#FORALL %replace( %item( @CompareTarget, 1), " ", "|") { #IF ((%pos(%lower(%concat(" ",%i," ")),%lower(@TargetRoom)))|(%pos(%lower(%concat(%i," ")),%lower(%concat(" ",@TargetRoom," "))))) { #ADD CurrentCompare 10}};#IF (%numwords( %item( @CompareTarget, 1))=%numwords( @TargetRoom)) { #ADD CurrentCompare 5};#IF (%lower( %item( @CompareTarget, 1))=%lower( @TargetRoom)) { #ADD CurrentCompare 100};#IF (@CurrentCompare>@ClosestMatch) {ClosestMatch=@CurrentCompare};#ADDITEM RoomMatches %concat( @CurrentCompare, "=", %item( @CompareTarget, 2))}
#TRIGGER {(%w) {tells|replies to} you '!path (*)'$} {#NOOP expected format is zone:room;TargetZone="";TargetRoom="";RoomMatches="";ClosestMatch=0;TargetZone=%trim( %word( "%2", 1, ":"));TargetRoom=%trim( %word( "%2", 2, ":"));#IF ((@TargetZone=%null)|(@TargetRoom=%null)) { tell %1 Your request was incomplete} { #IF ((%zonenum( @TargetZone)="")|(%ismember( @TargetZone, @ForbiddenZones))) { tell %1 I have no such zone on file. To request a zone list send a tell containing !zones.} {CurrentLocation=%concat( %zonenum, " ", %roomnum);TargetZone=%zonename( %zonenum( @TargetZone));#TELEPORT 1 %zonenum( @TargetZone);#LOOP %numrooms {CompareTarget=%concat( %remove( " (PK)", %roomname( %mapvnum( %i))), "|", %mapvnum( %i));CompareNames};TargetRoom="";#IF (@ClosestMatch<10) { tell %1 I could not find any room that resemble the one you mentioned.} {#IF (%db( @PendingPaths, %1)) {tell %1 Your last search had not expired yet, it is being removed.;CurrentCompare=%concat( %1, %db( @PendingPaths, %1));#UNVAR @CurrentCompare {GuideBot|PathsPending};#DELKEY PendingPaths %1};PossibleRooms="";#FORALL @RoomMatches { #IF (%number( %word( %i, 1, "="))=@ClosestMatch) {CurrentCompare=%word( %i, 2, "=");#IF (%ismember( %remove( " (PK)", %roomname( @CurrentCompare)), @TargetRoom)) { #ADDKEY PossibleRooms {%remove( " (PK)", %roomname( @CurrentCompare))} {%eval( %db( @PossibleRooms, %remove( " (PK)", %roomname( @CurrentCompare)))+1)}} { #ADDKEY PossibleRooms {%remove( " (PK)", %roomname( @CurrentCompare))} {1}};#ADDKEY PossibleRooms Total %eval( %db( @PossibleRooms, "Total")+1);#ADDITEM TargetRoom {%remove( " (PK)", %roomname( @CurrentCompare))};PathDetail=%replace( %concat( %db( @ZonePaths, @TargetZone), %walk( @CurrentCompare)), ".", "");#IF (%db( @PendingPaths, %1)) { #ADDITEM @CompareTarget {%concat( %roomname( @CurrentCompare), "=", @PathDetail)}} {#ADDKEY PendingPaths {%1} {%secs};CompareTarget=%concat( %1, %db( @PendingPaths, %1));#VAR @CompareTarget {%concat( %db( @PathRates, @TargetZone), "|", %roomname( @CurrentCompare), "=", @PathDetail)} {_nodef} {GuideBot|PathsPending};#T+ PathsPending}}};#FORALL @TargetRoom {#DELITEM TargetRoom {%i};#IF (%db( @PossibleRooms, %i)>1) { #ADDITEM TargetRoom {%concat( %i, "(", %db( @PossibleRooms, %i), ")")}} { #ADDITEM TargetRoom {%i}}};Teller=%concat( %1, " I matched ", %db( @PossibleRooms, "Total"), " room(s) they are ", %replace( @TargetRoom, "|", ", "), ". All searches expire after 3 minutes.");CompareTarget=%db( @AccountData, %1);#IF (@CompareTarget="free") { Teller=%concat( @Teller, " You have unlimited credits, use !buy # to receive a path.")} { #IF (@CompareTarget>0) { Teller=%concat( @Teller, " You have ", @CompareTarget, " credits, use !buy # to receive a path. Cost: ", %db( @PathRates, @TargetZone), " credits.")} {#IF (@CompareTarget!="") { Teller=%concat( @Teller, " You have insufficient credits, use !fund prior to giving me gold to purchase more.")} { Teller=%concat( @Teller, " You do not have an account yet, use !fund prior to giving me gold to establish one.")};CurrentCompare=%concat( %1, %db( @PendingPaths, %1));#UNVAR @CurrentCompare {GuideBot|PathsPending};#DELKEY PendingPaths %1}};LongTell};#TELEPORT %word( @CurrentLocation, 2) %word( @CurrentLocation, 1)}}}
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net