-
- HashMap withValues = mp.getParameters();
-
- //checking the onetimepasswd
- if(passwdProtection.equals("yes")){
- HttpSession session = req.getSession(false);
- String sessionPasswd = (String)session.getAttribute("passwd");
- if ( sessionPasswd == null){
- throw new ServletModuleUserException("Lost password");
- }
- String passwd = (String)withValues.get("passwd");
- if ( passwd == null || (!sessionPasswd.equals(passwd))) {
- throw new ServletModuleUserException("Missing password");
- }
- session.invalidate();
- }
-
- if ((((String)withValues.get("title")).length() == 0) ||
- (((String)withValues.get("description")).length() == 0) ||
- (((String)withValues.get("content_data")).length() == 0))
- throw new ServletModuleUserException("Missing field");
-
- // call the routines that escape html
-
- for (Iterator i=withValues.keySet().iterator(); i.hasNext(); ){
- String k=(String)i.next();
- String v=(String)withValues.get(k);
-
- if (k.equals("content_data")){
- //this doesn't quite work yet, so for now, all html goes
- //withValues.put(k,StringUtil.approveHTMLTags(v));
- //withValues.put(k,StringUtil.removeHTMLTags(v));
- } else {
- withValues.put(k,StringUtil.removeHTMLTags(v));
+ catch (Throwable e) {
+ getLogger().debug("Can't get topics: " + e.toString());
+ }
+
+ String searchBackValue = req.getParameter("search_back");
+ String searchForwardValue = req.getParameter("search_forward");
+
+ if (searchBackValue != null) {
+ int totalHits = ( (Integer) session.getAttribute("numberOfHits")).intValue();
+ int newPosition = ( (Integer) session.getAttribute("positionInResults")).intValue() - increment;
+ if (newPosition < 0)
+ newPosition = 0;
+ if (newPosition >= totalHits)
+ newPosition = totalHits - 1;
+ session.setAttribute("positionInResults", new Integer(newPosition));
+ }
+ else {
+ if (searchForwardValue != null) {
+ int totalHits = ( (Integer) session.getAttribute("numberOfHits")).intValue();
+ int newPosition = ( (Integer) session.getAttribute("positionInResults")).intValue() + increment;
+ if (newPosition < 0)
+ newPosition = 0;
+ if (newPosition >= totalHits)
+ newPosition = totalHits - 1;
+
+ session.setAttribute("positionInResults", new Integer(newPosition));
+ }
+ else {
+ File indexFile = FileRoutines.getAbsoluteOrRelativeFile(getConfiguration().getHome(), getConfiguration().getString("IndexPath"));
+
+ String creatorFragment = creatorTerm.makeTerm(req);
+ if (creatorFragment != null) {
+ queryString = queryString + " +" + creatorFragment;
+ }
+
+ // search title, description, and content for something
+ // the contentTerm uses param "search_boolean" to combine its terms
+ String contentFragment = contentTerm.makeTerm(req);
+ if (contentFragment != null) {
+ getLogger().debug("contentFragment: " + contentFragment);
+ queryString = queryString + " +" + contentFragment;
+ }
+
+ String topicFragment = topicTerm.makeTerm(req);
+ if (topicFragment != null) {
+ queryString = queryString + " +" + topicFragment;
+ }
+
+ String topicMatrixFragment = topicMatrixTerm.makeTerm(req);
+ if (topicMatrixFragment != null) {
+ queryString = queryString + " +" + topicMatrixFragment;
+ }
+
+ String imagesFragment = imagesTerm.makeTerm(req);
+ if (imagesFragment != null) {
+ queryString = queryString + " +" + imagesFragment;
+ }
+
+ String audioFragment = audioTerm.makeTerm(req);
+ if (audioFragment != null) {
+ queryString = queryString + " +" + audioFragment;
+ }
+
+ String videoFragment = videoTerm.makeTerm(req);
+ if (videoFragment != null) {
+ queryString = queryString + " +" + videoFragment;
+ }
+
+ if (queryString == null || queryString.length()==0) {
+ queryString = "";
+ }
+ else {
+ try {
+ Searcher searcher = null;
+
+ try {
+ searcher = new IndexSearcher(FSDirectory.getDirectory(indexFile,false));
+ }
+ catch (IOException e) {
+ getLogger().debug("Can't open indexPath: " + indexFile.getAbsolutePath());
+ throw new ServletModuleExc("Problem with Search Index! : " + e.toString());
+ }
+
+ Query query;
+ try {
+ query = QueryParser.parse(queryString, "content", new StandardAnalyzer());
+ }
+ catch (Exception e) {
+ searcher.close();
+ getLogger().debug("Query don't parse: " + queryString);
+ throw new ServletModuleExc("Problem with Query String! (was '" + queryString + "')");
+ }
+
+ Hits hits = null;
+ try {
+ hits = searcher.search(query);
+ }
+ catch (IOException e) {
+ searcher.close();
+ getLogger().debug("Can't get hits: " + e.toString());
+ throw new ServletModuleExc("Problem getting hits!");
+ }
+
+ int start = 0;
+ int end = hits.length();
+
+ String sortBy = req.getParameter("search_sort");
+ if (sortBy == null || sortBy.equals("")) {
+ throw new ServletModuleExc("Please let me sort by something!(missing search_sort)");
+ }
+
+ // here is where the documents will go for database across sessions
+ ArrayList theDocumentsSorted = new ArrayList();
+
+ if (sortBy.equals("score")) {
+ for (int i = start; i < end; i++) {
+ theDocumentsSorted.add(hits.doc(i));
+ }
+ }
+ else {
+ // then we'll sort by date!
+ Map dateToPosition = new HashMap(end, 1.0F); //we know how big it will be
+ for (int i = start; i < end; i++) {
+ String creationDate = (hits.doc(i)).get("creationDate");
+ // do a little dance in case two contents created at the same second!
+ if (dateToPosition.containsKey(creationDate)) {
+ ( (ArrayList) (dateToPosition.get(creationDate))).add(new Integer(i));
+ }
+ else {
+ ArrayList thePositions = new ArrayList();
+ thePositions.add(new Integer(i));
+ dateToPosition.put(creationDate, thePositions);
+ }
+ }
+ Set keys = dateToPosition.keySet();
+ ArrayList keyList = new ArrayList(keys);
+ Collections.sort(keyList);
+ if (sortBy.equals("date_desc")) {
+ Collections.reverse(keyList);
+ }
+ else {
+ if (!sortBy.equals("date_asc")) {
+ throw new ServletModuleExc("don't know how to sort by: " + sortBy);
+ }
+ }
+ ListIterator keyTraverser = keyList.listIterator();
+ while (keyTraverser.hasNext()) {
+ ArrayList positions = (ArrayList) dateToPosition.get( (keyTraverser.next()));
+ ListIterator positionsTraverser = positions.listIterator();
+ while (positionsTraverser.hasNext()) {
+ theDocumentsSorted.add(hits.doc( ( (Integer) (positionsTraverser.next())).intValue()));
+ }
+ }
+ }
+
+ try {
+ searcher.close();
+ }
+ catch (IOException e) {
+ getLogger().debug("Can't close searcher: " + e.toString());
+ throw new ServletModuleFailure("Problem closing searcher(normal):" + e.getMessage(), e);
+ }
+
+ session.removeAttribute("numberOfHits");
+ session.removeAttribute("theDocumentsSorted");
+ session.removeAttribute("positionInResults");
+
+ session.setAttribute("numberOfHits", new Integer(end));
+ session.setAttribute("theDocumentsSorted", theDocumentsSorted);
+ session.setAttribute("positionInResults", new Integer(0));
+
+ }
+ catch (IOException e) {
+ getLogger().debug("Can't close searcher: " + e.toString());
+ throw new ServletModuleFailure("Problem closing searcher: " + e.getMessage(), e);
+ }
+ }