You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "Digy (JIRA)" <ji...@apache.org> on 2009/11/18 20:50:39 UTC

[jira] Created: (LUCENENET-285) Problem with "CurrentCulture"

Problem with "CurrentCulture"
-----------------------------

                 Key: LUCENENET-285
                 URL: https://issues.apache.org/jira/browse/LUCENENET-285
             Project: Lucene.Net
          Issue Type: Bug
            Reporter: Digy


Hi Folks,

There is a bug in utilizing Thread.CurrentThread.CurrentCulture.

A float number such as 2.5 can be converted to string as "2.5" or  "2,5"  depending on the culture.
if it is converted to "2,5", some of the tests(ex, TestAnalyzerReturningNull) under "QueryParser" fails
_(cause: buffer.Append(minimumSimilarity.ToString()) in FuzzyQuery.cs line 204)_
Since they make string comparison of the queries.


There can be two solutions to this
1- Changing, for ex, 
	_buffer.Append(minimumSimilarity.ToString())_
	to
	_buffer.Append(SupportClass.Single.ToString(minimumSimilarity)_
in Lucene.NET core (there may be many other places)
or
2- Changing the current-culture of the test cases to "en-US".

Solution-2 is the simplest way, but what is the correct one?

DIGY









-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LUCENENET-285) Problem with "CurrentCulture"

Posted by "Nicholas Paldino (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENENET-285?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780176#action_12780176 ] 

Nicholas Paldino commented on LUCENENET-285:
--------------------------------------------

Andrei,

Well, not ALL cases =)  But most of them, yes, because when writing to an index, and reading from it, culture formatting shouldn't come into play when numeric values are read/written to an index.  I definitely agree.

To elaborate on the extension method, I would recommend when the code diverges to write "ToInvariantString()" extension methods for float, double, int, long which would allow for an easy way to write invariant versions of the numbers consistently, as opposed to always querying for InvariantCulture at the call site (better encapsulation of the code), but as mentioned, that's for a future date.

> Problem with "CurrentCulture"
> -----------------------------
>
>                 Key: LUCENENET-285
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-285
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Digy
>
> Hi Folks,
> There is a bug in utilizing Thread.CurrentThread.CurrentCulture.
> A float number such as 2.5 can be converted to string as "2.5" or  "2,5"  depending on the culture.
> if it is converted to "2,5", some of the tests(ex, TestAnalyzerReturningNull) under "QueryParser" fails
> _(cause: buffer.Append(minimumSimilarity.ToString()) in FuzzyQuery.cs line 204)_
> Since they make string comparison of the queries.
> There can be two solutions to this
> 1- Changing, for ex, 
> 	_buffer.Append(minimumSimilarity.ToString())_
> 	to
> 	_buffer.Append(SupportClass.Single.ToString(minimumSimilarity)_
> in Lucene.NET core (there may be many other places)
> or
> 2- Changing the current-culture of the test cases to "en-US".
> Solution-2 is the simplest way, but what is the correct one?
> DIGY

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LUCENENET-285) Problem with "CurrentCulture"

Posted by "George Aroush (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENENET-285?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780201#action_12780201 ] 

George Aroush commented on LUCENENET-285:
-----------------------------------------

Looks good, commit away.  Thanks DIGY!

> Problem with "CurrentCulture"
> -----------------------------
>
>                 Key: LUCENENET-285
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-285
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Digy
>         Attachments: LUCENENET-285.patch
>
>
> Hi Folks,
> There is a bug in utilizing Thread.CurrentThread.CurrentCulture.
> A float number such as 2.5 can be converted to string as "2.5" or  "2,5"  depending on the culture.
> if it is converted to "2,5", some of the tests(ex, TestAnalyzerReturningNull) under "QueryParser" fails
> _(cause: buffer.Append(minimumSimilarity.ToString()) in FuzzyQuery.cs line 204)_
> Since they make string comparison of the queries.
> There can be two solutions to this
> 1- Changing, for ex, 
> 	_buffer.Append(minimumSimilarity.ToString())_
> 	to
> 	_buffer.Append(SupportClass.Single.ToString(minimumSimilarity)_
> in Lucene.NET core (there may be many other places)
> or
> 2- Changing the current-culture of the test cases to "en-US".
> Solution-2 is the simplest way, but what is the correct one?
> DIGY

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LUCENENET-285) Problem with "CurrentCulture"

Posted by "Nicholas Paldino (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENENET-285?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12779664#action_12779664 ] 

Nicholas Paldino commented on LUCENENET-285:
--------------------------------------------

The ToString equivalents in Java always want the behavior of the ToString methods in .NET when you have an invariant culture, for the most part, it just so happens that the en-US culture will produce the same result when calling ToString on most numbers of this magnitude.

That being said, it looks to me that the intention here is to use an invariant representation of the float.

Right now, I would call ToString and pass the result of a call to the static property InvariantCulture on CultureInfo wo the string is formatted correctly. When the code diverges, this should be placed in an extension method for float, double, int, long, etc etc.

It also indicates that the test is incomplete as it isn't testing the boundary condition. The test should change the culture of the thread to a culture where calling ToString (without parameters) will result in a different character for the decimal point and then reverts back to en-US and verifies that everything still works.

