[jsword-devel] Lucene

Zhaojun Li lzj369 at gmail.com
Mon Dec 18 22:38:49 MST 2006


Here are the two methods, one original, one mirror.

 /**
     * Dig down into a Key indexing as we go.
     */
    private void newgenerateSearchIndexImpl( List errors, IndexWriter
writer, Key key) throws BookException, IOException
    {
        int bookNum = 0;
        int oldBookNum = -1;
        int percent = 0;
        String name = ""; //$NON-NLS-1$
        String text = ""; //$NON-NLS-1$
        BookData data = null;
        Key subkey = null;
        Verse verse = null;
        Document doc = null;
        for (Iterator it = key.iterator(); it.hasNext(); )
        {
            subkey = (Key) it.next();
            if (subkey.canHaveChildren())
            {
                newgenerateSearchIndexImpl( errors, writer, subkey);
            }
            else
            {
                data = null;
                try
                {
                    data = book.getData(subkey);
                }
                catch (BookException e)
                {
                    errors.add(subkey);
                    continue;
                }

                text = data.getVerseText();

                // Do the actual indexing
                if (text != null && text.length() > 0)
                {
                    doc = new Document();
                    doc.add(new Field(FIELD_NAME, subkey.getOsisRef(),
Field.Store.YES, Field.Index.NO));
                    doc.add(new Field(FIELD_BODY, new StringReader(text)));
                    writer.addDocument(doc);
                }

                // report progress
                verse = KeyUtil.getVerse(subkey);

                try
                {
                    percent = 95 * verse.getOrdinal() /
BibleInfo.versesInBible();
                    bookNum = verse.getBook();
                    if (oldBookNum != bookNum)
                    {
                        name = BibleInfo.getBookName(bookNum);
                        oldBookNum = bookNum;
                    }
                }
                catch (NoSuchVerseException ex)
                {
                    log.error("Failed to get book name from verse: " +
verse, ex); //$NON-NLS-1$
                    assert false;
                    name = subkey.getName();
                }


            }
        }
    }

    /**
     * Dig down into a Key indexing as we go.
     */
    private void generateSearchIndexImpl(Job job, List errors, IndexWriter
writer, Key key) throws BookException, IOException
    {
        int bookNum = 0;
        int oldBookNum = -1;
        int percent = 0;
        String name = ""; //$NON-NLS-1$
        String text = ""; //$NON-NLS-1$
        BookData data = null;
        Key subkey = null;
        Verse verse = null;
        Document doc = null;
        for (Iterator it = key.iterator(); it.hasNext(); )
        {
            subkey = (Key) it.next();
            if (subkey.canHaveChildren())
            {
                generateSearchIndexImpl(job, errors, writer, subkey);
            }
            else
            {
                data = null;
                try
                {
                    data = book.getData(subkey);
                }
                catch (BookException e)
                {
                    errors.add(subkey);
                    continue;
                }

                text = data.getVerseText();

                // Do the actual indexing
                if (text != null && text.length() > 0)
                {
                    doc = new Document();
                    doc.add(new Field(FIELD_NAME, subkey.getOsisRef(),
Field.Store.YES, Field.Index.NO));
                    doc.add(new Field(FIELD_BODY, new StringReader(text)));
                    writer.addDocument(doc);
                }

                // report progress
                verse = KeyUtil.getVerse(subkey);

                try
                {
                    percent = 95 * verse.getOrdinal() /
BibleInfo.versesInBible();
                    bookNum = verse.getBook();
                    if (oldBookNum != bookNum)
                    {
                        name = BibleInfo.getBookName(bookNum);
                        oldBookNum = bookNum;
                    }
                }
                catch (NoSuchVerseException ex)
                {
                    log.error("Failed to get book name from verse: " +
verse, ex); //$NON-NLS-1$
                    assert false;
                    name = subkey.getName();
                }

                job.setProgress(percent, Msg.INDEXING.toString(name));

                // This could take a long time ...
                Thread.yield();
                if (Thread.currentThread().isInterrupted())
                {
                    break;
                }
            }
        }
    }


On 12/19/06, Zhaojun Li <lzj369 at gmail.com> wrote:
>
> Hi, Dear all,
>
> I am new to Lucene, so please help.
>
> I need to remove the job class from the current Lucene implementation.
> What I did is: create mirror method from generateSearchIndexImpl by removing
> any Job class reference. I tested it and it works.
>
> However, the speed is not good.  In the design, it is a recursive call.
> How to do multithreading for this? I mean by usual thread class, not JSWORD
> Job api.
>
> Thanks!
>
> Zhaojun
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.crosswire.org/pipermail/jsword-devel/attachments/20061219/0d83f8f5/attachment-0001.html 


More information about the jsword-devel mailing list