Yes, data sources can be added dynamically at runtime; for example, adding a view data source:
var newViewData = new com.ibm.xsp.model.domino.DominoViewData();
newViewData.setVar("variable by which you will refer to this data source");
newViewData.setDatabaseName("Path to database");
newViewData.setViewName("Name of View");
newViewData.setSearch("Terms to search for");
view.addData(newViewData);
The tricky part will be actually extracting the data from each view... the ideal approach to this likely depends upon how you want the data represented to the user. If you want them to see a separate "report" for each source database, then this is fairly easy: bind a repeat to a list / array of the data sources you defined, then within the repeat, bind a view panel or inner repeat to each data source instance.
If, on the other hand, you want to blend all of the results into one big repeat (obviously, a view panel would be out of the question here, given the disparate data sources), you'd probably need to do something like this:
var result = new java.util.ArrayList();
for (var eachDataSource in dataSources) { // where dataSources is an array of all the data sources you've added
var viewModel = eachDataSource.getDataModel();
var dataContainer = viewModel.getDataContainer();
var viewNavigator = dataContainer.getNavigator();
result.addAll(viewNavigator.readEntries(dataContainer.getDominoView(), 0, viewNavigator.getCount()));
}
return result;
If you bind a repeat to the above, that should show the search results from each view in a single repeat. One word of caution, however: while this is likely to be more performant than using the low-level API's to merge the search results, since the classes involved are very highly optimized, this is still likely to be a fairly expensive operation. As a result, I'd recommend setting this repeat's value to be an onload binding ($ instead of #). This requires the following:
- The repeatControls attribute of the repeat must be set to "true"
- The search criteria and views to search must be known at load time; this means you'll either need to pass this information in the query string, or store it in the sessionScope prior to loading the page. This makes this less interactive than it would be otherwise, but the performance gain is likely to be worth the tradeoff.
Hope that helps...