[opencms-dev] What's wrong with this search script?

Uwe König uwederkoenig at web.de
Fri Jan 20 11:21:26 CET 2006



> I just want a search function on the website :-)  Obviously it must
> work for the general public visiting the site (I use Apache to serve
> the site as described in the OpenCms manual).
> 
> It's no good if you must be logged into OpenCms *and* remember to set
> Site="/".

Okay, that's not nice, indeed. All I can say that the following code works perfectly for me: 

	    	CmsSearch search = new CmsSearch();
	    	search.init(cmsae.getCmsObject());
	    	search.setSearchRoot("/" + th.getCurrentLanguage() + "/");
	    	search.setMatchesPerPage(10);
	    	search.setPage(pageNo);
	    	search.setQuery(searchTerm);
	    	String[] fields = new String[4];
	    	fields[0] = "title";
	    	fields[1] = "content";
	    	fields[2] = "description";
	    	fields[3] = "keywords";
	    	search.setField(fields);
	    	search.setIndex("Online project (VFS)");
	
	    	List results = search.getSearchResult();


th.getCurrentLanguage() evaluates to "en" or "jp" or the like, so I can search a language-specific subtree of my folder-structure. The rest should be clear. 
Hope this helps. Best regards, 

Uwe König 



More information about the opencms-dev mailing list