code: private void doLookup(String id,StringWrapper toFind)
      {
  	// retrain if necessary
  	if (distance==null) {
  	    distance = new MyTeacher().train( distanceLearner );
  	}
  	// used cached values if it's ok
  	if (lastLookup==toFind) return;
  
  	closeMatches = new HashSet();
  	closestMatch = null;
  	distanceToClosestMatch = -Double.MAX_VALUE;
  
  	// lookup best match to wrapper
  	MyWrapper wrapper = asMyWrapper(toFind);
  	Token[] tokens = wrapper.getTokens();
  	for (int i=0; i<tokens.length; i++) {
  	    ArrayList stringsWithToken = (ArrayList) index.get(tokens[i]);
  	    if (stringsWithToken!=null && ((double)stringsWithToken.size()/totalEntries) < maxFraction) {
  		for (Iterator j=stringsWithToken.iterator(); j.hasNext(); ) {
  		    MyWrapper wj = (MyWrapper)j.next(); 
  		    String wjId = (String)idMap.get(wj);
  		    //if (DEBUG) System.out.println("id:"+id+" wjId:"+wjId);
  		    if (!closeMatches.contains(wj) && (wjId==null || !wjId.equals(id))) {
  			double score = distance.score( wrapper.getDistanceWrapper(), wj.getDistanceWrapper() );
  			if (DEBUG) System.out.println("score for "+wj+": "+score);
  			//if (DEBUG) System.out.println(distance.explainScore(wrapper.getDistanceWrapper(),wj.getDistanceWrapper()));
  			closeMatches.add( wj );
  			if (score>=distanceToClosestMatch) {
  			    //if (DEBUG) System.out.println("closest so far");
  			    distanceToClosestMatch = score;
  			    closestMatch = wj;
  			}
  		    }
  		}
  	    }
  	}
  	lastLookup = toFind;
      }
docs: Lookup a string in the dictionary, cache result in closeMatches.
  
  <p>If id==null, consider any match. If id is non-null, consider
  only matches to strings that don't have the same id, or that have
  a null id.