Thank you for the info, Will try to implement it. Regards, Edwin
On 12 June 2015 at 01:32, Reitzel, Charles <[email protected]> wrote: > Moving the highlighted snippets to the main response is a bad thing for > some applications. E.g. if you do any sorting or searching on the returned > fields, you need to use the original values. The same is true if any of > the values are used as a key into some other system or table lookup. > Specifically, the insertion of markup into the text changes values that > affect sorting and matching. > > Thus the wisdom of the current design that returns highlighting results > separately. > > Of course, it is very simple to merge the highlighting results into the > returned documents. The highlighting results have been thoughtfully > arranged as a lookup table using the unique ID field as the key. In > SolrJ, this is a Map<>. Thus, you can loop over the result documents, > lookup the highlight results for that document and overwrite the original > value with the highlighted value. Be sure to set your snippet size bigger > than the largest value you expect! > > Anyway, this type of thing is better handled by the application than Solr, > per se. > > static int nDocs( QueryResponse response ) { > int nReturned = 0; > if ( null != response && null != response.getResults() ) { > nReturned = response.getResults().size(); > } > return nReturned; > } > > static boolean hasHighlight( QueryResponse response ) { > boolean hasHL = false; > if ( null != response && null != response.getHighlighting() ) { > hasHL = response.getHighlighting().size() > 0; > } > return hasHL; > } > > protected void mergeHighlightResults( QueryResponse response, String > uniqueIdField ) > { > if ( nDocs(response) > 0 && hasHighlight(response) ) > { > for ( SolrDocument result : response.getResults() ) > { > Map<String, List<String>> hlDoc > = response.getHighlighting().get( > result.getFirstValue(uniqueIdField) ); > if ( null != hlDoc && hlDoc.size() > 0 ) { > for ( String fieldName : hlDoc.keySet() ) > { > List<String> hlValues = hlDoc.get( > fieldName ); > // This is the only tricky bit: > this logic may not work all that well for multi-valued fields. > // You cannot reliably match the > altered values to an original value. So, if any HL values > // are returned, just replace all > values with HL values. > // This will not work 100% of the > time. > > int ix = 0; > for ( String hlVal : hlValues ) { > if ( 0 == ix++ ) { > result.setField( > fieldName, hlVal ); > } > else { > result.addField( > fieldName, hlVal ); > } > } > } > } > } > } > } > > -----Original Message----- > From: Ahmet Arslan [mailto:[email protected]] > Sent: Thursday, June 11, 2015 6:43 AM > To: [email protected] > Subject: Re: Show all fields in Solr highlighting output > > Hi Edwin, > > I think Highlighting Behaviour of those types shifts over time. May be we > should do the reverse. > Move snippets to main response: > https://issues.apache.org/jira/browse/SOLR-3479 > > Ahmet > > > > On Thursday, June 11, 2015 11:23 AM, Zheng Lin Edwin Yeo < > [email protected]> wrote: > Hi Ahmet, > > I've tried that, but it's still not able to show. > > Those fields are actually of type=float, type=date and type=int. > > By default those field type are not able to be highlighted? > > Regards, > Edwin > > > > > On 11 June 2015 at 15:03, Ahmet Arslan <[email protected]> wrote: > > > Hi Edwin, > > > > hl.alternateField is probably what you are looking for. > > > > ahmet > > > > > > > > > > On Thursday, June 11, 2015 5:38 AM, Zheng Lin Edwin Yeo < > > [email protected]> wrote: > > Hi, > > > > Is it possible to list all the fields in the highlighting portion in > > the output? > > Currently,even when I <str name="hl.fl">*</str>, it only shows fields > > where highlighting is possible, and fields which highlighting is not > > possible is not shown. > > > > I would like to have the output where all the fields, regardless if > > highlighting is possible or not, to be shown together. > > > > > > Regards, > > Edwin > > > > ************************************************************************* > This e-mail may contain confidential or privileged information. > If you are not the intended recipient, please notify the sender > immediately and then delete it. > > TIAA-CREF > ************************************************************************* >
