API search from a Java program
Following from my earlier post on this forum and a helpful Rainman's reply, I managed to make the API- based search work from a Java program. I am posting the steps (perhaps clumsy at places, but working) here as it may be of interest to others. Setup:
- add LuceneSearch.jar on your classpath
- modify lsearch.conf, lsearch-global.conf and lsearch.log4j and put them to your project's folder
[edit] lsearch.conf
- set MWConfig.global to point to lsearch-global.conf
- set Indexes.path
- set Logging.logconfig to point to lsearch.log4j
[edit] lsearch-global.conf
- make sure that you point to localhost
code:
Configuration config = Configuration.open();
SearcherCache cache = SearcherCache.getInstance();
URI uri = new URI("http://localhost:8123/search/wiki/maradona?limit=3");
HashMap query = new QueryStringMap(uri);
double version = getVersion(query);
SearchEngine search = new SearchEngine();
IndexId iid = IndexId.get("wiki");
iid.forceMySearch();
cache.waitForInitialDeployment();
cache.getSearcherPoolStatus(iid);
cache.waitForInitialDeployment();
SearchResults res = search.search("wiki","search","maradona",query,version);
for (ResultSet title : res.getResults())
{
String result = title.title;
System.out.println(result);
}