@RequestMapping( value = {"/", "/index"}, method = RequestMethod.GET) public String home(Model model) { // Two Test Dataset from datehub.io InputStream in2005 = servletContext.getResourceAsStream("/WEB-INF/content/ibm-publications-2005.rdf"); InputStream in2006 = servletContext.getResourceAsStream("/WEB-INF/content/ibm-publications-2006.rdf"); try { ArrayList<RdfModel> rms2005 = RdfProcess.processRDF(in2005); Boolean b = rms2005.addAll(RdfProcess.processRDF(in2006)); for (int i = 0; i < rms2005.size(); i++) jc.execute( new Delete.Builder(String.valueOf(i)) .index("publications") .type("publication") .build()); RdfSearch.Indexing(jc, rms2005); model.addAttribute("rdfModel", new RdfModel()); } catch (Exception e) { e.printStackTrace(); } return "index"; }
@Controller public class MainController { private @Autowired ServletContext servletContext; private JestClient jc = RdfSearch.Init(); @ModelAttribute("RdfModel") public RdfModel getUserForm() { return new RdfModel(); } @RequestMapping( value = {"/", "/index"}, method = RequestMethod.GET) public String home(Model model) { // Two Test Dataset from datehub.io InputStream in2005 = servletContext.getResourceAsStream("/WEB-INF/content/ibm-publications-2005.rdf"); InputStream in2006 = servletContext.getResourceAsStream("/WEB-INF/content/ibm-publications-2006.rdf"); try { ArrayList<RdfModel> rms2005 = RdfProcess.processRDF(in2005); Boolean b = rms2005.addAll(RdfProcess.processRDF(in2006)); for (int i = 0; i < rms2005.size(); i++) jc.execute( new Delete.Builder(String.valueOf(i)) .index("publications") .type("publication") .build()); RdfSearch.Indexing(jc, rms2005); model.addAttribute("rdfModel", new RdfModel()); } catch (Exception e) { e.printStackTrace(); } return "index"; } @RequestMapping(value = "/performSearch", method = RequestMethod.POST) public String performSearch( @ModelAttribute("RdfModel") RdfModel rdfModel, Model model, RedirectAttributes attrs) { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); QueryBuilder qb = QueryBuilders.matchQuery("hasTitle", rdfModel.getHasTitle()); searchSourceBuilder.query(qb); Search search = new Search.Builder(searchSourceBuilder.toString()).addIndex("publications").build(); try { SearchResult searchresult = jc.execute(search); ArrayList<RdfModel> publications = new ArrayList<RdfModel>(searchresult.getSourceAsObjectList(RdfModel.class)); model.addAttribute("searchResults", publications); model.addAttribute("rdfModel", new RdfModel()); } catch (Exception e) { e.printStackTrace(); } return "index"; } }