[ https://issues.apache.org/jira/browse/SOLR-20?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12483051 ]
Thierry Collogne commented on SOLR-20: -------------------------------------- I found that there was no way of adding highlight paramters to an SolrQuery, so I made some modifications to SolrQuery.java and ParamNames.java to allow highlighting Changes to SolrQuery First add a new variable private HighlightParams _highlight = new HighlightParams(); Than I defined a new innerclass (a bit like FacetParams) public static class HighlightParams { public List<String> field = new ArrayList<String>(); public int snippets = 3; public int fragsize = 100; public String simple_pre = "<b>"; public String simple_post = "</b>"; public boolean isEnabled() { return field.size() > 0; } } Than add the following methods public void addHighlightField( String f ) { _highlight.field.add( f ); } public void setHighlightSnippets( int snippets ) { _highlight.snippets = snippets; } public void setHighlightFragSize( int fragsize ) { _highlight.fragsize = fragsize; } // ATTENTION : only simple tags. No quotes like in <span class="tag"> public void setHighlightSurroundingTags( String pre, String post ) { _highlight.simple_pre = pre; _highlight.simple_post = post; } Add the following code to getQueryString method (for example right before return builder.toString();) if( _highlight.isEnabled() ) { builder.append( '&' ).append( ParamNames.HIGHLIGHT ).append( "=true" ); builder.append( '&' ).append( ParamNames.HIGHLIGHT_FIELDS ).append( "=" ); for( String f : _highlight.field ) { builder.append( f ).append( ',' ); } builder.append( '&' ).append( ParamNames.HIGHLIGHT_SNIPPETS ).append( "=" ).append( _highlight.snippets ); builder.append( '&' ).append( ParamNames.HIGHLIGHT_FRAGSIZE ).append( "=" ).append( _highlight.fragsize ); builder.append( '&' ).append( ParamNames.HIGHLIGHT_SIMPLE_PRE ).append( "=" ).append( _highlight.simple_pre ); builder.append( '&' ).append( ParamNames.HIGHLIGHT_SIMPLE_POST ).append( "=" ).append( _highlight.simple_post ); } Changes to ParamNames.java Add/modify the following variables /** wether to highlight */ public static final String HIGHLIGHT = "hl"; /** fields to highlight */ public static final String HIGHLIGHT_FIELDS = "hl.fl"; /** maximum highlight fragments to return */ public static final String HIGHLIGHT_SNIPPETS = "hl.snippets"; /** override default highlight fragsize */ public static final String HIGHLIGHT_FRAGSIZE = "hl.fragsize"; /** override default pre highlight */ public static final String HIGHLIGHT_SIMPLE_PRE = "hl.simple.pre"; /** override default post highlight */ public static final String HIGHLIGHT_SIMPLE_POST = "hl.simple.post"; This can be used as follwed SolrClient client = new SolrClientImpl( new URL("http://localhost:8080/solr/") ); // required query.addHighlightField("title"); query.addHighlightField("content"); // following is optional query.setHighlightFragSize(100); query.setHighlightSnippets(3); query.setHighlightSurroundingTags("<i>","</i>"); I think that is all. If I forgot something, post it here. One remark. The setHighlightSurroundingTags method can only take simple tags, no tags containing quotes or such. Greetz. > A simple Java client for updating and searching > ----------------------------------------------- > > Key: SOLR-20 > URL: https://issues.apache.org/jira/browse/SOLR-20 > Project: Solr > Issue Type: New Feature > Components: clients - java > Environment: all > Reporter: Darren Erik Vengroff > Priority: Minor > Attachments: DocumentManagerClient.java, DocumentManagerClient.java, > solr-client-java-2.zip.zip, solr-client-java.zip, solr-client-sources.jar, > solr-client.zip, solr-client.zip, solr-client.zip, SolrClientException.java, > SolrServerException.java > > > I wrote a simple little client class that can connect to a Solr server and > issue add, delete, commit and optimize commands using Java methods. I'm > posting here for review and comments as suggested by Yonik. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.