[opencms-dev] Customise search ERROR [OpenCMS 6.0] (resend)
David
db92rj45 at gmail.com
Fri Jul 29 12:43:50 CEST 2005
Hi,
I am trying to customise the search behaviour in OpenCMS such that to allow
an application to dynamically create a new index source and search index
from an arbitrary set of files in VFS and perform a search on those files.
The code that I am using is given below. When I run this from a JSP page it
returned with an error saying *No analyzer found for language "null". *The
trace log for this error is given at the bottom which points to method
getAnalyzer() in CmsSearchManager. So I checked the source code of this
method and it looks perfectly normal given that I already set the locale for
my CmsSearchIndex object to 'en'. I even test printing out the analyzer
class name (see code) using getAnalyzers() method of the CmsSearchManager to
make sure that analyzer for 'en' locale exists.
So the analyzer is there and the locale has been set for the CmsSearchIndex
object, why does it still complain about the analyzer being not found and
weird enough in the error message it seems not able to detect the locale
("null" value)? Has anyone experienced this before and perhaps could provide
some insights? Thanks very much for your prompt response.
Rgds,
David.
// Define the document set from files
ArrayList docPaths = new ArrayList();
docPaths.add("/sites/mysite/file1.doc");
docPaths.add("/sites/mysite/file2.pdf");
docPaths.add("/sites/mysite/file3.txt");
String query = "hello*";
// Define index source
CmsSearchIndexSource indexSource = new CmsSearchIndexSource();
indexSource.setName("tempIndexSource");
indexSource.setIndexerClassName("org.opencms.search.CmsVfsIndexer");
indexSource.addDocumentType("xmlpage");
indexSource.addDocumentType("xmlcontent");
indexSource.addDocumentType("page");
indexSource.addDocumentType("text");
indexSource.addDocumentType("pdf");
indexSource.addDocumentType("rtf");
indexSource.addDocumentType("html");
indexSource.addDocumentType("msword");
indexSource.addDocumentType("msexcel");
indexSource.addDocumentType("mspowerpoint");
indexSource.addDocumentType("image");
indexSource.addDocumentType("generic");
// Add documents to index source
for (Iterator pointerIt = docPaths.iterator(); pointerIt.hasNext();) {
String pointer = (String) pointerIt.next();
// create a document object from this pointer
indexSource.addResourceName(pointer);
}
// Instantiate an index from the index source
CmsSearchIndex index = new CmsSearchIndex();
index.setName("tempIndex");
index.addSourceName(indexSource.getName());
index.setLocale("en");
index.setRebuildMode(CmsSearchIndex.AUTO_REBUILD);
index.initialize();
// Test to make sure analyzer for locale 'en' exists
CmsSearchManager searchMgr = OpenCms.getSearchManager();
CmsSearchAnalyzer analyzer = (CmsSearchAnalyzer) searchMgr.getAnalyzers
().get("en");
out.println("Analyzer for locale 'en' is "+analyzer.getClassName());
// Update the index (build it)
searchMgr.addAnalyzer(analyzer);
searchMgr.addSearchIndexSource(indexSource);
searchMgr.addSearchIndex(index);
searchMgr.updateIndex(index.getName());
// Code to search using this indexer...
<<< ERROR TRACE MESSAGE >>>>
org.opencms.search.CmsIndexException: No analyzer found for language "null".
at org.opencms.search.CmsSearchManager.getAnalyzer(CmsSearchManager.java:692)
at org.opencms.search.CmsSearchIndex.getIndexWriter(CmsSearchIndex.java:328)
at org.opencms.search.CmsSearchManager.updateIndex(CmsSearchManager.java:600)
at org.opencms.search.CmsSearchManager.updateIndex(CmsSearchManager.java:557)
at org.opencms.search.CmsSearchManager.updateIndex(CmsSearchManager.java:544)
at .....
...... (omitted)
<<<ERROR>>>>
--
Rgds,
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20050729/727fed65/attachment.htm>
More information about the opencms-dev
mailing list