Results 1 to 2 of 2

Thread: Problem With Calling SearchAPI in Lucene

  1. #1

    Default Problem With Calling SearchAPI in Lucene

    Issue -
    Its a note sharing sysem Running on JBoss 4.0, Clamwin, Tortoise, Spring, Ecliplse, JDK1.5.
    Search engine is Lucene.
    The problem is that -
    When I search with query strings in different fields(as you will find in the above mentioned java files)..the keywords in resourcedto and get some files as search results.
    Then I click on one of the file from within the search result and visit the file.
    Here if I m logged in as an user, and the session time out is set to 1 minute in the web.xml file of the web folder not the admin folder then when I hit the BACK TO SEARCH button it easily goes back to the previous search result page along with the queries string that I had input previously.
    The problem is that when I m NOT LOGGED in as an user, and I've performed a search with queries and other dropdowns in the search panel, I get the search result page, I visit the file by clicking on one of them but when I hit the BACK TO SEARCH button I don't see the previous search result page from where I had navigated to view the file.
    Please suggest on what changes shall I make in the code so that even if I m not logged in as an user, I get back to the search result page on hitting the BACK TO SEARCH button from the file view page.

    I've thought of a solution but just can't put'em together.
    Heres the solution I've thought of - For a quick fix of the bug when the unlogged in user clicks on the BACK TO SEARCH button, all we do we is we call the searchAPI and simply add a query string to the url that will carry all the parameters of the previous search performed by the user.
    i.e. for example I've chosen to use keywords as university, country, course, discipline, etc whatever parameters the user used to search previously.

    But just seem to get it done. Could you please help me on this?

    I herein attach all the codes pertainining to the search folder belonging to the web folder of the application

    I herein paste the code of the searchresultscontroller.java file-
    Code:
    package com.mgh.sps.search.web.handler;
    
    import java.util.Map;
    import java.util.regex.Pattern;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.log4j.Logger;
    import org.springframework.validation.BindException;
    import org.springframework.validation.Errors;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormController;
    
    import com.mgh.sps.search.business.facade.Search;
    import com.mgh.sps.common.dto.ResourceDTO;
    import com.mgh.sps.common.util.SessionAttributeKey;
    import com.mgh.sps.common.util.SessionManager;
    import com.mgh.sps.fileusage.web.constants.FileUsageWebConstants;
    
    public class SearchResultsController extends SimpleFormController {
    
    	/**
    	 * SearchResults Controller 
    	 * @author Muralikrishna.s
    	 * @Codedondate DD-MM-YY=26-07-07
    	 * @Usecase/s associated =UC504
    	 */
    	private static final Logger logger = Logger
    			.getLogger(SearchResultsController.class.getName());
    
    	private final static String REG_EXP = "^[A-Za-z0-9]*$";
    
    	private final static Pattern EMAIL_PATTERN_REG = Pattern.compile(REG_EXP);
    	/**
    	 * Spring framework method used to hold reference data
    	 * 
    	 * @param request
    	 *            HttpServletRequest
    	 * @param command
    	 *            Object
    	 * @param arg2
    	 *            Errors
    	 * @return Map
    	 * @throws Exception
    	 */
    	@Override
    	protected Map referenceData(HttpServletRequest request, Object command,
    			Errors errors) throws Exception {
    		logger.debug("SearchResultsController.referenceData() method entered:"
    				+ request + "," + command + "," + errors);
    		 
    		SessionManager.setSessionAttribute(SessionAttributeKey.tabIndex,
    				FileUsageWebConstants.TAB_SEARCH, request);
    		Search search = (Search) super.getWebApplicationContext().getBean(
    				"searchfacade");
    		ResourceDTO resourceDto = (ResourceDTO) command;
    		String[] allValues = new String[7];
    		if (null != (String[]) SessionManager.getSessionAttribute(
    				SessionAttributeKey.allValues, request)) {
    			allValues = (String[]) SessionManager.getSessionAttribute(
    					SessionAttributeKey.allValues, request);
    			resourceDto.setKeywords(allValues[0]);
    			resourceDto.setCountry(allValues[1]);
    			resourceDto.setUniversityName(allValues[2]);
    			resourceDto.setSubjectArea(allValues[3]);
    			resourceDto.setQualification(allValues[4]);
    			resourceDto.setYearLevel(allValues[5]);
    			resourceDto.setSpecificType(allValues[6]);
    		}
    		logger.debug("%%%%%%%%%%%%%%%%%qualification%%%%%%%%%%%%%%%"
    				+ resourceDto.getQualification());
    		String flag = (String) request.getParameter("id");
    		resourceDto.setFlag(flag);
    		logger.debug("SearchResultsController.referenceData() method exited:");
    		return search.retrieveReferenceData(resourceDto);
    		 
    	}
    
    	/**
    	 * Spring framework method used to hold OnSubmit
    	 * 
    	 * @param request
    	 *            HttpServletRequest
    	 * @param response
    	 *            HttpServletResponse
    	 * @param command
    	 *            Object
    	 * @param arg3
    	 *            BindException
    	 * @return ModelAndView
    	 * @throws Exception
    	 */
    	@Override
    	protected ModelAndView onSubmit(HttpServletRequest request,
    			HttpServletResponse response, Object command, BindException errors)
    			throws Exception {
    		SessionManager.cleanup(request);
    		logger.debug("SearchResultsController.onSubmit() method entered:"
    				+ request + "," + command + "," + response + "," + errors);
    		Search search = (Search) super.getWebApplicationContext().getBean(
    				"searchfacade");
    		Map dynamic = (Map) getServletContext().getAttribute("config");
    		ResourceDTO resourceDto = (ResourceDTO) command;
    		SessionManager.removeSessionAttribute(SessionAttributeKey.allValues,
    				request);
    		//changed by sreelatha on sep21
    		//resourceDto.setKeywords(request.getParameter("keywords"));
    		//String key = request.getParameter("keywords");
    		//logger.debug("&&&&&&&&&&&&&  key &&&&&&&&&&&&" + key);
    		String keywords = (request.getParameter("keywords"));
    		if(null!=keywords) {
    			keywords = keywords.trim();
    		}
    		resourceDto.setKeywords(keywords);
    //		 changes end
    		resourceDto.setUniversityName(request.getParameter("universityName"));
    		resourceDto.setSubjectArea(request.getParameter("subjectArea"));
    		resourceDto.setCountry(request.getParameter("country"));
    		resourceDto.setQualification(request.getParameter("qualification"));
    		resourceDto.setYearLevel(request.getParameter("yearLevel"));
    		resourceDto.setSpecificType(request.getParameter("specificType"));
    		String[] allValues = new String[7];
    		//changed by sreelatha on sep21
    		//allValues[0] = request.getParameter("keywords");
    		allValues[0] = resourceDto.getKeywords();
    		//changes end
    		allValues[1] = request.getParameter("country");
    		allValues[2] = request.getParameter("universityName");
    		allValues[3] = request.getParameter("subjectArea");
    		allValues[4] = request.getParameter("qualification");
    		allValues[5] = request.getParameter("yearLevel");
    		allValues[6] = request.getParameter("specificType");
    		SessionManager.setSessionAttribute(SessionAttributeKey.allValues,
    				allValues, request);
    			if(null!=keywords) {
    			keywords = keywords.trim();
    			String words="";
    			for(int i=0;i<keywords.length();i++) {			
    				String key=String.valueOf(keywords.charAt(i));
    				 if(key.contains("*")) {
    						key = key.replace("*"," ");
    					} else if(key.contains("?")) {
    						key = key.replace("?"," ");
    					} else if(key.contains("[")) {
    						key = key.replace("["," ");
    					} else if(key.contains("{")) {
    						key = key.replace("{"," ");
    					} else if(key.contains("(")) {
    						key = key.replace("("," ");
    					} else if(key.contains(")")) {
    						key = key.replace(")"," ");
    					} else if(key.contains("+")) {
    						key = key.replace("+"," ");
    					} else if(key.contains("\\")) {
    						key = key.replace("\\"," ");
    					} else if(key.contains(" ")) {
    						key = key.replace(" "," ");
    					} else if(key.contains("_")) {
    						key = key.replace("_","_");
    					}  else if(!EMAIL_PATTERN_REG.matcher(key).matches()) {
    						key = key.replaceAll(key," ");
    					} 
    				words = words + key;
    				}
    			keywords = words;
    			resourceDto.setKeywords(keywords);
    		}
    		
    		SessionManager.setSessionAttribute(SessionAttributeKey.test, search.setInputValues(resourceDto, dynamic), request);
    		String name = (String) SessionManager.getSessionAttribute(SessionAttributeKey.tempName, request);
    		String flag1 = request.getParameter("id");
    		String status="";
    		if (flag1 !=null && flag1.equals("loggedInUser"))
    		{			
    		if(name==null)
    			{
    				return new ModelAndView();
    			}
    		}
    		if (flag1 !=null && flag1.equals("loggedInUser")){
    			status = "redirect:SearchResults.htm?id=loggedInUser";
    		}else if(flag1 !=null && flag1.equals("nonLoggedInUser"))
    		{
    			status = "redirect:SearchResultsnlu.htm?id=nonLoggedInUser";	
    		}
    		//}
    		super.setSuccessView(status);
    		ModelAndView mav = new ModelAndView(super.getSuccessView());
    		logger.debug("SearchResultsController.onSubmit() method exited:");
    		return mav;
    	 
    	}
    	
    }
    Attached Files Attached Files

  2. #2

    Default A Proposed Solution- Please Help

    Since here my code relies on sessions (when logged in) and when am not logged in, there is no session, hence there is no search parameters. But it is a requirement that I should be able to get back to the search results when logged out, then I thought I may've to do what I thought of (encoding the search request params in the back to search results link url). Alternatively, I may use cookies.

    Now the problem is how do I encode the search parameters, cause I just can't seem to find where are the queries generated?

    I've a hunch its in the resourcedto.class file.
    I herein paste the jsp file with the Back To Search button for you to suggest a solution.
    Code:
    fileInFrame.Jsp- <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
    <%@ taglib prefix="spring" uri="/tld/spring.tld" %>
      
    <%@ page import="java.util.*,com.mgh.sps.common.dto.UserDTO" %>
    <%@ taglib prefix="form" uri="/tld/spring-form.tld" %>
      
    <%@ taglib prefix="fmt" uri="/tld/fmt.tld"%>
    <%@ page import="com.mgh.sps.fileusage.web.constants.FileUsageWebConstants"%>
    <%@ page import="com.mgh.sps.common.util.CryptoManager,com.mgh.sps.common.util.Utilities"%> 
    <%@ page import="com.mgh.sps.common.constants.app.AppConstants"%>
    <%@ page import="com.mgh.sps.fileusage.web.constants.FileUsageWebConstants"%>
    <%@ page import="com.mgh.sps.common.util.GenerateBreaks"%>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>GradeGuru, note sharing by students for students</title>
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
    <!-- CODE ADDED FOR STUBBING --->
    <script type="text/javascript" src="js/addEvent.js"></script>
    <script type="text/javascript" src="js/sweetTitles.js"></script>
    <!-- CODE ENDED FOR STUBBING --->
    <script>
    
    function backToSearch(){
    
    document.getElementById("buttonValue").value="Back to search >";
     
    }
    function backToSearchnlu(){
    
    document.getElementById("buttonValue").value="Back to search >";
     
    }
    function home()
    {
    location.href="login.action";
    }
    function setButtonValue()
    {
    document.getElementById("buttonValue").value="save";
    }
    function setButtonValue2()
    {
    document.getElementById("buttonValue").value="save to my folder";
    }
    function showPreview()
    {
    	var fileScriptName=document.getElementById("filePathElement").value;
    	var reuesturl ="<%=request.getContextPath()%>";	
    	url=reuesturl+"/jsp/download.jsp?download="+fileScriptName;
    	
    	document.getElementById("FileFrame").src=url
    
    }
    function callServletSave()
    {
    var fileScriptName=document.getElementById("filePathElement").value;
    var reuesturl ="<%=request.getContextPath()%>";	
    location.href=reuesturl+"/download.download?save="+fileScriptName;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •