view src/main/webapp/pages/fullTextSearch.jsp @ 49:7c2e1b14b77d

new: load existing full text searching result into searching table
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Tue, 26 Jan 2016 11:46:10 +0100
parents 13555aff1f88
children 8f6c47775fe8
line wrap: on
line source

<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="de.mpiwg.gazetteer.db.DBContents"%>
<%@page import="de.mpiwg.gazetteer.bo.LGFullTextSearchFile"%>


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<jsp:useBean id="sessionBean" class="de.mpiwg.web.jsp.SessionBean" scope="session" />
	

<html>

<head>

	<jsp:include page="../componentes/headContent.jsp"/>	

	<script>	
		$(function() {
		    $( "#dialogMoreInfo" ).dialog({
		        autoOpen: false,
		        modal: true,
		        position: { my: "center", at: "top", of: window },
		        
		      });
		    
		    var dialogSave = $("#dialogSave").dialog(
					{autoOpen: false}
		  	);	   
			$("#saveResult").button().on( "click", function() {
				// append searchTerm into the form 		
				$('<input>').attr({
				    type: 'hidden',
				    name: 'searchTerm',
				    value: $("#searchTerm").val()
				}).appendTo('form[name="saveTableForm"]');
				
				
				dialogSave.dialog( "open" );
			});
			
			var dialogViewSavedResult = $("#dialogViewSavedResult").dialog(
					{autoOpen: false}
		  	);	  
			$("#viewSavedResult").button().on( "click", function() {
				dialogViewSavedResult.dialog( "open" );
			});
			
			
		});
		
		// enter pressed event, we don't want to always go to "search".
		$(document).keypress(
			function(event){
				if (event.which == '13') {	// enter pressed
					// if any of the filter fields is filled in, filter first; otherwize, go to search
					$(".filterInput" ).each(function( i ) {
						//console.log( this.value );
						if (this.value != "") {
							//console.log('filtering' + i);
							setAction('filter', 'fullTextSearchForm');
							$("#fullTextSearchForm").submit();
							return false;		
						}
						
					});
			    }
		});
		
		$(document).ready(function(){
			highlightKeywords();
		})

		function highlightKeywords()	// highlight keywords in content column, with class="content"
		{	
			if ($("#searchTerm")[0] == undefined ){
				return;
			}
			var keywords = $("#searchTerm")[0].value;
			var keywordsArray = keywords.split(", ");
			//console.log("keywordsArray: "+keywordsArray);
			
			var content = $(".content");
			for (var i = 0; i < content.length; i++) {
				// find keywords in content[i]
				var text = content[i].innerHTML;
				for (var j = 0; j < keywordsArray.length; j++) {
					var index = text.indexOf(keywordsArray[j]);
					if (index >= 0) {
						text = text.substring(0,index) + "<span class='highlight'>" + text.substring(index, index+keywordsArray[j].length) + "</span>" + text.substring(index+keywordsArray[j].length);
						content[i].innerHTML = text;
					}		
				};

			};
		}
		
	</script>
</head>

