lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eyal Post" <eyalp...@epocalipse.com>
Subject RE: bug in SegmentTermVector.IndexOf ?
Date Sat, 30 May 2009 21:31:15 GMT
You can simply use  
int res = System.Array.BinarySearch(terms, termText, StringComparer.Ordinal)

Eyal

> -----Original Message-----
> From: Franklin Simmons [mailto:fsimmons@sccmediaserver.com] 
> Sent: Friday, May 29, 2009 22:23 PM
> To: lucene-net-dev@incubator.apache.org
> Subject: bug in SegmentTermVector.IndexOf ?
> 
> Greetings,
> 
>  
> 
> I hope I have this all wrong;  I haven't seen this issue raised. 
> 
>  
> 
> At index time term vectors are sorted using String.CompareOrdinal.
> However method IndexOf  of class SegmentTermVector invokes 
> System.Array.BinarySearch, which is using String.Compare:
> 
>  
> 
> public virtual int IndexOf(System.String termText)
> 
> {
> 
>                                 if (terms == null)
> 
>                                                 return - 1;
> 
> int res = System.Array.BinarySearch(terms, termText);
> 
> return res >= 0 ? res : - 1;
> 
> }
> 
>  
> 
>  
> 
> As implemented this method always (for me, anyway) returns a 
> negative number.  The modification below works, but I need to 
> know if this is actually a bug and if so, what is the correct fix.
> 
>  
> 
>  
> 
> public class SegmentTermVector : TermFreqVector
> 
> {
> 
>                 . . .
> 
>  
> 
> private class TermVectorComparer : System.Collections.IComparer 
> 
> {
> 
> public int Compare(object a, object b)
> 
> {                
> 
> return String.CompareOrdinal((string)a, (string)b);            
> 
> }
> 
> }
> 
>  
> 
> public virtual int IndexOf(System.String termText)
> 
> {
> 
>                                 if (terms == null)
> 
>                                                 return - 1;
> 
> int res = System.Array.BinarySearch(terms, termText, new 
> TermVectorComparer());
> 
> return res >= 0 ? res : - 1;
> 
> }
> 
>                 
> 
> . . . 
> 
> }
> 
>  
> 
>  
> 
> Franklin Simmons
> 
>  
> 
> 


Mime
View raw message