Process query builder rules in custom search controller
This commit is contained in:
parent
a6fa88bd1f
commit
1590d58830
2 changed files with 56 additions and 1 deletions
|
@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.search.controller;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -127,6 +128,39 @@ public class CustomSearchController extends FreemarkerHttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
VitroRequest vreq = new VitroRequest(request);
|
||||||
|
boolean wasXmlRequested = isRequestedFormatXml(vreq);
|
||||||
|
boolean wasCSVRequested = isRequestedFormatCSV(vreq);
|
||||||
|
if( !wasXmlRequested && !wasCSVRequested){
|
||||||
|
super.doGet(vreq,response);
|
||||||
|
}else if (wasXmlRequested){
|
||||||
|
try {
|
||||||
|
ResponseValues rvalues = processRequest(vreq);
|
||||||
|
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setContentType("text/xml;charset=UTF-8");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=search.xml");
|
||||||
|
writeTemplate(rvalues.getTemplateName(), rvalues.getMap(), request, response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e, e);
|
||||||
|
}
|
||||||
|
}else if (wasCSVRequested){
|
||||||
|
try {
|
||||||
|
ResponseValues rvalues = processRequest(vreq);
|
||||||
|
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setContentType("text/csv;charset=UTF-8");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=search.csv");
|
||||||
|
writeTemplate(rvalues.getTemplateName(), rvalues.getMap(), request, response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||||
|
|
||||||
|
@ -156,6 +190,8 @@ public class CustomSearchController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
int startIndex = getStartIndex(vreq);
|
int startIndex = getStartIndex(vreq);
|
||||||
int hitsPerPage = getHitsPerPage( vreq );
|
int hitsPerPage = getHitsPerPage( vreq );
|
||||||
|
String queryBuilderRules = getQueryBuilderRules(vreq);
|
||||||
|
|
||||||
|
|
||||||
String queryText = vreq.getParameter(PARAM_QUERY_TEXT);
|
String queryText = vreq.getParameter(PARAM_QUERY_TEXT);
|
||||||
log.debug("Query text is \""+ queryText + "\"");
|
log.debug("Query text is \""+ queryText + "\"");
|
||||||
|
@ -281,7 +317,9 @@ public class CustomSearchController extends FreemarkerHttpServlet {
|
||||||
body.put("nextPage", getNextPageLink(startIndex, hitsPerPage,
|
body.put("nextPage", getNextPageLink(startIndex, hitsPerPage,
|
||||||
vreq.getServletPath(), pagingLinkParams));
|
vreq.getServletPath(), pagingLinkParams));
|
||||||
}
|
}
|
||||||
|
if (queryBuilderRules != null) {
|
||||||
|
body.put("queryBuilderRules", queryBuilderRules);
|
||||||
|
}
|
||||||
// VIVO OpenSocial Extension by UCSF
|
// VIVO OpenSocial Extension by UCSF
|
||||||
try {
|
try {
|
||||||
OpenSocialManager openSocialManager = new OpenSocialManager(vreq, "search");
|
OpenSocialManager openSocialManager = new OpenSocialManager(vreq, "search");
|
||||||
|
@ -314,6 +352,16 @@ public class CustomSearchController extends FreemarkerHttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getQueryBuilderRules(VitroRequest vreq) {
|
||||||
|
String rules = null;
|
||||||
|
try {
|
||||||
|
rules = vreq.getParameter("queryBuilderRules");
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error(e);
|
||||||
|
}
|
||||||
|
return rules;
|
||||||
|
}
|
||||||
|
|
||||||
private int getHitsPerPage(VitroRequest vreq) {
|
private int getHitsPerPage(VitroRequest vreq) {
|
||||||
int hitsPerPage = DEFAULT_HITS_PER_PAGE;
|
int hitsPerPage = DEFAULT_HITS_PER_PAGE;
|
||||||
try{
|
try{
|
||||||
|
|
|
@ -152,8 +152,15 @@ $('input[type=checkbox]').removeAttr('checked');
|
||||||
fillOutForm(compilationName);
|
fillOutForm(compilationName);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillOutForm(compilationName){
|
function fillOutForm(compilationName){
|
||||||
var iframeDoc = document.getElementById('newCompilationIframe').contentWindow.document;
|
var iframeDoc = document.getElementById('newCompilationIframe').contentWindow.document;
|
||||||
|
var rules = $('#builder').queryBuilder('getRules');
|
||||||
|
var query = format_query_string(rules,"");
|
||||||
|
iframeDoc.getElementById('queryBuilderRules').value = JSON.stringify(rules);
|
||||||
|
iframeDoc.getElementById('rawQueryString').value = query;
|
||||||
|
|
||||||
|
|
||||||
iframeDoc.getElementById('newCompilationLabel').value = compilationName;
|
iframeDoc.getElementById('newCompilationLabel').value = compilationName;
|
||||||
var excerpts = $('.virtualArticlePart').toArray();
|
var excerpts = $('.virtualArticlePart').toArray();
|
||||||
for (i = 0;i < excerpts.length;i++){
|
for (i = 0;i < excerpts.length;i++){
|
||||||
|
|
Loading…
Add table
Reference in a new issue