<body>

	<jsp:include page="../componentes/template.jsp"/>

	<div id="dialogMoreInfo" title="Full Text Search Details"> </div>
	
	<div id="page">
	
		<% if(sessionBean.getUser() == null) { %>
			<label class="subTitel">You must login!</label>
		<% } else { 
			
			if (sessionBean.getFullTextSearchPage().getFileList() == null){ 
				sessionBean.getFullTextSearchPage().loadParameters(request, response);
				sessionBean.getFullTextSearchPage().forceLoadFileList();
			}
			
			%>
			
			<div id="dialogSave" title="Save Table:">
				<form name="saveTableForm" id="saveTableForm"
						action="<%= sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
						method="post">
						<input name="bean" type="hidden" value="fullTextSearchBean" /> 
					<table>
						<tr>
							<td>
								<input id="fileName" name="fileName" type="text" placeholder="table name"/>
							</td>
							<td>
								<button onclick="setAction('save', 'saveTableForm'); document.getElementById('saveTableForm').submit();">Save</button> 
								
							</td>
						</tr>						
					</table>	
				</form>
			 	
			</div>	
			
			<div id="dialogViewSavedResult" title="Saved Table List:">
		
				<table class="pageTable">
					<tr>
						<td class="tableTitle">Table name</td>
						<td class="tableTitle">html</td>
						<td></td>
					</tr>
					
					<% for (LGFullTextSearchFile aFile : sessionBean.getFullTextSearchPage().getFileList() ){%>
					<tr>
						<td><%= aFile.getFileName() %></td>
						<!-- getFullTextSearchFileText?fileId= &userId= -->
						<td>
							<!-- TODO click searching result to open it in the same table of full-text-search result -->
							<a href="<%=sessionBean.getApplicationBean().getRootServer() %>/rest/text/getFullTextSearchHtmlFile?fileId=<%= aFile.getId() %>"
										target="_blank">
								<img alt="Show text in html" src="<%=sessionBean.getApplicationBean().getShowImage()%>"/>	
							</a>
						</td>
						<td>
							<button type="button" class="lgButton" onclick="setAction0('loadFile', 'fullTextSearchForm', 'fileId', <%=aFile.getId() %>); document.getElementById('fullTextSearchForm').submit();">load</button>	
						</td>
					</tr>
					<% } %>
					
				</table>
				
		
			</div>	
		<label class="subTitel">Full Text Search</label> 

			<form name="fullTextSearchForm" id="fullTextSearchForm"
				action="<%=sessionBean.getApplicationBean().getRootServer()%>/proxy.jsp"
				method="post"
				class="contentForm">
				<input name="bean" type="hidden" value="fullTextSearchBean" /> 
	
				<table style="width: 300px; margin-left: auto;margin-right: auto;">
				<tr>
					<td>
						<input
							id="searchTerm"
							name="searchTerm"
							type="text"
							class="searchInput"
							value="<%=sessionBean.getFullTextSearchPage().getSearchTerm()%>" />				
					</td>
					<td>
						<input id="search"
							type="image" 
							onclick="setAction('search', 'fullTextSearchForm');"
							src="<%=sessionBean.getApplicationBean().getSearchImage()%>"/>
					</td>
	
		
				</tr>
				
				<!-- TODO batching querying -->
				<!-- for batching, query keyword sets separated by ";" and within each keyword set, keywords separated by "," -->
				<% if (StringUtils.equals(sessionBean.getUserName(), "zhong") || StringUtils.equals(sessionBean.getUserName(), "silk")) { %>
				<tr>
					<td>
						<input
							id="batchSearchTerm"
							name="batchSearchTerm"
							type="text"
							class="searchInput"
							value="<%=sessionBean.getFullTextSearchPage().getBatchSearchTerm() %>" />				
					</td>
					<td>
						<input id="search"
							type="image" 
							onclick="setAction('searchBatch', 'fullTextSearchForm');"
							src="<%=sessionBean.getApplicationBean().getSearchImage()%>"/>
					</td>
	
		
				</tr>
				<% } %>
				
				<tr><td><label class="label"><%= (StringUtils.isNotEmpty(sessionBean.getFullTextSearchPage().getSearchMessage())) ? sessionBean.getFullTextSearchPage().getSearchMessage() : ""%></label></td></tr>
				<tr><td><label class="label"><%= (StringUtils.isNotEmpty(sessionBean.getFullTextSearchPage().getFilteringMessage())) ? sessionBean.getFullTextSearchPage().getFilteringMessage() : ""%></label></td></tr>
				<tr><td>
					<button id="saveResult" type="button" class="lgButton">Save Table</button>								
					<button id="viewSavedResult" type="button" class="lgButton">View/Load Saved Table(s)</button>
				</td></tr>
					
				
				</table>
		
		
	
			<%
				if (sessionBean.getFullTextSearchPage().getCompleteList() != null) {
			%>
	
			
			<jsp:include page="../componentes/paginator.jsp">
				<jsp:param name="formName" value="fullTextSearchForm"/>
			</jsp:include> 
		
			
			<div class="tableDiv double-scroll">
				<table class="pageTable">
					<tbody>
						<tr>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">#</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image" 
														onclick="setAction('sortByInxUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByInxDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
								</table>
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Book Id</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image" 
														onclick="setAction('sortByBookIdUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByBookIdDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="bookIdFilter" id="bookIdFilter" value="<%= sessionBean.getFullTextSearchPage().getBookIdFilter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>
								</table>
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Book Name</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByBookNameUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByBookNameDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																	
												</td></tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="bookNameFilter" id="bookNameFilter" value="<%= sessionBean.getFullTextSearchPage().getBookNameFilter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>
								</table>					
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Level 1</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByLevel1Up', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByLevel1Down', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="level1Filter" id="level1Filter" value="<%= sessionBean.getFullTextSearchPage().getLevel1Filter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>								
								</table>	
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Level 2</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByLevel2Up', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByLevel2Down', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="level2Filter" id="level2Filter" value="<%= sessionBean.getFullTextSearchPage().getLevel2Filter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>								
								</table>
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Dynasty</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByDynastyUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByDynastyDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="dynastyFilter" id="dynastyFilter" value="<%= sessionBean.getFullTextSearchPage().getDynastyFilter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>
								</table>					
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Period</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByPeriodUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByPeriodDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="periodFilter" id="periodFilter" value="<%= sessionBean.getFullTextSearchPage().getPeriodFilter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>
								</table>						
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Admin Type</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByAdminTypeUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByAdminTypeDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="adminTypeFilter" id="adminTypeFilter" value="<%= sessionBean.getFullTextSearchPage().getAdminTypeFilter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>								
								</table>	
							</th>
							
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Section Name</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortBySectionNameUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortBySectionNameDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="sectionNameFilter" id="sectionNameFilter" value="<%= sessionBean.getFullTextSearchPage().getSectionNameFilter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>
								</table>	
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Section Pages</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortBySectionNameUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortBySectionNameDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
								</table>	
							</th>
							<th>
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Page</label></td>
										<td>
											<table>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByStartPageUp', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getUpImage()%>"/>										
												</td></tr>
												<tr><td>
													<input type="image"
														onclick="setAction('sortByStartPageDown', 'fullTextSearchForm');"
														src="<%=sessionBean.getApplicationBean().getDownImage()%>"/>																				
												</td></tr>
											</table>
										</td>
									</tr>
								</table>							
							
							</th>
							<th style="min-width:300px">
								
								<table class="sortTable">
									<tr>
										<td><label class="tableTitle">Content</label></td>
										<td></td>
									</tr>
									<tr>
										<td>
											<input type="text" class="filterInput" name="contentFilter" id="contentFilter" value="<%= sessionBean.getFullTextSearchPage().getContentFilter()%>" size="8"/>
										</td>									
										<td>
											<input type="image"
												onclick="setAction('filter', 'fullTextSearchForm');"
												src="<%=sessionBean.getApplicationBean().getFilterImage()%>"/>
										</td>							
									</tr>
									
								</table>	
								
							</th>
							<th><label class="tableTitle">Select rows</th>
						</tr>
					
		
						<%
						for (DBContents content : sessionBean.getFullTextSearchPage().getDisplayList() ) {
						%>
						
						<% if ( content.isRemoved() ) { %>
						<tr class="removedContent">	
						<% } else { %>
						<tr>	
						<% } %>
									
							<td><%=content.getInx() %></td>
							<td><%=content.getBookId() %></td>
							<td><%=content.getSection().getBook().getName()%></td>
							<td><%=content.getSection().getBook().getLevel1()%></td>
							<td><%=content.getSection().getBook().getLevel2()%></td>
							<td><%=content.getSection().getBook().getDynasty()%></td>
							<td><%=content.getSection().getBook().getPeriod()%></td>
							<td><%=content.getSection().getBook().getAdmin_type() %></td>
							<td><%=content.getSection().getName() %></td>
							<td><%=content.getSection().getPages()%></td>
							<td><%=content.getPage() %></td>
							<td class="content"><%=content.getContent()%></td>
							<td>
								<% if ( content.isRemoved() ) { %>
	
									<input type="image"	onclick="setAction0('recoverFocusedContent', 'fullTextSearchForm', 'focusedContentId', '<%=content.getId() %>');"	
										src="<%=sessionBean.getApplicationBean().getCheckboxUncheckedImage()%>" width="20" height="20"/>
										
								<% } else { %>
							
									<input type="image" onclick="setAction0('removeFocusedContent', 'fullTextSearchForm', 'focusedContentId', '<%=content.getId() %>');"	
										src="<%=sessionBean.getApplicationBean().getCheckboxCheckedImage()%>" width="20" height="20"/>
								
								<% } %>
							
									
								
							</td>
							
						</tr>
						<%
							}
						%>
						
					</tbody>
				</table>
		
				
			<%
				}
			%>
			
			</div>
			
			<jsp:include page="../componentes/paginator.jsp">
				<jsp:param name="formName" value="fullTextSearchForm"/>
			</jsp:include> 
			 
			 
		</form>
	
		<% } %>
		
	</div>

</body>
</html>