Thanks a lot, it is working fine..

-LM



On 4/20/07, Laxmilal Menaria <[EMAIL PROTECTED]> wrote:

Thanks..

On 4/20/07, Digy <[EMAIL PROTECTED]> wrote:
>
> Hi All,
>
> NumberTools class is different in Lucene(Java) and Lucene.Net.
> "RADIX" is 36 in lucene and 16 in Lucene.Net. Therefore Java-Index is
> not
> compatible with .NET index.
>
> I will propose a solution for this(I marked the changes as //DIGY
> *******).
>
> Best Regards,
> DIGY
>
>
>     public class NumberTools
>     {
>
>         #region BASE36 OPS //DIGY ********** New
>         static string digits = "0123456789abcdefghijklmnopqrstuvwxyz";
>         static long[] powersOf36 =
>         {   1L,
>             36L,
>             36L*36L,
>             36L*36L*36L,
>             36L*36L*36L*36L,
>             36L*36L*36L*36L*36L,
>             36L*36L*36L*36L*36L*36L,
>             36L*36L*36L*36L*36L*36L*36L,
>             36L*36L*36L*36L*36L*36L*36L*36L,
>             36L*36L*36L*36L*36L*36L*36L*36L*36L,
>             36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,
>             36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,
>             36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L
>         };
>
>
>         public static string ToString(long lval)
>         {
>             int maxStrLen = powersOf36.Length;
>             long curval = lval;
>
>             char[] tb = new char[maxStrLen];
>             int outpos = 0;
>             for (int i = 0; i < maxStrLen; i++)
>             {
>                 long pval = powersOf36[maxStrLen - i - 1];
>                 int pos = (int)(curval / pval);
>                 tb[outpos++] = digits.Substring(pos,
> 1).ToCharArray()[0];
>                 curval = curval % pval;
>             }
>             if (outpos == 0) tb[outpos++] = '0';
>             return new string(tb, 0, outpos).TrimStart('0');
>         }
>
>         public static long ToLong(string t)
>         {
>             long ival = 0;
>             char[] tb = t.ToCharArray();
>             for (int i = 0; i < tb.Length; i++)
>             {
>                 ival += powersOf36[i] * digits.IndexOf(tb[tb.Length - i
> -
> 1]);
>             }
>             return ival;
>         }
>         #endregion
>
>
>
>         private const int RADIX = 36;   //DIGY ********** Changed
>
>         private const char NEGATIVE_PREFIX = '-';
>
>         // NB: NEGATIVE_PREFIX must be < POSITIVE_PREFIX
>         private const char POSITIVE_PREFIX = '0';
>
>         //NB: this must be less than
>         /// <summary> Equivalent to longToString(Long.MIN_VALUE
> )</summary>
>         public static readonly System.String MIN_STRING_VALUE =
> NEGATIVE_PREFIX + "0000000000000";
>
>         /// <summary> Equivalent to longToString( Long.MAX_VALUE
> )</summary>
>         public static readonly System.String MAX_STRING_VALUE =
> POSITIVE_PREFIX + "1y2p0ij32e8e7";
>
>         /// <summary> The length of (all) strings returned by [EMAIL 
PROTECTED]
> #longToString}</summary>
>         public static readonly int STR_SIZE = MIN_STRING_VALUE.Length;
>
>         /// <summary> Converts a long to a String suitable for
> indexing.</summary>
>         public static System.String LongToString(long l)
>         {
>
>             if (l == System.Int64.MinValue)
>             {
>                 // special case, because long is not symetric around
> zero
>                 return MIN_STRING_VALUE;
>             }
>
>             System.Text.StringBuilder buf = new
> System.Text.StringBuilder(STR_SIZE);
>
>             if (l < 0)
>             {
>                 buf.Append(NEGATIVE_PREFIX);
>                 l = System.Int64.MaxValue + l + 1;
>             }
>             else
>             {
>                 buf.Append(POSITIVE_PREFIX);
>             }
>             System.String num = ToString(l); //DIGY ********** Changed
>
>             int padLen = STR_SIZE - num.Length - buf.Length;
>             while (padLen-- > 0)
>             {
>                 buf.Append('0');
>             }
>             buf.Append(num);
>
>             return buf.ToString();
>         }
>
>         /// <summary> Converts a String that was returned by [EMAIL PROTECTED]
> #longToString} back to a
>         /// long.
>         ///
>         /// </summary>
>         /// <throws>  IllegalArgumentException </throws>
>         /// <summary>             if the input is null
>         /// </summary>
>         /// <throws>  NumberFormatException </throws>
>         /// <summary>             if the input does not parse (it was
> not a
> String returned by
>         /// longToString()).
>         /// </summary>
>         public static long StringToLong(System.String str)
>         {
>             if (str == null)
>             {
>                 throw new System.NullReferenceException("string cannot
> be
> null");
>             }
>             if (str.Length != STR_SIZE)
>             {
>                 throw new System.FormatException("string is the wrong
> size");
>             }
>
>             if (str.Equals(MIN_STRING_VALUE))
>             {
>                 return System.Int64.MinValue;
>             }
>
>             char prefix = str[0];
>             long l = ToLong(str.Substring(1)); //DIGY ********** Changed
>
>             if (prefix == POSITIVE_PREFIX)
>             {
>                 // nop
>             }
>             else if (prefix == NEGATIVE_PREFIX)
>             {
>                 l = l - System.Int64.MaxValue - 1;
>             }
>             else
>             {
>                 throw new System.FormatException("string does not begin
> with
> the correct prefix");
>             }
>
>             return l;
>         }
>     }
>
> -----Original Message-----
> From: George Aroush [mailto: [EMAIL PROTECTED]
> Sent: Wednesday, April 18, 2007 4:14 AM
> To: [email protected]
> Subject: RE: Exception while search in Lucene.Net and Index prepared by
> LuceneJava
>
> Hi Laxmilal,
>
> I don't have the free cycles to look into this right now.  However, now
> that
> you narrowed this down to one field, "CellNo", can you narrow it down
> even
> further to one document or does it not matter?  Also, can you try
> Field.Store.NO instead of Field.Store.YES ?
>
> Regards,
>
> -- George
>
> > -----Original Message-----
> > From: Laxmilal Menaria [mailto:[EMAIL PROTECTED]
> > Sent: Monday, April 16, 2007 5:26 AM
> > To: [email protected]
> > Subject: Re: Exception while search in Lucene.Net and Index
> > prepared by LuceneJava
> >
> > I have reindex the same, and got exception while
> > reading..also posted sample java program for indexing and
> > vb.net for reading..
> >
> > Thanks
> > --LM
> >
> > On 4/15/07, Laxmilal Menaria <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > >
> > > On 4/13/07, Laxmilal Menaria <[EMAIL PROTECTED]> wrote:
> > > >
> > > > JAVA CODE :
> > > >
> > > > import java.io.*;
> > > > import java.util.Date;
> > > >
> > > > import org.apache.lucene.analysis.standard.*;
> > > > import org.apache.lucene.document.*; import
> > > > org.apache.lucene.index.* ;
> > > >
> > > > public class Indexer {
> > > >     public static void main(String[] args)  {
> > > >         try
> > > >         {
> > > >
> > > >             File indexDir = new File("C:/LuceneApp/Testindex");
> > > >             long start = new Date().getTime();
> > > >             int numIndexed = index(indexDir);
> > > >             long end = new Date().getTime();
> > > >             System.out.println("Indexing " + numIndexed +
> > " docs took "
> > > > + (end - start) + " milliseconds");
> > > >
> > > >         }catch(Exception e)
> > > >         {
> > > >             System.out.println("Exception by
> > main=>"+e.toString());
> > > >         }
> > > >
> > > >     }
> > > > // open an index and start file directory traversal
> > > >     public static int index(File indexDir) throws IOException
> > > >     {
> > > >         System.out.println("Entering  into Index method");
> > > >             IndexWriter writer = new IndexWriter(indexDir,new
> > > > StandardAnalyzer(), true);
> > > >             writer.setUseCompoundFile(false);
> > > >
> > > >             indexFile(writer);
> > > >             int numIndexed = writer.docCount();
> > > >             writer.optimize();
> > > >             writer.close();
> > > >             return numIndexed;
> > > >
> > > >     }
> > > >     private static void indexFile(IndexWriter writer)
> > > >     {
> > > >         try
> > > >         {
> > > >             Document doc = new Document();
> > > >             doc.add(new Field("CellNo", NumberTools.longToString
> > > > (12345678),Field.Store.YES,Field.Index.TOKENIZED));
> > > >             writer.addDocument(doc);
> > > >
> > > >             doc = new Document();
> > > >             doc.add(new Field("CellNo", NumberTools.longToString
> > > > (234569455),Field.Store.YES,Field.Index.TOKENIZED));
> > > >             writer.addDocument(doc);
> > > >
> > > >             doc = new Document();
> > > >             doc.add(new Field("CellNo", NumberTools.longToString
> > > > (567895000),Field.Store.YES,Field.Index.TOKENIZED));
> > > >             writer.addDocument(doc);
> > > >
> > > >             doc = new Document();
> > > >             doc.add(new Field("CellNo", NumberTools.longToString
> > > > (789511111),Field.Store.YES,Field.Index.TOKENIZED ));
> > > >             writer.addDocument(doc);
> > > >
> > > >             doc = new Document();
> > > >             doc.add(new Field("CellNo", NumberTools.longToString
> > > > (455656448),Field.Store.YES,Field.Index.TOKENIZED));
> > > >             writer.addDocument(doc);
> > > >         }
> > > >         catch(Exception e)
> > > >         {
> > > >             System.out.println("Exception =>"+ e.toString());
> > > >         }
> > > >
> > > >
> > > >     }
> > > > }
> > > >
> > > > VB.NET CODE:
> > > >
> > > >   Dim objIndexReader As Lucene.Net.Index.IndexReader =
> > > > Lucene.Net.Index.IndexReader.Open("C:\LuceneApp\Testindex")
> > > >         Dim sResults() As String
> > > >         Dim iTotalDocs As Integer = objIndexReader.NumDocs
> > > >         Dim iCounter As Integer
> > > >         While iCounter < iTotalDocs
> > > >             ReDim Preserve sResults(iCounter)
> > > >             sResults(iCounter) =
> > > >
> > Lucene.Net.Documents.NumberTools.StringToLong(objIndexReader.Documen
> > > > t
> > > > (iCounter).Get("CellNo"))
> > > >             iCounter += 1
> > > >         End While
> > > >
> > > > On 4/13/07, Laxmilal Menaria < [EMAIL PROTECTED] > wrote:
> > > > >
> > > > > ok..thanks, I will post sample of both ..
> > > > >
> > > > > -LM
> > > > >
> > > > >
> > > > > On 4/13/07, George Aroush <[EMAIL PROTECTED] > wrote:
> > > > > >
> > > > > > Hi Laxmilal,
> > > > > >
> > > > > > Can you re-index with one field at a time and see which field
> > > > > > maybe the cause?  I'm betting it's the one you are storing
> > > > > > NumberTools.StringToLong.
> > > > > >
> > > > > > Also, can you post the sample Java code?
> > > > > >
> > > > > > Thanks!
> > > > > >
> > > > > > -- George
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Laxmilal Menaria [mailto: [EMAIL PROTECTED]
> > > > > > > Sent: Friday, April 13, 2007 7:09 AM
> > > > > > > To: [email protected]
> > > > > > > Subject: Exception while search in Lucene.Net and Index
> > > > > > > prepared by LuceneJava
> > > > > > >
> > > > > > > Hello everyone,
> > > > > > >
> > > > > > > I have created Index using MyJava program..but when I have
> > > > > > > search using .Net code, it gives exception
> > "Run-time exception
> > > > > > > thrown :
> > > > > > > System.FormatException- string is the wrong size "..
> > > > > > >
> > > > > > > MyIndexCollection have 3 Fileds: Name, Address and Cell No.
> > > > > > > and I am index Cell No as NumberTools.LongtoString,
> > and while
> > > > > > > reading convert to NumberTools.StringToLong, its working in
> > > > > > > java, but when created same with Lucene.net, it gives above
> > > > > > > exception..
> > > > > > >
> > > > > > > What is the problem? Please suggest me...
> > > > > > >
> > > > > > > My lucene version in both Java and .Net is 2.0.
> > > > > > >
> > > > > > > Thanks in advance,
> > > > > > > Laxmilal
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
>

Reply via email to