software/test/performance/src/org/LexGrid/LexBIG/example/remote2/MetaMatch2.java
/**
     * Attempt to approximate term completion.
     * @param s The test string.
     * @throws LBException
     */
Attempt to approximate term completion.
@param s The test string.
Attempt to approximate term completion . @param s The test string .
@SuppressWarnings("unchecked")
    protected void matchTermCompletion(String s)
        throws LBException
    {
        _buffer.delete(0, _buffer.length());
        Util.StopWatch stopWatch = new Util.StopWatch();
        _buffer.append("\n*** Term completion ...\n");
        String prefix = s.toLowerCase();
        String[] words = toWords(s, false);
        CodedNodeSet nodes = _lbSvc.getCodingSchemeConcepts(_scheme, _csvt);
        nodes.restrictToMatchingDesignations(
            prefix, SearchDesignationOption.ALL,
            "startsWith", null);
        SortOptionList sortCriteria =
            Constructors.createSortOptionList(new String[]{"matchToQuery"});
        ResolvedConceptReferenceList matches =
            nodes.resolveToList(sortCriteria, null, new PropertyType[] {}, 5);
        _buffer.append("* startsWith (limited to 5 hits); short circuit after query...\n");
        if (matches.getResolvedConceptReferenceCount() > 0) {
            int ctr = 0;
            for (int i = 0; i < matches.getResolvedConceptReferenceCount(); i++) {
                ResolvedConceptReference ref = matches.getResolvedConceptReference(i);
                ctr = printText(ctr, ref, false, prefix, words.length + 1);
            }
        } else {
            _buffer.append("\tNo match found.\n");
        }
        _buffer.append("* " + stopWatch.getResult());
        Util.displayMessage(_buffer.toString());
        _buffer.delete(0, _buffer.length());
        stopWatch.start();
        nodes = _lbSvc.getCodingSchemeConcepts(_scheme, _csvt);
        String regex = '^' + prefix + "\\W*\\w*\\Z";
        nodes.restrictToMatchingDesignations(
                regex, SearchDesignationOption.ALL,
                "RegExp", null);
        matches = nodes.resolveToList(sortCriteria, null, new PropertyType[] {}, 5);
        _buffer.append("\n* RegExp match (limited to 5 hits); short circuit on query...\n");
        if (matches.getResolvedConceptReferenceCount() > 0) {
            int ctr = 0;
            for (int i = 0; i < matches.getResolvedConceptReferenceCount(); i++) {
                ResolvedConceptReference ref = matches.getResolvedConceptReference(i);
                ctr = printText(ctr, ref, false, prefix, words.length + 1);
            }
        } else {
            _buffer.append("\tNo match found.\n");
        }
        _buffer.append("* " + stopWatch.getResult());
        Util.displayMessage(_buffer.toString());
    }
@ SuppressWarnings ( "unchecked" ) protected void matchTermCompletion ( String s ) throws LBException { _buffer . delete ( 0 , _buffer . length ( ) ) ; Util . StopWatch stopWatch = new Util . StopWatch ( ) ; _buffer . append ( "\n*** Term completion ...\n" ) ; String prefix = s . toLowerCase ( ) ; String [ ] words = toWords ( s , false ) ; CodedNodeSet nodes = _lbSvc . getCodingSchemeConcepts ( _scheme , _csvt ) ; nodes . restrictToMatchingDesignations ( prefix , SearchDesignationOption . ALL , "startsWith" , null ) ; SortOptionList sortCriteria = Constructors . createSortOptionList ( new String [ ] { "matchToQuery" } ) ; ResolvedConceptReferenceList matches = nodes . resolveToList ( sortCriteria , null , new PropertyType [ ] { } , 5 ) ; _buffer . append ( "* startsWith (limited to 5 hits); short circuit after query...\n" ) ; if ( matches . getResolvedConceptReferenceCount ( ) > 0 ) { int ctr = 0 ; for ( int i = 0 ; i < matches . getResolvedConceptReferenceCount ( ) ; i ++ ) { ResolvedConceptReference ref = matches . getResolvedConceptReference ( i ) ; ctr = printText ( ctr , ref , false , prefix , words . length + 1 ) ; } } else { _buffer . append ( "\tNo match found.\n" ) ; } _buffer . append ( "* " + stopWatch . getResult ( ) ) ; Util . displayMessage ( _buffer . toString ( ) ) ; _buffer . delete ( 0 , _buffer . length ( ) ) ; stopWatch . start ( ) ; nodes = _lbSvc . getCodingSchemeConcepts ( _scheme , _csvt ) ; String regex = '^' + prefix + "\\W*\\w*\\Z" ; nodes . restrictToMatchingDesignations ( regex , SearchDesignationOption . ALL , "RegExp" , null ) ; matches = nodes . resolveToList ( sortCriteria , null , new PropertyType [ ] { } , 5 ) ; _buffer . append ( "\n* RegExp match (limited to 5 hits); short circuit on query...\n" ) ; if ( matches . getResolvedConceptReferenceCount ( ) > 0 ) { int ctr = 0 ; for ( int i = 0 ; i < matches . getResolvedConceptReferenceCount ( ) ; i ++ ) { ResolvedConceptReference ref = matches . getResolvedConceptReference ( i ) ; ctr = printText ( ctr , ref , false , prefix , words . length + 1 ) ; } } else { _buffer . append ( "\tNo match found.\n" ) ; } _buffer . append ( "* " + stopWatch . getResult ( ) ) ; Util . displayMessage ( _buffer . toString ( ) ) ; }
Attempt to approximate term completion.
Attempt to approximate term completion .
// Term completion is basically 'startsWith'.  Two different
 // queries are tried to match.  The first utilizes the standard
 // startsWith match algorithm.  The second utilizes regular
 // expressions to try and accomplish short-circuiting more
 // efficiently.
 //
 // Queries are currently made against all text representations,
 // but this could be narrowed.
 //
 // On resolve, we sort by lucene score ('matchToQuery' sort algorithm).
 // Resolve and analyze the result ...
 // Found a match?
 //----------------------------------------------------------------------
 // Try again with regular expression.
 //----------------------------------------------------------------------
 // Resolve and analyze the result ...
 // Found a match?
