bin/amigo.js
function(cache){

	    // Frame to hang our results on.
	    var results = {
		"good": [],
		"bad": [],
		"ugly": []
	    };

	    // Break out the two parts of the species cache.
	    var doc_lookup = cache['documents'];
	    var str_refs = cache['references'];

	    // Comb through the cache, carefully, and get the results
	    // that we can. First, for each of the entities try and
	    // pull out the right fields.
	    us.each(entities, function(entity){

		var entity_hits = [];

		// Check to see if we can find any document references
		// for our given string.
		if( str_refs && us.isArray(str_refs[entity]) ){

		    // For each of the matched IDs, lookup the
		    // document in question and try and figure out
		    // which field or fields matched.
		    var match_proxy_ids = str_refs[entity];
		    us.each(match_proxy_ids, function(match_proxy_id){

			// Retrieve the document by proxy ID.
			var doc = doc_lookup[match_proxy_id];
			if( doc ){

			    // Look in all the possibly multi-valued
			    // fields in the doc for the match.
			    us.each(bioentity_search_fields, function(search_field){

				//console.log("search_field: ", search_field);

				var vals = doc[search_field];
				// Array-ify the field if not already.
				if( vals && ! us.isArray(vals) ){
				    vals = [vals];
				}
				us.each(vals, function(val){

				    // Record that we found the exact
				    // match we want.
				    if( entity === val ){
					entity_hits.push({
					    "id": match_proxy_id,
					    "matched": search_field
					});
				    }
				});
			    });
			}
		    });
		}

		// The results are good, bad, or ugly, depending on the
		// number.
		var rtype = null;
		if( entity_hits.length === 1 ){
		    rtype = "good";
		}else if( entity_hits.length === 0 ){
		    rtype = "bad";
		}else{
		    rtype = "ugly";
		}

		//console.log("results: ", results);

		// Push the found results into the right section.
		results[rtype].push({
		    "input": entity,
		    "results": entity_hits
		});

	    });

	    return results;
	}
function(cache){

	    // Frame to hang our results on.
	    var results = {
		"good": [],
		"bad": [],
		"ugly": []
	    };

	    // Break out the two parts of the species cache.
	    var doc_lookup = cache['documents'];
	    var str_refs = cache['references'];

	    // Comb through the cache, carefully, and get the results
	    // that we can. First, for each of the entities try and
	    // pull out the right fields.
	    us.each(entities, function(entity){

		var entity_hits = [];

		// Check to see if we can find any document references
		// for our given string.
		if( str_refs && us.isArray(str_refs[entity]) ){

		    // For each of the matched IDs, lookup the
		    // document in question and try and figure out
		    // which field or fields matched.
		    var match_proxy_ids = str_refs[entity];
		    us.each(match_proxy_ids, function(match_proxy_id){

			// Retrieve the document by proxy ID.
			var doc = doc_lookup[match_proxy_id];
			if( doc ){

			    // Look in all the possibly multi-valued
			    // fields in the doc for the match.
			    us.each(bioentity_search_fields, function(search_field){

				//console.log("search_field: ", search_field);

				var vals = doc[search_field];
				// Array-ify the field if not already.
				if( vals && ! us.isArray(vals) ){
				    vals = [vals];
				}
				us.each(vals, function(val){

				    // Record that we found the exact
				    // match we want.
				    if( entity === val ){
					entity_hits.push({
					    "id": match_proxy_id,
					    "matched": search_field
					});
				    }
				});
			    });
			}
		    });
		}

		// The results are good, bad, or ugly, depending on the
		// number.
		var rtype = null;
		if( entity_hits.length === 1 ){
		    rtype = "good";
		}else if( entity_hits.length === 0 ){
		    rtype = "bad";
		}else{
		    rtype = "ugly";
		}

		//console.log("results: ", results);

		// Push the found results into the right section.
		results[rtype].push({
		    "input": entity,
		    "results": entity_hits
		});

	    });

	    return results;
	}
function ( cache ) { // Frame to hang our results on. var results = { "good" : [ ] , "bad" : [ ] , "ugly" : [ ] } ; // Break out the two parts of the species cache. var doc_lookup = cache [ 'documents' ] ; var str_refs = cache [ 'references' ] ; // Comb through the cache, carefully, and get the results // that we can. First, for each of the entities try and // pull out the right fields. us . each ( entities , function ( entity ) { var entity_hits = [ ] ; // Check to see if we can find any document references // for our given string. if ( str_refs && us . isArray ( str_refs [ entity ] ) ) { // For each of the matched IDs, lookup the // document in question and try and figure out // which field or fields matched. var match_proxy_ids = str_refs [ entity ] ; us . each ( match_proxy_ids , function ( match_proxy_id ) { // Retrieve the document by proxy ID. var doc = doc_lookup [ match_proxy_id ] ; if ( doc ) { // Look in all the possibly multi-valued // fields in the doc for the match. us . each ( bioentity_search_fields , function ( search_field ) { //console.log("search_field: ", search_field); var vals = doc [ search_field ] ; // Array-ify the field if not already. if ( vals && ! us . isArray ( vals ) ) { vals = [ vals ] ; } us . each ( vals , function ( val ) { // Record that we found the exact // match we want. if ( entity === val ) { entity_hits . push ( { "id" : match_proxy_id , "matched" : search_field } ) ; } } ) ; } ) ; } } ) ; } // The results are good, bad, or ugly, depending on the // number. var rtype = null ; if ( entity_hits . length === 1 ) { rtype = "good" ; } else if ( entity_hits . length === 0 ) { rtype = "bad" ; } else { rtype = "ugly" ; } //console.log("results: ", results); // Push the found results into the right section. results [ rtype ] . push ( { "input" : entity , "results" : entity_hits } ) ; } ) ; return results ; }
First, let us discuss what will happen when we have a populated cache to work with, one way or another. The cache is
First let us discuss what will happen when we have a populated cache to work with one way or another . The cache is