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

Tomer Gabel commented on SOLR-205:
----------------------------------

The following small patch (generated with diff, sorry about the format if not 
appropriate) has the following features:
* Switch to a (IMO...) tidier type mapping system with a static dictionary 
instead of an if statement hierarchy
* Adds missing type mappings (long, unsigned types etc.) -- note the warning 
about small (less than 32 bit) data types!
* Adds constructor overloads for abstract QueryBuilder that accept SolrSearcher 
instead of reading from configuration (we prefer to integrate with our own 
configuration provider)

I don't know if this is the accepted way of submitting patches, if so please 
let me know and I'll submit again if necessary.


diff -x .svn -x docs -x bin -x obj -x *.XML -x *.xml -r 
.\src\Configuration\Schema\SolrType.cs 
..\..\semingo\dev\luceneint\search\Dependencies\SolrSharp\src\Configuration\Schema\SolrType.cs
19d18
< using System.Text;
30a30,61
>         protected static readonly Dictionary<Type, string> typeMap;
> 
>         /// <summary>
>         /// Initializes the type map
>         /// </summary>
>         static SolrType()
>         {
>             typeMap = new Dictionary<Type, string>();
>             typeMap.Add( typeof( string   ), "str"   );
>             typeMap.Add( typeof( int      ), "int"   );
>             typeMap.Add( typeof( DateTime ), "date"  );
>             typeMap.Add( typeof( float    ), "float" );
>             typeMap.Add( typeof( bool     ), "bool"  );
>             typeMap.Add( typeof( long     ), "long"  );
> 
>             // As Java doesn't recognize unsigned types, they are marshalled 
> as 
>             // signed types.
>             typeMap.Add( typeof( uint     ), "int"   );
>             typeMap.Add( typeof( ulong    ), "long"  );
> 
>             // (s)byte and (u)short aren't recognized by Solr, and are 
> therefore
>             // considered integers; users are cautioned that if such fields 
> are
>             // long-typed in the Solr schema they will not be found when 
> parsing
>             // the result XML. Additionally, overflow erros may result in
>             // exceptions, so choose your types wisely!
>             typeMap.Add( typeof( sbyte    ), "int" );
>             typeMap.Add( typeof( byte     ), "int" );
>             typeMap.Add( typeof( short    ), "int" );
>             typeMap.Add( typeof( ushort   ), "int" );
>         }
> 
> 
39,60c70
<             if (type == typeof(string))
<             {
<                 return "str";
<             }
<             if (type == typeof(int))
<             {
<                 return "int";
<             }
<             if (type == typeof(DateTime))
<             {
<                 return "date";
<             }
<             if (type == typeof(float))
<             {
<                 return "float";
<             }
<             if (type == typeof(bool))
<             {
<                 return "bool";
<             }
<             if (type.IsArray)
<             {
---
>             if ( type.IsArray )
61a72,77
>             else
>             {
>                 string descriptor;
>                 if ( !typeMap.TryGetValue( type, out descriptor ) )
>                     throw new InvalidOperationException( "Unrecognized type " 
> + type + "!" );
>                 return descriptor;
63d78
<             return null;
diff -x .svn -x docs -x bin -x obj -x *.XML -x *.xml -r 
.\src\Query\QueryBuilder.cs 
..\..\semingo\dev\luceneint\search\Dependencies\SolrSharp\src\Query\QueryBuilder.cs
17d16
< using System;
19,20d17
< using System.Text;
< using System.Web;
22d18
< using org.apache.solr.SolrSharp.Query.Parameters;
23a20
> using org.apache.solr.SolrSharp.Query.Parameters;
87a85,99
>         /// Constructs an empty, default <see cref="QueryBuilder"/> object 
> with the
>         /// specified <see cref="SolrSearcher"/> object.
>         /// </summary>
>         /// <param name="solrsearcher">The solrsearcher.</param>
>         public QueryBuilder( SolrSearcher solrsearcher )
>         {
>             _solrsearcher = solrsearcher;
> 
>             if ( this._solrsearcher != null )
>             {
>                 this.SOLR_SEARCH = this._solrsearcher.SOLR + "select/";
>             }
>         }
> 
>         /// <summary>
92a105
>             : this( SolrSearchers.GetSearcher( Mode.Read ) )
94,99d106
<             this._solrsearcher = SolrSearchers.GetSearcher(Mode.Read);
< 
<             if (this._solrsearcher != null)
<             {
<                 this.SOLR_SEARCH = this._solrsearcher.SOLR + "select/";
<             }
113a121,133
>         /// Constucts an empty, default QueryBuilder object with the specified
>         /// <see cref="SolrSearcher"/>, and adds the Page parameter.
>         /// </summary>
>         /// <param name="page">integer to be used as the Page 
> parameter</param>
>         /// <param name="solrsearcher">The <see cref="SolrSearcher"/> 
> instance for
>         /// this QueryBuilder.</param>
>         public QueryBuilder( SolrSearcher solrsearcher, int page )
>             : this( solrsearcher )
>         {
>             this._page = page;
>         }
> 
>         /// <summary>
124a145,156
>         /// the DefaultSearchField, setting the Page parameter to 1.
>         /// </summary>
>         /// <param name="solrsearcher">The <see cref="SolrSearcher"/> 
> instance for
>         /// this QueryBuilder.</param>
>         /// <param name="searchterms">keywords to query against the 
> DefaultSearchField</param>
>         public QueryBuilder( SolrSearcher solrsearcher, string searchterms )
>             : this( solrsearcher, searchterms, 1 )
>         {
>         }
> 
>         /// <summary>
>         /// Constructs a QueryBuilder object to execute a keyword search 
> against
144a177,199
>         /// Constructs a QueryBuilder object to execute a keyword search 
> against
>         /// the DefaultSearchField.
>         /// </summary>
>         /// <param name="searchterms">keywords to query against the 
> DefaultSearchField</param>
>         /// <param name="page">integer to be used as the Page 
> parameter</param>
>         /// <param name="solrsearcher">The <see cref="SolrSearcher"/> 
> instance for
>         /// this QueryBuilder.</param>
>         public QueryBuilder( SolrSearcher solrsearcher, string searchterms, 
> int page )
>             : this( solrsearcher )
>         {
>             this._query = new Query();
>             if ( searchterms != null && searchterms != "" )
>             {
>                 QueryParameter qp = new QueryParameter( 
> this.SolrSearcher.SolrSchema.DefaultSearchField, searchterms );
>                 List<QueryParameter> qpList = new List<QueryParameter>();
>                 qpList.Add( qp );
>                 QueryParameterCollection qps = new QueryParameterCollection( 
> "default", qpList );
>                 this._query.AddQueryParameters( qps, ParameterJoin.OR );
>             }
>             this._page = page;
>         }
> 
>         /// <summary>
196a252,311
> 
>         /// <summary>
>         /// Constructs a QueryBuilder object to execute a query based on the 
>         /// arKeys and arValues collections. A query request will be 
> formulated based on
>         /// aligned index values in arKeys and arValues respectively, i.e.
>         /// arKeys[0] will be evaluated against arValues[0]. Use this only to 
> bypass
>         /// the default behavior and if you need to set name/value pairs for 
> the url
>         /// request directly.
>         /// </summary>
>         /// <param name="solrsearcher">The <see cref="SolrSearcher"/> 
> instance for
>         /// this QueryBuilder.</param>
>         /// <param name="arKeys">Collection of request parameters</param>
>         /// <param name="arValues">Collection of request values</param>
>         /// <param name="page">integer to be used as the Page 
> parameter</param>
>         public QueryBuilder( SolrSearcher solrsearcher, string[] arKeys, 
> string[] arValues, int page )
>             : this( solrsearcher )
>         {
>             Dictionary<string, string> searchkeyvalues = new 
> Dictionary<string, string>();
>             for ( int x = 0; x < arKeys.Length; x++ )
>                 searchkeyvalues.Add( arKeys[ x ], arValues[ x ] );
> 
>             this._searchkeyvalues = searchkeyvalues;
>             this._page = page;
>         }
> 
>         /// <summary>
>         /// Constructs a QueryBuilder object to execute a query based on the 
>         /// searchkeyvalues dictionary. A query request will be formulated 
> based on
>         /// the KeyValuePair objects contained in searchkeyvalues. Use 
>         /// this only to bypass the default behavior and if you need to set 
> name/value 
>         /// pairs for the url request directly.
>         /// </summary>
>         /// <param name="solrsearcher">The <see cref="SolrSearcher"/> 
> instance for
>         /// this QueryBuilder.</param>
>         /// <param name="searchkeyvalues">Dictionary of parameter/value 
> pairs</param>
>         /// <param name="page">integer to be used as the Page 
> parameter</param>
>         public QueryBuilder( SolrSearcher solrsearcher, Dictionary<string, 
> string> searchkeyvalues, int page )
>             : this( solrsearcher )
>         {
>             this._searchkeyvalues = searchkeyvalues;
>             this._page = page;
>         }
> 
>         /// <summary>
>         /// Constructs a QueryBuilder object to execute a query based on the 
>         /// Query object.  This is the most used constructor for this object 
> and the
>         /// "best" way to create a search request, as the Query object and 
> QueryBuilder
>         /// work together to save you from having to figure out syntax in 
> building a
>         /// (sometimes complex) search query within a url.
>         /// </summary>
>         /// <param name="solrsearcher">The <see cref="SolrSearcher"/> 
> instance for
>         /// this QueryBuilder.</param>
>         /// <param name="query">Query object containing the field(s) to be 
> queried against a solr index</param>
>         /// <param name="page">integer to be used as the Page 
> parameter</param>
>         public QueryBuilder( SolrSearcher solrsearcher, Query query, int page 
> )
>             : this( solrsearcher )
>         {
>             this._query = query;
>             this._page = page;
>         }


> SolrSharp - a C# client API for Solr
> ------------------------------------
>
>                 Key: SOLR-205
>                 URL: https://issues.apache.org/jira/browse/SOLR-205
>             Project: Solr
>          Issue Type: New Feature
>          Components: clients - C#
>         Environment: Microsoft Windows, .Net Framework 2.0
>            Reporter: Jeff Rodenburg
>            Assignee: Jeff Rodenburg
>            Priority: Minor
>         Attachments: solrsharp-1.2-08302007.zip
>
>
> SolrSharp is a client API written in C# using the .Net framework to interact 
> with Apache Solr.

-- 
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