<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<DIV dir=ltr align=left><SPAN class=526053412-18102006><FONT face=Arial
color=#0000ff size=2>PS A couple of lessons I learned the hard way, to do
with the necessarily multi-threaded nature of IndexSearcher (IndexReader)
use:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=526053412-18102006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=526053412-18102006><FONT face=Arial
color=#0000ff size=2>1. An IndexSearcher becomes invalid when changes are
made to the underlying index elsewhere. To test for this condition before
using other IndexSearcher methods, test
indexSearcher.getIndexReader().isCurrent(). Even that doesn't guarantee
currency, because the index could be changed after your test but before your use
of it... so you still have to handle Exceptions.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=526053412-18102006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=526053412-18102006><FONT face=Arial
color=#0000ff size=2>2. Although we're told it's a good idea to call
close() on an IndexSearcher once it's invalid, note that other threads which
still expect to use it will receive an IOException ('bad file descriptor') if
they try to access an IndexSearcher which has already been
closed.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=526053412-18102006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=526053412-18102006><FONT face=Arial
color=#0000ff size=2>Jon</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> opencms-dev-bounces@opencms.org
[mailto:opencms-dev-bounces@opencms.org] <B>On Behalf Of </B>Jonathan
Woods<BR><B>Sent:</B> 18 October 2006 13:27<BR><B>To:</B> 'The OpenCms mailing
list'<BR><B>Subject:</B> RE: [opencms-dev] Search on different fields of
structuredcontenttype.<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV dir=ltr align=left><SPAN class=885562212-18102006><FONT face=Arial
color=#0000ff size=2>Christoph, Sakshi -</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=885562212-18102006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=885562212-18102006><FONT face=Arial
color=#0000ff size=2>The approach below works fine. You need some way to
get past the OpenCms search interface and into the Lucene API, so I've attached
a snippet of code which gets you a Lucene IndexSearcher from the OpenCms
runtime framework.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=885562212-18102006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=885562212-18102006><FONT face=Arial
color=#0000ff size=2>Jon</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> opencms-dev-bounces@opencms.org
[mailto:opencms-dev-bounces@opencms.org] <B>On Behalf Of </B>Christoph
Schönfeld<BR><B>Sent:</B> 18 October 2006 11:34<BR><B>To:</B> The OpenCms
mailing list<BR><B>Subject:</B> Re: [opencms-dev] Search on different fields of
structured contenttype.<BR></FONT><BR></DIV>
<DIV></DIV><FONT face="Helvetica, Arial, sans-serif">As far as I understand
OpenCms correctly what you want is possible by providing a custom Lucene
Document Factory (which implements
org.opencms.search.documents.I_CmsDocumentFactory) as part of your own custom
OpenCms Document Type class. Your </FONT><FONT
face="Helvetica, Arial, sans-serif">implementation of the interface method
</FONT><FONT
face="Helvetica, Arial, sans-serif">"org.opencms.search.documents.I_CmsDocumentFactory.</FONT><FONT
face="Helvetica, Arial, sans-serif">newInstance(</FONT><FONT
face="Helvetica, Arial, sans-serif">cms:</FONT><FONT
face="Helvetica, Arial, sans-serif"> CmsObject, resource: </FONT><FONT
face="Helvetica, Arial, sans-serif">A_CmsIndexResource</FONT><FONT
face="Helvetica, Arial, sans-serif">, </FONT><FONT
face="Helvetica, Arial, sans-serif">language:</FONT><FONT
face="Helvetica, Arial, sans-serif"> String):
org.apache.lucene.document.Document" should be able to </FONT><FONT
face="Helvetica, Arial, sans-serif">add the custom fields you need to the
</FONT><FONT face="Helvetica, Arial, sans-serif">returned </FONT><FONT
face="Helvetica, Arial, sans-serif">Lucene Document.<BR><BR>This class has
probably to appear as the "Document type class" in the search index source
frontend (Administration View > Search Management > View index
sources > Index source overview). <BR></FONT><FONT
face="Helvetica, Arial, sans-serif"><BR>See
org.opencms.search.documents.CmsDocumentXmlPage for an example of such a class.
It extends A_CmsVfsDocument which implements the afore mentioned
interface.<BR></FONT><FONT face="Helvetica, Arial, sans-serif"><BR>I plan to use
this approach for my own project, though I did not </FONT><FONT
face="Helvetica, Arial, sans-serif">yet </FONT><FONT
face="Helvetica, Arial, sans-serif">validate it and I do not yet know how to
build the customized search on top of it.<BR></FONT><BR><FONT
face="Helvetica, Arial, sans-serif"><BR>Christoph<BR><BR></FONT><BR></BODY></HTML>