You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Daniel Debray (JIRA)" <ji...@apache.org> on 2013/07/01 11:46:21 UTC

[jira] [Commented] (SOLR-4980) Improve method names on SolrQuery

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

Daniel Debray commented on SOLR-4980:
-------------------------------------

### Eclipse Workspace Patch 1.0
#P trunk
Index: solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
===================================================================
--- solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java	(revision 1498294)
+++ solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java	(working copy)
@@ -808,7 +808,7 @@
     
     SolrQuery query = new SolrQuery( "*:*" );
     query.setRows( 0 );
-    query.setGetFieldStatistics( f );
+    query.addFieldStatistics( f );
     
     QueryResponse rsp = server.query( query );
     FieldStatsInfo stats = rsp.getFieldStatsInfo().get( f );
Index: solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java
===================================================================
--- solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java	(revision 1498294)
+++ solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java	(working copy)
@@ -759,17 +759,57 @@
     }
   }
 
+  /**
+   * @param v true if statistics should be returned by this query, false if not.
+   * @deprecated use #setFieldStatistics(boolean)
+   */
+  @Deprecated
   public void setGetFieldStatistics( boolean v )
   {
     this.set( StatsParams.STATS, v );
   }
   
+  /**
+   * Adds a field to the requested query.  
+   * @param field - the statistics field to add to the solr query.
+   * @deprecated use #addFieldStatistics(String...)
+   */
+  @Deprecated
   public void setGetFieldStatistics( String field )
   {
     this.set( StatsParams.STATS, true );
     this.add( StatsParams.STATS_FIELD, field );
   }
   
+  /**
+   * @param v true if statistics should be returned by this query, false if not.
+   */
+  public void setFieldStatistics( boolean v )
+  {
+    this.set( StatsParams.STATS, v );
+  }
+  
+  /**
+   * Adds a field to the requested query.  
+   * @param fields - one or more statistics fields to add to the solr query.
+   */
+  public void addFieldStatistics( String... fields)
+  {
+    this.set( StatsParams.STATS, true );
+    this.add( StatsParams.STATS_FIELD, fields );
+  }
+  
+  /**
+   * Sets the statistics fields that should be returned by this query. Statistic fields that have been already set will be overwritten.   
+   * @param fields - one or more statistics fields to add to the solr query.
+   */
+  public void setFieldStatistics( String... fields)
+  {
+    this.set( StatsParams.STATS, true );
+    this.remove(StatsParams.STATS_FIELD);
+    this.add( StatsParams.STATS_FIELD, fields );
+  }
+  
   public void addStatsFieldFacets( String field, String ... facets )
   {
     if( field == null ) {
                
> Improve method names on SolrQuery
> ---------------------------------
>
>                 Key: SOLR-4980
>                 URL: https://issues.apache.org/jira/browse/SOLR-4980
>             Project: Solr
>          Issue Type: Improvement
>          Components: clients - java
>    Affects Versions: 5.0
>            Reporter: Daniel Debray
>            Priority: Trivial
>              Labels: easyfix, patch
>             Fix For: 5.0
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> The setter method names for the field statistics in the SolrQuery class are a little bit confusing and i think they should be renamed. 
> I think a setter method should set a field to a given value and not just add a value to the existing field. For this behavior, an add method is more convinent.
> A patch is applyed to this issue. If you think is is not needed, just close this issue :).
> The existing setter methods are set to deprecated and some documentation is added to explain their behavior.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org