Index: src/port/port.tcl
===================================================================
--- src/port/port.tcl	(revision 46172)
+++ src/port/port.tcl	(working copy)
@@ -684,10 +684,10 @@
             set installed_epoch     [lindex $i 5]
 
             # Get info about the port from the index
-            if {[catch {set res [mportsearch $portname no exact]} result]} {
+            if {[catch {set res [mportlookup $portname]} result]} {
                 global errorInfo
                 ui_debug "$errorInfo"
-                fatal "search for portname $portname failed: $result"
+                fatal "lookup of portname $portname failed: $result"
             }
             if {[llength $res] < 2} {
                 if {[macports::ui_isset ports_debug]} {
@@ -1355,17 +1355,13 @@
         # otherwise try to map the portname to a url
         if {$porturl eq ""} {
         # Verify the portname, getting portinfo to map to a porturl
-            if {[catch {mportsearch $portname no exact} result]} {
+            if {[catch {mportlookup $portname} result]} {
                 ui_debug "$::errorInfo"
-                break_softcontinue "search for portname $portname failed: $result" 1 status
+                break_softcontinue "lookup of portname $portname failed: $result" 1 status
             }
             if {[llength $result] < 2} {
                 break_softcontinue "Port $portname not found" 1 status
             }
-            set found [expr [llength $result] / 2]
-            if {$found > 1} {
-                ui_warn "Found $found port $portname definitions, displaying first one."
-            }
             array unset portinfo
             array set portinfo [lindex $result 1]
             set porturl $portinfo(porturl)
@@ -1700,10 +1696,10 @@
     }
 
     foreachport $portlist {
-        # Search for the port.
-        if {[catch {mportsearch $portname no exact} result]} {
+        # Look up the port.
+        if {[catch {mportlookup $portname} result]} {
             ui_debug $::errorInfo
-            break_softcontinue "The search for '$portname' failed: $result" \
+            break_softcontinue "The lookup of '$portname' failed: $result" \
                                1 status
         }
         if {[llength $result] < 2} {
@@ -2160,7 +2156,7 @@
             set installed_epoch [lindex $i 5]
 
             # Get info about the port from the index
-            if {[catch {set res [mportsearch $portname no exact]} result]} {
+            if {[catch {set res [mportlookup $portname]} result]} {
                 global errorInfo
                 ui_debug "$errorInfo"
                 break_softcontinue "search for portname $portname failed: $result" 1 status
@@ -2268,11 +2264,11 @@
         return 1
     }
     foreachport $portlist {
-        # search for port
-        if {[catch {mportsearch $portname no exact} result]} {
+        # look up port
+        if {[catch {mportlookup $portname} result]} {
             global errorInfo
             ui_debug "$errorInfo"
-            break_softcontinue "search for portname $portname failed: $result" 1 status
+            break_softcontinue "lookup of portname $portname failed: $result" 1 status
         }
         if {[llength $result] < 2} {
             break_softcontinue "Port $portname not found" 1 status
@@ -2582,10 +2578,10 @@
         if {$porturl == ""} {
         
             # Verify the portname, getting portinfo to map to a porturl
-            if {[catch {set res [mportsearch $portname no exact]} result]} {
+            if {[catch {set res [mportlookup $portname]} result]} {
                 global errorInfo
                 ui_debug "$errorInfo"
-                break_softcontinue "search for portname $portname failed: $result" 1 status
+                break_softcontinue "lookup of portname $portname failed: $result" 1 status
             }
             if {[llength $res] < 2} {
                 break_softcontinue "Port $portname not found" 1 status
@@ -2739,10 +2735,10 @@
         # otherwise try to map the portname to a url
         if {$porturl == ""} {
             # Verify the portname, getting portinfo to map to a porturl
-            if {[catch {set res [mportsearch $portname no exact]} result]} {
+            if {[catch {set res [mportlookup $portname]} result]} {
                 global errorInfo
                 ui_debug "$errorInfo"
-                break_softcontinue "search for portname $portname failed: $result" 1 status
+                break_softcontinue "lookup of portname $portname failed: $result" 1 status
             }
             if {[llength $res] < 2} {
                 break_softcontinue "Port $portname not found" 1 status
Index: src/macports1.0/macports.tcl
===================================================================
--- src/macports1.0/macports.tcl	(revision 46172)
+++ src/macports1.0/macports.tcl	(working copy)
@@ -708,6 +708,9 @@
             unsetenv $envkey
         }
     }
+    
+    # load the quick index
+    _mports_load_quickindex
 }
 
 proc macports::worker_init {workername portpath porturl portbuildpath options variations} {
@@ -1654,6 +1657,142 @@
     return $matches
 }
 
+proc mportlookup {name} {
+    global macports::portdbpath macports::sources macports::quick_indices macports::quick_offsets
+    
+    set found 0
+    set matches [list]
+    foreach source $sources {
+        set source [lindex $source 0]
+        if {[macports::getprotocol $source] != "mports"} {
+            set result [lsearch -sorted [lindex ${quick_indices} $found] [string tolower $name]]
+            if {$result == -1} {
+                continue
+            }
+            set offset [lindex [lindex ${quick_offsets} $found] $result]
+            incr found 1
+            if {[catch {set fd [open [macports::getindex $source] r]} result]} {
+                ui_warn "Can't open index file for source: $source"
+            } else {
+                try {
+                    seek $fd $offset
+                    gets $fd line
+                    set name [lindex $line 0]
+                    set len [lindex $line 1]
+                    set line [read $fd $len]
+                        
+                    array set portinfo $line
+
+                    switch -regexp -- [macports::getprotocol ${source}] {
+                        {^rsync$} {
+                            # Rsync files are local
+                            set source_url "file://[macports::getsourcepath $source]"
+                        }
+                        {^https?$|^ftp$} {
+                            if {[_source_is_snapshot $source filename extension]} {
+                                # daily snapshot tarball
+                                set source_url "file://[macports::getsourcepath $source]"
+                             } else {
+                                # default action
+                                set source_url $source
+                             }
+                        }
+                        default {
+                            set source_url $source
+                        }
+                    }
+                    if {[info exists portinfo(portarchive)]} {
+                        set porturl ${source_url}/$portinfo(portarchive)
+                    } elseif {[info exists portinfo(portdir)]} {
+                        set porturl ${source_url}/$portinfo(portdir)
+                    }
+                    if {[info exists porturl]} {
+                        lappend line porturl $porturl
+                        ui_debug "Found port in $porturl"
+                    } else {
+                        ui_debug "Found port info: $line"
+                    }
+                    lappend matches $name
+                    lappend matches $line
+                    close $fd
+                    break
+                } catch {*} {
+                    ui_warn "It looks like your PortIndex file may be corrupt."
+                    throw
+                } finally {
+                    catch {close $fd}
+                }
+            }
+        } else {
+            array set attrs [list name $name]
+            set res [macports::index::search $macports::portdbpath $source [array get attrs]]
+            if {[llength $res] > 0} {
+                eval lappend matches $res
+                break
+            }
+        }
+    }
+
+    return $matches
+}
+
+proc _mports_load_quickindex {args} {
+    global macports::sources macports::quick_indices macports::quick_offsets
+    
+    set found 0
+    set quick_indices [list]
+    set quick_offsets [list]
+    foreach source $sources {
+        set source [lindex $source 0]
+        set index [macports::getindex $source]
+        if {![file exists ${index}.quick] || [file mtime ${index}] > [file mtime ${index}.quick]} {
+            if {[catch {set fd [open ${index} r]} result] || [catch {set quickfd [open ${index}.quick w]} result]} {
+                ui_warn "Can't open index file for source: $source"
+            } else {
+                try {
+                    set offset [tell $fd]
+                    set quicklist [list]
+                    while {[gets $fd line] >= 0} {
+                        if {[llength $line] != 2} {
+                            continue
+                        }
+                        set name [lindex $line 0]
+                        lappend quicklist [list [string tolower $name] $offset]
+                        
+                        set len [lindex $line 1]
+                        seek $fd $len current
+                        set offset [tell $fd]
+                    }
+                    puts $quickfd [lsort -index 0 $quicklist]
+                } catch {*} {
+                    ui_warn "It looks like your PortIndex file may be corrupt."
+                    throw
+                } finally {
+                    close $fd
+                    close $quickfd
+                }
+            }
+        }
+        # quick index should now exist
+        if {[catch {set fd [open ${index}.quick r]} result]} {
+            ui_warn "Can't open quick index file for source: $source"
+        } else {
+            incr found 1
+            set quicklist [gets $fd]
+            close $fd
+            foreach l $quicklist {
+                lappend this_indices [lindex $l 0]
+                lappend this_offsets [lindex $l 1]
+            }
+            lappend quick_indices $this_indices
+            lappend quick_offsets $this_offsets
+        }
+    }
+    if {!$found} {
+        return -code error "No index(es) found! Have you synced your source indexes?"
+    }
+}
+
 proc mportinfo {mport} {
     set workername [ditem_key $mport workername]
     return [$workername eval array get PortInfo]
@@ -1756,20 +1895,17 @@
         }
         
         # Find the porturl
-        if {[catch {set res [mportsearch $dep_portname false exact]} error]} {
+        if {[catch {set res [mportlookup $dep_portname]} error]} {
             global errorInfo
             ui_debug "$errorInfo"
-            ui_error "Internal error: port search failed: $error"
+            ui_error "Internal error: port lookup failed: $error"
             return 1
         }
         
         unset -nocomplain porturl
-        foreach {name array} $res {
-            array set portinfo $array
-            if {[info exists portinfo(porturl)]} {
-                set porturl $portinfo(porturl)
-                break
-            }
+        array set portinfo [lindex $res 1]
+        if {[info exists portinfo(porturl)]} {
+            set porturl $portinfo(porturl)
         }
 
         if {![info exists porturl]} {
@@ -1938,10 +2074,10 @@
     }
 
     # check if the port is in tree
-    if {[catch {mportsearch $portname false exact} result]} {
+    if {[catch {mportlookup $portname} result]} {
         global errorInfo
         ui_debug "$errorInfo"
-        ui_error "port search failed: $result"
+        ui_error "port lookup failed: $result"
         return 1
     }
     # argh! port doesnt exist!

