[ https://issues.apache.org/jira/browse/SOLR-1071?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12735859#action_12735859 ]
Uri Boness commented on SOLR-1071: ---------------------------------- I'm not sure it's a bug in the JSONRW, it seems to me that it was intentionally implemented to behave in this manner. It is confusing though, and indeed when developing components one has to keep in mind the consequences of using a _SimpleOrderedMap_ vs. a simple _NamedList_. I think there are several ways to tackle this: 1. Do nothing. In which case people should always know the consequences of using a _SimpleOrderedMap_ vs. a simple _NamedList._ *Advantages:* you probably don't break existing functionality. No code changes need to take place. *Disadvantages:* (as you mentioned) more error prone - easier to introduce such bugs when writing new components. People need to know the best practices which are not enforced. 2. In the _SimpleOrderedMap_, keep track of duplicate keys. If a _SimpleOrderedMap_ hold duplicate keys then it should not be rendered as a JSON object, but more like a normal _NamedList_ *Advantages:* you probably break nothing.. if components already use duplicate keys in a _SimpleOrderedMap_ then most probably they've introduced this same bug. *Disadvantage:* Inconsistent in the sense that in different occasions a _SimpleOrderedMap_ will be rendered differently. If duplicate keys are added, then there's no added value in choosing _SimpleOrderedMap_ over a normal _NamedList_. Which brings me to the last option 3. Make sure that _SimpleOrderedMap_ does not accept duplicates. Either by enforcing it (e.g. by throwing an exception) or just by overriding the values. *Advantages:* Gives the _SimpleOrderedMap_ a true meaning and a reason to exist. With this in place, it will be clear when and how it can be used. No changes need to be applied to the JSONRW. *Disadvantages:* Existing functionality might break, yet again... if duplicate keys are already used than this bug is introduced anyway. According to the Javadoc, the _SimpleOrderedMap_ implementation intentionality doesn't prevent duplicate keys... so there must be a reason for that. Personally, I'm for option 3. The current implementation of _SimpleOrderedMap_ doesn't seem to add any functionality to the _NamedList_ class, so it seems to me this class was created just as a hint for the response writers to render it differently. The name "SimpleOrderedMap" also suggest a "Map-like" functionality which doesn't support duplicate keys. But again, I'm not sure about the original reasons for not preventing duplicate keys in the first place, so there might be something I'm missing here. > spellcheck.extendedResults returns an invalid JSON response when count > 1 > -------------------------------------------------------------------------- > > Key: SOLR-1071 > URL: https://issues.apache.org/jira/browse/SOLR-1071 > Project: Solr > Issue Type: Bug > Components: spellchecker > Affects Versions: 1.3 > Reporter: Uri Boness > Assignee: Grant Ingersoll > Fix For: 1.4 > > Attachments: SpellCheckComponent_fix.patch, > SpellCheckComponent_new_structure.patch, > SpellCheckComponent_new_structure_incl_test.patch > > > When: wt=json & spellcheck.extendedResults=true & spellcheck.count > 1, the > suggestions are returned in the following format: > "suggestions":[ > "amsterdm",{ > "numFound":5, > "startOffset":0, > "endOffset":8, > "origFreq":0, > "suggestion":{ > "frequency":8498, > "word":"amsterdam"}, > "suggestion":{ > "frequency":1, > "word":"amsterd"}, > "suggestion":{ > "frequency":8, > "word":"amsterdams"}, > "suggestion":{ > "frequency":1, > "word":"amstedam"}, > "suggestion":{ > "frequency":22, > "word":"amsterdamse"}}, > "beak",{ > "numFound":5, > "startOffset":9, > "endOffset":13, > "origFreq":0, > "suggestion":{ > "frequency":379, > "word":"beek"}, > "suggestion":{ > "frequency":26, > "word":"beau"}, > "suggestion":{ > "frequency":26, > "word":"baak"}, > "suggestion":{ > "frequency":15, > "word":"teak"}, > "suggestion":{ > "frequency":11, > "word":"beuk"}}, > "correctlySpelled",false, > "collation","amsterdam beek"]}} > This is an invalid json as each term is associated with a JSON object which > holds multiple "suggestion" attributes. When working with a JSON library only > the last "suggestion" attribute is picked up. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.