Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
Now edit \[dspace-source\]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/search/advanced.jsp
\\

Code Block
languagehtml/xml
titleadvanced.jsp
collapsetrue

...
<%
 //Add this code on top section
 //Generate JSPUI Solr path url
 String scheme = request.getScheme();             // http
 String serverName = request.getServerName();     //request.getServerName();     // hostname.com
 int serverPort = request.getServerPort();        // 80
 String parentContextPath = "";                   //Change this value if dspace not installed on html root folder
 String contextPath = "/jspui";
 String servletPath = "/searchJSON";
 // Reconstruct original requesting URL
 StringBuffer url =  new StringBuffer();
 url.append(scheme).append("://").append(serverName);
 if (serverPort != 80)
 url.append(":").append(serverPort);
 url.append(parenContextPath).append(contextPath).append(servletPath);
 String solrPath = url.toString();

%>
...
<!-- Add this lines after <dspace:layout> tag-->
<link type="text/css" href="<%=request.getContextPath()%>/static/js/jqueryui/css/smoothness/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
<script type="text/javascript" src="<%=request.getContextPath()%>/static/js/jqueryui/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/js/jqueryui/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/js/autocomplete.js"></script>
...
<!-- Add onchange event call for every search textbox -->
<select name="field2" id="tfield2" onchange="JavaScript:replaceSAXExpression('<%=solrPath%>', 10 ,'tfield2', 'tquery2');">
<select name="field1" id="tfield1" onchange="JavaScript:replaceSAXExpression('<%=solrPath%>', 10 ,'tfield1', 'tquery1');">

Adding javascript functions

...

Code Block
languagejavascript
titleautocomplete.js
linenumberstrue
collapsetrue
/**
 * Functions used on advanced search page
 */
function monkeyPatchAutocomplete() {
    // don't really need this, but in case I did, I could store it and chain
    var oldFn = $.ui.autocomplete.prototype._renderItem;

    $.ui.autocomplete.prototype._renderItem = function( ul, item){
    	var term = this.term.split(' ').join('|');
    	var re = new RegExp("(" + term + ")", "gi") ;
    	var t = item.label.replace(re,"<b>$1</b>");
    	return $( "<li></li>" )
    	.data( "item.autocomplete", item )
    	.append( "<a>" + t + "</a>" )
    	.appendTo( ul );
    };

}

function replaceSAXExpression(baseUrl , limit ,fieldName, fieldText){
	var field = $('#'+ fieldName).val();
	$('#' + fieldText).val('');
	$('#' + fieldText).autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: baseUrl +"/terms?terms=true&terms.limit=" + limit + "&terms.sort=count&terms.regex.flag=case_insensitive&terms.fl=" + field + "&terms.regex=.*" + request.term + ".*&wt=json",
				dataType: "json",
				data: {
					style: "full",
					maxRows: 5,
					name_startsWith: request.term,
				},
				success: function( data ) {
 					response( $.map( data.terms[field], function( item ) {
						if(!$.isNumeric(item)){
							return{
    							label: item,
    							value: "\"" + item + "\"",
         					}
         				}else {
         					return null;
         				}
         			}
				));}
			});
		},
		minLength: 1,
		select: function( event, ui ) {

		},
		open: function() {
			$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
		},
		close: function() {
			$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
		}
	});
}

 


Creating a new SOLR core

Wiki Markup
Now we must create a new SOLR core inside \[dspace-source\]/solr directory. To do so we'll use one of the existing cores and copy it's structure with this command:

Code Block
bash$ cp -R [dspace-source]/dspace/solr/search [dspace-source]/dspace/solr/searchJSPUI
bash$ mkdir [dspace-source]/dspace/solr/searchJSPUI/data
bash$ mkdir [dspace-source]/dspace/solr/searchJSPUI/data/index

Wiki Markup
We'll editEdit \[dspace-source\]/dspace/solr/solr.xml and add one extra line with our new search core.

Code Block
<cores adminPath="/admin/cores">
 <core name="search" instanceDir="search" />
 <core name="statistics" instanceDir="statistics" />
 <core name="searchJSPUI" instanceDir="searchJSPUI" />  <!-- Add this line-->
</cores> 

Wiki Markup
Now we'll overwrite ourOverwrite new solr core configuration file \[dspace-source\]/dspace/solr/searchJSPUI/conf/schema.xml to handle lucene generated indexes.

 If If no modification to search indexes has been done on dspace.cfg file this configuration file will be enough:

...

Code Block
languagehtml/xml
titleweb.xml
collapsetrue
<servlet>
  	      <servlet-name>searchJSON</servlet-name>name
  	      <servlet-class>org.dspace.app.webui.servlet.SearchJSONServlet</servlet-class>
</servlet>
<servlet-mapping>
        <servlet-name>searchJSON</servlet-name>
        	<url-pattern>/searchJSON/*</url-pattern>
</servlet-mapping>