software/test/performance/src/gov/nih/nci/evs/browser/utils/SearchUtils.java
/**
	 * Sorts the given concept references based on a scoring algorithm
	 * designed to provide a more natural ordering.  Scores are determined by
	 * comparing each reference against a provided search term.
	 * @param searchTerm The term used for comparison; single or multi-word.
	 * @param toSort The iterator containing references to sort.
	 * @param maxToReturn Sets upper limit for number of top-scored items returned.
	 * @return Iterator over sorted references.
	 * @throws LBException
	 */
Sorts the given concept references based on a scoring algorithm
designed to provide a more natural ordering.  Scores are determined by
comparing each reference against a provided search term.
@param searchTerm The term used for comparison; single or multi-word.
@param toSort The iterator containing references to sort.
@param maxToReturn Sets upper limit for number of top-scored items returned.
@return Iterator over sorted references.
Sorts the given concept references based on a scoring algorithm designed to provide a more natural ordering . Scores are determined by comparing each reference against a provided search term . @param searchTerm The term used for comparison ; single or multi - word . @param toSort The iterator containing references to sort . @param maxToReturn Sets upper limit for number of top - scored items returned . @return Iterator over sorted references .
protected ResolvedConceptReferencesIterator sortByScore(String searchTerm, ResolvedConceptReferencesIterator toSort, int maxToReturn) throws LBException {
		List<String> compareWords = toScoreWords(searchTerm);
		Map<String, ScoredTerm> scoredResult = new TreeMap<String, ScoredTerm>();
		while (toSort.hasNext()) {
    		ResolvedConceptReferenceList refs = toSort.next(100);
    		for (int i = 0; i < refs.getResolvedConceptReferenceCount(); i++) {
    			ResolvedConceptReference ref = refs.getResolvedConceptReference(i);
    			String code = ref.getConceptCode();
                Concept ce = ref.getReferencedEntry();
                Presentation[] allTermsForConcept = ce.getPresentation();
    			for (Presentation p : allTermsForConcept) {
    				float score = score(p.getText().getContent(), compareWords, p.isIsPreferred(), i);
    				if (scoredResult.containsKey(code)) {
    					ScoredTerm scoredTerm = (ScoredTerm) scoredResult.get(code);
    					if (scoredTerm.score > score)
    						continue;
    				}
    				scoredResult.put(code, new ScoredTerm(ref, score));
    			}
    		}
		}
		return new ScoredIterator(scoredResult.values(), maxToReturn);
	}
protected ResolvedConceptReferencesIterator sortByScore ( String searchTerm , ResolvedConceptReferencesIterator toSort , int maxToReturn ) throws LBException { List < String > compareWords = toScoreWords ( searchTerm ) ; Map < String , ScoredTerm > scoredResult = new TreeMap < String , ScoredTerm > ( ) ; while ( toSort . hasNext ( ) ) { ResolvedConceptReferenceList refs = toSort . next ( 100 ) ; for ( int i = 0 ; i < refs . getResolvedConceptReferenceCount ( ) ; i ++ ) { ResolvedConceptReference ref = refs . getResolvedConceptReference ( i ) ; String code = ref . getConceptCode ( ) ; Concept ce = ref . getReferencedEntry ( ) ; Presentation [ ] allTermsForConcept = ce . getPresentation ( ) ; for ( Presentation p : allTermsForConcept ) { float score = score ( p . getText ( ) . getContent ( ) , compareWords , p . isIsPreferred ( ) , i ) ; if ( scoredResult . containsKey ( code ) ) { ScoredTerm scoredTerm = ( ScoredTerm ) scoredResult . get ( code ) ; if ( scoredTerm . score > score ) continue ; } scoredResult . put ( code , new ScoredTerm ( ref , score ) ) ; } } } return new ScoredIterator ( scoredResult . values ( ) , maxToReturn ) ; }
Sorts the given concept references based on a scoring algorithm
 designed to provide a more natural ordering.
Sorts the given concept references based on a scoring algorithm designed to provide a more natural ordering .
//logger.debug("Sorting by score: " + searchTerm);
 // Determine the set of individual words to compare against.
 // Create a bucket to store results.
 // Score all items ...
 // Working in chunks of 100.
 // Note: Preferred descriptions carry more weight,
 // but we process all terms to allow the score to improve
 // based on any contained presentation.
 // Check for a previous match on this code for a different presentation.
 // If already present, keep the highest score.
 // Return an iterator that will sort the scored result.
