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.Document
(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
> > >
> >
> >
>