More cleanup.
This commit is contained in:
parent
738a177cb8
commit
830456ac9f
1 changed files with 22 additions and 63 deletions
|
@ -15,6 +15,7 @@ import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
@ -53,7 +54,8 @@ import edu.cornell.mannlib.vitro.webapp.search.lucene.LuceneSetup;
|
||||||
*/
|
*/
|
||||||
public class JSONReconcileServlet extends VitroHttpServlet {
|
public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
private static String QUERY_PARAMETER_NAME = "term";
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static String QUERY_PARAMETER_NAME = "term";
|
||||||
public static final int MAX_QUERY_LENGTH = 500;
|
public static final int MAX_QUERY_LENGTH = 500;
|
||||||
private static final Log log = LogFactory.getLog(JSONReconcileServlet.class.getName());
|
private static final Log log = LogFactory.getLog(JSONReconcileServlet.class.getName());
|
||||||
|
|
||||||
|
@ -70,14 +72,14 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
super.doGet(req, resp);
|
super.doGet(req, resp);
|
||||||
resp.setContentType("application/json");
|
resp.setContentType("application/json");
|
||||||
VitroRequest vreq = new VitroRequest(req);
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
// System.out.println("vreq");
|
//log.debug("vreq");
|
||||||
// System.out.println(vreq.getWebappDaoFactory());
|
//log.debug(vreq.getWebappDaoFactory());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (vreq.getParameter("query") != null
|
if (vreq.getParameter("query") != null
|
||||||
|| vreq.getParameter("queries") != null) {
|
|| vreq.getParameter("queries") != null) {
|
||||||
JSONObject qJson = getResult(vreq, req, resp);
|
JSONObject qJson = getResult(vreq, req, resp);
|
||||||
// System.out.println("result: " + qJson.toString());
|
log.debug("result: " + qJson.toString());
|
||||||
String responseStr = (vreq.getParameter("callback") == null) ? qJson
|
String responseStr = (vreq.getParameter("callback") == null) ? qJson
|
||||||
.toString() : vreq.getParameter("callback") + "("
|
.toString() : vreq.getParameter("callback") + "("
|
||||||
+ qJson.toString() + ")";
|
+ qJson.toString() + ")";
|
||||||
|
@ -85,23 +87,14 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
out.print(responseStr);
|
out.print(responseStr);
|
||||||
} else { // metadata
|
} else { // metadata
|
||||||
String defaultNamespace = null;
|
String defaultNamespace = null;
|
||||||
//String defaultTypeList = null;
|
String defaultTypeList = null;
|
||||||
String serverName = null;
|
String serverName = null;
|
||||||
int serverPort = req.getServerPort();
|
int serverPort = req.getServerPort();
|
||||||
|
|
||||||
if (vreq.getWebappDaoFactory() != null) {
|
if (vreq.getWebappDaoFactory() != null) {
|
||||||
defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
|
defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
|
||||||
}
|
}
|
||||||
String defaultTypeList =
|
defaultTypeList = ConfigurationProperties.getBean(req).getProperty("Vitro.reconcile.defaultTypeList");
|
||||||
ConfigurationProperties.getBean(getServletContext()).getProperty("Vitro.reconcile.defaultTypeList");
|
|
||||||
|
|
||||||
//defaultTypeList =
|
|
||||||
// "http://vivoweb.org/ontology/core#Course, Course; " +
|
|
||||||
// "http://vivoweb.org/ontology/core#Grant, Grant; " +
|
|
||||||
// "http://aims.fao.org/aos/geopolitical.owl, Location; " +
|
|
||||||
// "http://xmlns.com/foaf/0.1/Organization, Organization; " +
|
|
||||||
// "http://xmlns.com/foaf/0.1/Person, Person; " +
|
|
||||||
// "http://purl.org/ontology/bibo/Article, Publication";
|
|
||||||
serverName = req.getServerName();
|
serverName = req.getServerName();
|
||||||
JSONObject metaJson = getMetadata(req, resp, defaultNamespace, defaultTypeList, serverName, serverPort);
|
JSONObject metaJson = getMetadata(req, resp, defaultNamespace, defaultTypeList, serverName, serverPort);
|
||||||
String callbackStr = (vreq.getParameter("callback") == null) ? ""
|
String callbackStr = (vreq.getParameter("callback") == null) ? ""
|
||||||
|
@ -133,8 +126,7 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
// "q2":{"query":"Dina","type":"http://xmlns.com/foaf/0.1/Person","type_strict":"should"}}
|
// "q2":{"query":"Dina","type":"http://xmlns.com/foaf/0.1/Person","type_strict":"should"}}
|
||||||
String qStr = (String) qObj;
|
String qStr = (String) qObj;
|
||||||
queries.add(qStr);
|
queries.add(qStr);
|
||||||
// System.out.println();
|
log.debug("\nquery: " + qStr + "\n");
|
||||||
// System.out.println("query: " + qStr + "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -167,7 +159,7 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JSONException ex) {
|
} catch (JSONException ex) {
|
||||||
System.err.println("JSONReconcileServlet JSONException: " + ex);
|
log.error("JSONException: " + ex);
|
||||||
throw new ServletException("JSONReconcileServlet JSONException: "
|
throw new ServletException("JSONReconcileServlet JSONException: "
|
||||||
+ ex);
|
+ ex);
|
||||||
}
|
}
|
||||||
|
@ -302,7 +294,8 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
Individual ind = iDao.getIndividualByURI(uri);
|
Individual ind = iDao.getIndividualByURI(uri);
|
||||||
if (ind != null) {
|
if (ind != null) {
|
||||||
String name = ind.getName();
|
String name = ind.getName();
|
||||||
String modUri = uri.replace("#", "%23"); // encodes # to %23
|
// encode # to %23
|
||||||
|
String modUri = uri.replace("#", "%23");
|
||||||
resultJson.put("id", modUri);
|
resultJson.put("id", modUri);
|
||||||
resultJson.put("name", name);
|
resultJson.put("name", name);
|
||||||
}
|
}
|
||||||
|
@ -335,15 +328,15 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (JSONException ex) {
|
} catch (JSONException ex) {
|
||||||
System.err.println("JSONReconcileServlet JSONException: " + ex);
|
log.error("JSONException: " + ex);
|
||||||
throw new ServletException("JSONReconcileServlet JSONException: "
|
throw new ServletException("JSONReconcileServlet JSONException: "
|
||||||
+ ex);
|
+ ex);
|
||||||
} catch (SearchException ex) {
|
} catch (SearchException ex) {
|
||||||
System.err.println("JSONReconcileServlet SearchException: " + ex);
|
log.error("SearchException: " + ex);
|
||||||
throw new ServletException("JSONReconcileServlet SearchException: "
|
throw new ServletException("JSONReconcileServlet SearchException: "
|
||||||
+ ex);
|
+ ex);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.err.println("JSONReconcileServlet IOException: " + ex);
|
log.error("IOException: " + ex);
|
||||||
throw new ServletException("JSONReconcileServlet IOException: "
|
throw new ServletException("JSONReconcileServlet IOException: "
|
||||||
+ ex);
|
+ ex);
|
||||||
}
|
}
|
||||||
|
@ -362,30 +355,12 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
|
|
||||||
private Query makeReconcileNameQuery(String querystr, Analyzer analyzer, HttpServletRequest request) {
|
private Query makeReconcileNameQuery(String querystr, Analyzer analyzer, HttpServletRequest request) {
|
||||||
|
|
||||||
/* Original code
|
|
||||||
String tokenizeParam = (String) request.getParameter("tokenize");
|
|
||||||
boolean tokenize = "true".equals(tokenizeParam);
|
|
||||||
|
|
||||||
// Note: Stemming is only relevant if we are tokenizing: an untokenized name
|
|
||||||
// query will not be stemmed. So we don't look at the stem parameter until we get to
|
|
||||||
// makeTokenizedNameQuery().
|
|
||||||
if (tokenize) {
|
|
||||||
return makeTokenizedNameQuery(querystr, analyzer, request);
|
|
||||||
} else {
|
|
||||||
return makeUntokenizedNameQuery(querystr);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// modified code for reconciliation service
|
|
||||||
request.setAttribute("stem", true);
|
|
||||||
return makeTokenizedNameQuery(querystr, analyzer, request);
|
return makeTokenizedNameQuery(querystr, analyzer, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Query makeTokenizedNameQuery(String querystr, Analyzer analyzer, HttpServletRequest request) {
|
private Query makeTokenizedNameQuery(String querystr, Analyzer analyzer, HttpServletRequest request) {
|
||||||
|
|
||||||
String stemParam = (String) request.getParameter("stem");
|
String termName = VitroLuceneTermNames.NAME_STEMMED;
|
||||||
boolean stem = "true".equals(stemParam);
|
|
||||||
String termName = stem ? VitroLuceneTermNames.NAME_STEMMED : VitroLuceneTermNames.NAME_UNSTEMMED;
|
|
||||||
|
|
||||||
BooleanQuery boolQuery = new BooleanQuery();
|
BooleanQuery boolQuery = new BooleanQuery();
|
||||||
|
|
||||||
|
@ -415,30 +390,16 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
log.warn(e, e);
|
log.warn(e, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return boolQuery;
|
return boolQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Query makeUntokenizedNameQuery(String querystr) {
|
|
||||||
|
|
||||||
querystr = querystr.toLowerCase();
|
|
||||||
String termName = VitroLuceneTermNames.NAME_LOWERCASE;
|
|
||||||
BooleanQuery query = new BooleanQuery();
|
|
||||||
log.debug("Adding wildcard query on unanalyzed name");
|
|
||||||
query.add(
|
|
||||||
new WildcardQuery(new Term(termName, querystr + "*")),
|
|
||||||
BooleanClause.Occur.MUST);
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
|
|
||||||
private QueryParser getQueryParser(String searchField, Analyzer analyzer){
|
private QueryParser getQueryParser(String searchField, Analyzer analyzer){
|
||||||
// searchField indicates which field to search against when there is no term
|
// searchField indicates which field to search against when there is no term
|
||||||
// indicated in the query string.
|
// indicated in the query string.
|
||||||
// The analyzer is needed so that we use the same analyzer on the search queries as
|
// The analyzer is needed so that we use the same analyzer on the search queries as
|
||||||
// was used on the text that was indexed.
|
// was used on the text that was indexed.
|
||||||
QueryParser qp = new QueryParser(searchField,analyzer);
|
QueryParser qp = new QueryParser(Version.LUCENE_29, searchField,analyzer);
|
||||||
//this sets the query parser to AND all of the query terms it finds.
|
//this sets the query parser to AND all of the query terms it finds.
|
||||||
qp.setDefaultOperator(QueryParser.AND_OPERATOR);
|
qp.setDefaultOperator(QueryParser.AND_OPERATOR);
|
||||||
return qp;
|
return qp;
|
||||||
|
@ -458,10 +419,8 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
"query length is " + MAX_QUERY_LENGTH );
|
"query length is " + MAX_QUERY_LENGTH );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
query = makeReconcileNameQuery(querystr, analyzer, request);
|
query = makeReconcileNameQuery(querystr, analyzer, request);
|
||||||
|
|
||||||
|
|
||||||
// filter by type
|
// filter by type
|
||||||
if (typeParam != null) {
|
if (typeParam != null) {
|
||||||
|
@ -479,7 +438,7 @@ public class JSONReconcileServlet extends VitroHttpServlet {
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
String[] pvPair = it.next();
|
String[] pvPair = it.next();
|
||||||
Query extraQuery = makeReconcileNameQuery(pvPair[1], analyzer, request);
|
Query extraQuery = makeReconcileNameQuery(pvPair[1], analyzer, request);
|
||||||
if (!"".equals(pvPair[0]) && pvPair[0] != null) {
|
if ( ! StringUtils.isEmpty(pvPair[0]) ) {
|
||||||
BooleanQuery boolQuery = new BooleanQuery();
|
BooleanQuery boolQuery = new BooleanQuery();
|
||||||
boolQuery.add(new TermQuery(new Term(
|
boolQuery.add(new TermQuery(new Term(
|
||||||
VitroLuceneTermNames.RDFTYPE, pvPair[0])),
|
VitroLuceneTermNames.RDFTYPE, pvPair[0])),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue