[opencms-dev] Search on different fields of structuredcontenttype.
Jonathan Woods
jonathan.woods at scintillance.com
Sat Jan 20 20:30:55 CET 2007
Sami -
You're right - there's no need to create a new class to represent your
custom content; the resource type is still OpenCms's XML content type.
The resource type is _not_ the same as the search config's so-called
document type, which as you know is defined in opencms-search.xml. It may
be coincidentally named the same, but that's as far as it goes. If you look
in opencms-search.xml as it ships with OpenCms, you'll see a <documenttype>
node for a document type called 'xmlcontent'. All you need is to create
another entry, named however you like - but for clarity probably using the
same name as your resource type - and with your own implementation of
I_CmsDocument.
When you've added this, don't forget also to include your new document type
later on in the opencms-search.xml file, underneath the
<indexsources><indexsource><documenttypes-indexed> node... otherwise it
won't ever be indexed.
You may find you also need to remove the first entry in opencms-search.xml,
the one which maps a resource type '*' to a document type called 'generic'.
I can't recall now, but I think I had to do that to stop my XML content from
being indexed by the wrong Lucene document factory - certainly everything's
working fine without it.
Jon
_____
From: sfdbfoui at host2.scintillance.com
[mailto:sfdbfoui at host2.scintillance.com] On Behalf Of Sami Nygard
Sent: 20 January 2007 14:23
To: The OpenCms mailing list
Subject: RE: [opencms-dev] Search on different fields of
structuredcontenttype.
I'm having this problem that my resource type gets associated with the wrong
document factory.
Ref.:
http://mail.opencms.org/pipermail/opencms-dev/2006q2/024011.html
How did you get around this problem?
My xmlcontent custom resource type (registered in modules) shouldn't need
its own resource type class (e.g. extends A_CmsResourceType)? Just the
implementation of I_CmsDocumentFactory (I extended A_CmsVfsDocument) for the
indexing?
Thanks
/Sami
On Oct 18, 2006 02:44 PM, Jonathan Woods wrote:
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/20070120/c85bc563/attachment.htm>
More information about the opencms-dev
mailing list