[ 
https://issues.apache.org/jira/browse/SOLR-572?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12608527#action_12608527
 ] 

Sean Timm commented on SOLR-572:
--------------------------------

For what it is worth, here is the code that I used client side before the 
collation feature was available.  I haven't looked at how it is done in this 
patch.  It has some nice features such as delimiting the spelling correction, 
e.g., with HTML bold tags, and preserving the users initial case on each word.

{code}
        StringBuilder buff = new StringBuilder();
        StringBuilder rawBuff = new StringBuilder();
        int last = 0;
        String userStr = null;
        // for each suggestion
        for( Suggestion s : suggestions ) {
            // add part before the mispelling
            userStr = userQuery.substring( last, s.startOffset );
            buff.append( userStr );
            rawBuff.append( userStr );
            String suggestion = s.suggestion;
            if( _spellCheckPreserveUserCase ) {
                userStr = userQuery.substring( s.startOffset, s.endOffset );
                char[] userCh = userStr.toCharArray();
                boolean initialUpper = Character.isUpperCase( userCh[0] );
                boolean allUpper = true;
                for( char c : userCh ) {
                    if( Character.isLowerCase( c ) ) {
                        allUpper = false;
                        break;
                    }
                }
                if( allUpper ) {
                    suggestion = suggestion.toUpperCase();
                }
                else if( initialUpper ) {
                    userCh = suggestion.toCharArray();
                    userCh[0] = Character.toUpperCase( userCh[0] );
                    suggestion = new String( userCh );
                }
            }
            buff.append( _spellCheckStartHighlight ).append( suggestion )
                .append( _spellCheckEndHighlight );
            rawBuff.append( suggestion );
            last = s.endOffset;
        }
        // add part after all mispellings
        userStr = userQuery.substring( last );
        buff.append( userStr );
        rawBuff.append( userStr );
        if( log().isDebugEnabled() ) {
            log().debug( "Did you mean: " + buff );
            log().debug( "Did you mean link: " + rawBuff );
        }
{code}

> Spell Checker as a Search Component
> -----------------------------------
>
>                 Key: SOLR-572
>                 URL: https://issues.apache.org/jira/browse/SOLR-572
>             Project: Solr
>          Issue Type: New Feature
>          Components: spellchecker
>    Affects Versions: 1.3
>            Reporter: Shalin Shekhar Mangar
>            Assignee: Grant Ingersoll
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, 
> SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, 
> SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, 
> SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, 
> SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, 
> SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, SOLR-572.patch, 
> SOLR-572.patch, SOLR-572.patch, SOLR-572.patch
>
>
> http://wiki.apache.org/solr/SpellCheckComponent
> Expose the Lucene contrib SpellChecker as a Search Component. Provide the 
> following features:
> * Allow creating a spell index on a given field and make it possible to have 
> multiple spell indices -- one for each field
> * Give suggestions on a per-field basis
> * Given a multi-word query, give only one consistent suggestion
> * Process the query with the same analyzer specified for the source field and 
> process each token separately
> * Allow the user to specify minimum length for a token (optional)
> Consistency criteria for a multi-word query can consist of the following:
> * Preserve the correct words in the original query as it is
> * Never give duplicate words in a suggestion

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to