> Problem with "CurrentCulture"
> -----------------------------
>
>                 Key: LUCENENET-285
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-285
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Digy
>
> Hi Folks,
> There is a bug in utilizing Thread.CurrentThread.CurrentCulture.
> A float number such as 2.5 can be converted to string as "2.5" or  "2,5"  depending on the culture.
> if it is converted to "2,5", some of the tests(ex, TestAnalyzerReturningNull) under "QueryParser" fails
> _(cause: buffer.Append(minimumSimilarity.ToString()) in FuzzyQuery.cs line 204)_
> Since they make string comparison of the queries.
> There can be two solutions to this
> 1- Changing, for ex, 
> 	_buffer.Append(minimumSimilarity.ToString())_
> 	to
> 	_buffer.Append(SupportClass.Single.ToString(minimumSimilarity)_
> in Lucene.NET core (there may be many other places)
> or
> 2- Changing the current-culture of the test cases to "en-US".
> Solution-2 is the simplest way, but what is the correct one?
> DIGY

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LUCENENET-285) Problem with "CurrentCulture"

Posted by "Digy (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENENET-285?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Digy updated LUCENENET-285:
---------------------------

    Attachment: LUCENENET-285.patch

No more failing tests under QueryParser related with CurrentCulture.
I replaced all "System.Sigle.Parse"s  with SupportClass.System.Parse

DIGY

> Problem with "CurrentCulture"
> -----------------------------
>
>                 Key: LUCENENET-285
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-285
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Digy
>         Attachments: LUCENENET-285.patch
>
>
> Hi Folks,
> There is a bug in utilizing Thread.CurrentThread.CurrentCulture.
> A float number such as 2.5 can be converted to string as "2.5" or  "2,5"  depending on the culture.
> if it is converted to "2,5", some of the tests(ex, TestAnalyzerReturningNull) under "QueryParser" fails
> _(cause: buffer.Append(minimumSimilarity.ToString()) in FuzzyQuery.cs line 204)_
> Since they make string comparison of the queries.
> There can be two solutions to this
> 1- Changing, for ex, 
> 	_buffer.Append(minimumSimilarity.ToString())_
> 	to
> 	_buffer.Append(SupportClass.Single.ToString(minimumSimilarity)_
> in Lucene.NET core (there may be many other places)
> or
> 2- Changing the current-culture of the test cases to "en-US".
> Solution-2 is the simplest way, but what is the correct one?
> DIGY

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LUCENENET-285) Problem with "CurrentCulture"

Posted by "Andrei Iliev (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LUCENENET-285?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12780152#action_12780152 ] 

Andrei Iliev commented on LUCENENET-285:
----------------------------------------

I agree with Nicholas, I would prefer to use invariant culture in  all ToString() Lecene.Net classes. 

> Problem with "CurrentCulture"
> -----------------------------
>
>                 Key: LUCENENET-285
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-285
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Digy
>
> Hi Folks,
> There is a bug in utilizing Thread.CurrentThread.CurrentCulture.
> A float number such as 2.5 can be converted to string as "2.5" or  "2,5"  depending on the culture.
> if it is converted to "2,5", some of the tests(ex, TestAnalyzerReturningNull) under "QueryParser" fails
> _(cause: buffer.Append(minimumSimilarity.ToString()) in FuzzyQuery.cs line 204)_
> Since they make string comparison of the queries.
> There can be two solutions to this
> 1- Changing, for ex, 
> 	_buffer.Append(minimumSimilarity.ToString())_
> 	to
> 	_buffer.Append(SupportClass.Single.ToString(minimumSimilarity)_
> in Lucene.NET core (there may be many other places)
> or
> 2- Changing the current-culture of the test cases to "en-US".
> Solution-2 is the simplest way, but what is the correct one?
> DIGY

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (LUCENENET-285) Problem with "CurrentCulture"

Posted by "Digy (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LUCENENET-285?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Digy resolved LUCENENET-285.
----------------------------

    Resolution: Fixed
      Assignee: Digy

committed.
DIGY

> Problem with "CurrentCulture"
> -----------------------------
>
>                 Key: LUCENENET-285
>                 URL: https://issues.apache.org/jira/browse/LUCENENET-285
>             Project: Lucene.Net
>          Issue Type: Bug
>            Reporter: Digy
>            Assignee: Digy
>         Attachments: LUCENENET-285.patch
>
>
> Hi Folks,
> There is a bug in utilizing Thread.CurrentThread.CurrentCulture.
> A float number such as 2.5 can be converted to string as "2.5" or  "2,5"  depending on the culture.
> if it is converted to "2,5", some of the tests(ex, TestAnalyzerReturningNull) under "QueryParser" fails
> _(cause: buffer.Append(minimumSimilarity.ToString()) in FuzzyQuery.cs line 204)_
> Since they make string comparison of the queries.
> There can be two solutions to this
> 1- Changing, for ex, 
> 	_buffer.Append(minimumSimilarity.ToString())_
> 	to
> 	_buffer.Append(SupportClass.Single.ToString(minimumSimilarity)_
> in Lucene.NET core (there may be many other places)
> or
> 2- Changing the current-culture of the test cases to "en-US".
> Solution-2 is the simplest way, but what is the correct one?
> DIGY

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.