[opencms-dev] Search on different fields of structuredcontenttype.

Jonathan Woods jonathan.woods at scintillance.com
Wed Oct 18 14:44:21 CEST 2006


PS  A couple of lessons I learned the hard way, to do with the necessarily
multi-threaded nature of IndexSearcher (IndexReader) use:
 
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.
 
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.
 
Jon

  _____  

From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Jonathan Woods
Sent: 18 October 2006 13:27
To: 'The OpenCms mailing list'
Subject: RE: [opencms-dev] Search on different fields of
structuredcontenttype.


Christoph, Sakshi -
 
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.
 
Jon

  _____  

From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Christoph Schönfeld
Sent: 18 October 2006 11:34
To: The OpenCms mailing list
Subject: Re: [opencms-dev] Search on different fields of structured
contenttype.


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 implementation of the interface
method "org.opencms.search.documents.I_CmsDocumentFactory.newInstance(cms:
CmsObject, resource: A_CmsIndexResource, language: String):
org.apache.lucene.document.Document" should be able to add the custom fields
you need to the returned Lucene Document.

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). 

See org.opencms.search.documents.CmsDocumentXmlPage for an example of such a
class. It extends A_CmsVfsDocument which implements the afore mentioned
interface.

I plan to use this approach for my own project, though I did not yet
validate it and I do not yet know how to build the customized search on top
of it.


Christoph



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20061018/0e5f8330/attachment.htm>


More information about the opencms-dev mailing list