import mir.entity.*;
import mir.storage.*;
import mir.media.*;
+import mir.log.*;
import mircoders.entity.*;
import mircoders.storage.*;
* open-postings to the newswire
*
* @author mir-coders group
- * @version $Id: ServletModuleOpenIndy.java,v 1.44 2002/11/27 15:28:52 john Exp $
+ * @version $Id: ServletModuleOpenIndy.java,v 1.48 2002/11/30 19:45:57 zapata Exp $
*
*/
private ServletModuleOpenIndy() {
try {
- theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.OpenIndy.Logfile"));
+ logger = new LoggerWrapper("ServletModule.OpenIndy");
+
commentFormTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentTemplate");
commentFormDoneTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDoneTemplate");
commentFormDupeTemplate = MirConfig.getProp("ServletModule.OpenIndy.CommentDupeTemplate");
}
catch (StorageObjectException e) {
- theLog.printError("servletmoduleopenindy could not be initialized");
+ logger.error("servletmoduleopenindy could not be initialized: " + e.getMessage());
}
}
// inserting into database
String id = mainModule.add(withValues);
- theLog.printDebugInfo("id: "+id);
+ logger.debug("id: "+id);
//insert was not successfull
if(id==null){
deliver(req, res, new SimpleHash(), commentFormDupeTemplate);
extraInfo.put("topics", themenModule.getTopicsList());
- } catch (Exception e) {
- theLog.printError("languagePopUpData or getTopicslist failed "
- +e.toString());
+ }
+ catch (Exception e) {
+ logger.error("languagePopUpData or getTopicslist failed "+e.toString());
throw new ServletModuleException("OpenIndy -- failed getting language or topics: "+e.toString());
}
// inserting content into database
String cid = contentModule.add(withValues);
- theLog.printDebugInfo("id: "+cid);
+ logger.debug("id: "+cid);
//insert was not successfull
if(cid==null){
//How do we know that it was not succesful cause of a
try{
DatabaseContentToTopics.getInstance().setTopics(cid,to_topicsArr);
setTopic = true;
- } catch (Exception e) {
- theLog.printError("setting content_x_topic failed");
+ }
+ catch (Exception e) {
+ logger.error("setting content_x_topic failed");
contentModule.deleteById(cid);
throw new ServletModuleException("smod - openindy :: insposting: setting content_x_topic failed: "+e.toString());
} //end try
*/
public void search(HttpServletRequest req, HttpServletResponse res)
throws ServletModuleException, ServletModuleUserException {
-
- String queryString="";
-
- SimpleHash mergeData = new SimpleHash();
-
- //make the query available to subsequent iterations
+ try {
+ int increment=10;
- for (Enumeration theParams = req.getParameterNames(); theParams.hasMoreElements() ;) {
- String pName=(String)theParams.nextElement();
- if (pName.startsWith("search_")){
- mergeData.put(pName,new SimpleScalar(req.getParameter(pName)));
- }
- }
-
- try{
- mergeData.put("topics", themenModule.getTopicsAsSimpleList());
- }
- catch(ModuleException e) {
- theLog.printDebugInfo("Can't get topics: " + e.toString());
- }
+ HttpSession session = req.getSession(false);
- //String indexPath=MirConfig.getProp("IndexPath");
- String indexPath="/tmp/index";
-
- KeywordSearchTerm dateTerm = new KeywordSearchTerm("date_formatted","search_date","webdb_create_formatted","webdbcreate_formatted","webdb_create_formatted");
+ String queryString="";
- UnIndexedSearchTerm whereTerm = new UnIndexedSearchTerm("","","","where","where");
+ SimpleHash mergeData = new SimpleHash();
- TextSearchTerm creatorTerm = new TextSearchTerm("creator","search_creator","creator","creator","creator");
- TextSearchTerm titleTerm = new TextSearchTerm("title","search_content","title","title","title");
- TextSearchTerm descriptionTerm = new TextSearchTerm("description","search_content","description","description","description");
-
- ContentSearchTerm contentTerm = new ContentSearchTerm("content_data","search_content","content","","");
-
- TopicSearchTerm topicTerm = new TopicSearchTerm();
+ KeywordSearchTerm dateTerm = new KeywordSearchTerm("date_formatted","search_date","webdb_create_formatted","webdb_create_formatted","webdb_create_formatted");
+ UnIndexedSearchTerm whereTerm = new UnIndexedSearchTerm("","","","where","where");
+ TextSearchTerm creatorTerm = new TextSearchTerm("creator","search_creator","creator","creator","creator");
+ TextSearchTerm titleTerm = new TextSearchTerm("title","search_content","title","title","title");
+ TextSearchTerm descriptionTerm = new TextSearchTerm("description","search_content","description","description","description");
+ ContentSearchTerm contentTerm = new ContentSearchTerm("content_data","search_content","content","","");
+ TopicSearchTerm topicTerm = new TopicSearchTerm();
+ ImagesSearchTerm imagesTerm = new ImagesSearchTerm();
+ AudioSearchTerm audioTerm = new AudioSearchTerm();
+ VideoSearchTerm videoTerm = new VideoSearchTerm();
- ImagesSearchTerm imagesTerm = new ImagesSearchTerm();
-
- AudioSearchTerm audioTerm = new AudioSearchTerm();
-
- VideoSearchTerm videoTerm = new VideoSearchTerm();
+ //make the query available to subsequent iterations
- String creatorFragment = creatorTerm.makeTerm(req);
- if (creatorFragment != null){
- queryString = queryString + " +" + creatorFragment;
- }
+ for (Enumeration theParams = req.getParameterNames(); theParams.hasMoreElements() ;) {
+ String pName=(String)theParams.nextElement();
+ if (pName.startsWith("search_")){
+ mergeData.put(pName,new SimpleScalar(req.getParameter(pName)));
+ }
+ }
- // search title, description, and content for something
- // the contentTerm uses "search_boolean" to combine its terms
- String contentFragment = contentTerm.makeTerm(req);
- if (contentFragment != null){
- theLog.printDebugInfo("contentFragment: " + contentFragment);
- queryString = queryString + " +" + contentFragment;
- }
+ try{
+ mergeData.put("topics", themenModule.getTopicsAsSimpleList());
+ }
+ catch(ModuleException e) {
+ logger.debug("Can't get topics: " + e.toString());
+ }
- String topicFragment = topicTerm.makeTerm(req);
- if (topicFragment != null){
- queryString = queryString + " +" + topicFragment;
- }
-
- String imagesFragment = imagesTerm.makeTerm(req);
- if (imagesFragment != null){
- queryString = queryString + " +" + imagesFragment;
- }
+ String searchSubmitValue = req.getParameter("search_submit");
- 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 == ""){
- queryString = "";
- }
- else{
+ if (searchSubmitValue != null && searchSubmitValue.equals("Back")){
+ int totalHits = ((Integer) session.getAttribute("numberOfHits")).intValue();
+ int newPosition=((Integer)session.getAttribute("positionInResults")).intValue()-increment;
+ if (newPosition < 0 || newPosition >= totalHits){
+ throw new ServletModuleUserException("newPosition: index out bounds, value was:"+(new Integer(newPosition)).toString());
+ }
+ session.setAttribute("positionInResults",new Integer(newPosition));
+
+ }
+ else {
+ if (searchSubmitValue != null && searchSubmitValue.equals("Forward")){
+ int totalHits = ((Integer) session.getAttribute("numberOfHits")).intValue();
+ int newPosition=((Integer)session.getAttribute("positionInResults")).intValue()+increment;
+ if (newPosition < 0 || newPosition >= totalHits){
+ throw new ServletModuleUserException("newPosition: index out bounds, value was:"+(new Integer(newPosition)).toString());
+ }
+ session.setAttribute("positionInResults",new Integer(newPosition));
- try{
- Searcher searcher = null;
- try {
- searcher = new IndexSearcher(indexPath);
- }
- catch(IOException e) {
- theLog.printDebugInfo("Can't open indexPath: " + indexPath);
- throw new ServletModuleUserException("Problem with Search Index!");
}
+ else {
+ String indexPath=MirConfig.getProp("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){
+ logger.debug("contentFragment: " + contentFragment);
+ queryString = queryString + " +" + contentFragment;
+ }
+
+ String topicFragment = topicTerm.makeTerm(req);
+ if (topicFragment != null){
+ queryString = queryString + " +" + topicFragment;
+ }
+
+ 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 == ""){
+ queryString = "";
+ }
+ else{
+ try{
+ Searcher searcher = null;
+ try {
+ searcher = new IndexSearcher(indexPath);
+ }
+ catch(IOException e) {
+ logger.debug("Can't open indexPath: " + indexPath);
+ throw new ServletModuleUserException("Problem with Search Index! : "+ e.toString());
+ }
- // parse the query String.
- Query query = null;
- try {
- query = QueryParser.parse(queryString, "content", new StandardAnalyzer());
- }
- catch(Exception e) {
- searcher.close();
- theLog.printDebugInfo("Query don't parse: " + queryString);
- throw new ServletModuleUserException("Problem with Query String! (was '"+queryString+"')");
- }
+ Query query = null;
+ try {
+ query = QueryParser.parse(queryString, "content", new StandardAnalyzer());
+ }
+ catch(Exception e) {
+ searcher.close();
+ logger.debug("Query don't parse: " + queryString);
+ throw new ServletModuleUserException("Problem with Query String! (was '"+queryString+"')");
+ }
- Hits hits = null;
- try {
- hits = searcher.search(query);
- } catch(IOException e) {
- searcher.close();
- theLog.printDebugInfo("Can't get hits: " + e.toString());
- throw new ServletModuleUserException("Problem getting hits!");
+ Hits hits = null;
+ try {
+ hits = searcher.search(query);
+ }
+ catch(IOException e) {
+ searcher.close();
+ logger.debug("Can't get hits: " + e.toString());
+ throw new ServletModuleUserException("Problem getting hits!");
+ }
+
+ int start = 0;
+ int end = hits.length();
+
+ String sortBy=req.getParameter("search_sort");
+ if (sortBy == null || sortBy.equals("")){
+ throw new ServletModuleUserException("Please let me sort by something!(missing search_sort)");
+ }
+
+ // here is where the documents will go for storage 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!
+ HashMap 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 ServletModuleUserException("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){
+ logger.debug("Can't close searcher: " + e.toString());
+ throw new ServletModuleUserException("Problem closing searcher(normal)!");
+ }
+
+
+ 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){
+ logger.debug("Can't close searcher: " + e.toString());
+ throw new ServletModuleUserException("Problem closing searcher!");
+ }
+ }
}
+ }
+
+ try {
+ ArrayList theDocs = (ArrayList)session.getAttribute("theDocumentsSorted");
+ if (theDocs != null){
-
- // this is what needs to change in order to get sorting by date
- // iterate over the results
- // the results are an array of document
- // associate this with session so we don't need to reduplicate searches
- // make a map from date to position
- // make an list of dates
- // sort list by date
- // grab low+n entries from the list of dates,
- // iterate over these, using hash to get hit position,
- // and hit position to get hit
- // shove hit into SimpleList of SimpleHashes
+ mergeData.put("numberOfHits", ((Integer)session.getAttribute("numberOfHits")).toString());
+ SimpleList theHits = new SimpleList();
+ int pIR=((Integer)session.getAttribute("positionInResults")).intValue();
+ int terminus;
+ int numHits=((Integer)session.getAttribute("numberOfHits")).intValue();
-
+ if (!(pIR+increment>=numHits)){
+ mergeData.put("hasNext","y");
+ }
+ if (pIR-increment>=0){
+ mergeData.put("hasPrevious","y");
+ }
- try {
- int start = 0;
- int end = hits.length();
- mergeData.put("numberOfHits", (new Integer(end)).toString());
- SimpleList theHits = new SimpleList();
- for(int i = start; i < end; i++) {
+ if ((pIR+increment)>numHits){
+ terminus=numHits;
+ }
+ else {
+ terminus=pIR+increment;
+ }
+ for(int i = pIR; i < terminus; i++) {
SimpleHash h = new SimpleHash();
- Document theHit = hits.doc(i);
+ Document theHit = (Document)theDocs.get(i);
whereTerm.returnMeta(h,theHit);
creatorTerm.returnMeta(h,theHit);
titleTerm.returnMeta(h,theHit);
}
mergeData.put("hits",theHits);
}
- catch (Exception e) {
- searcher.close();
- theLog.printDebugInfo("Can't iterate over hits: " + e.toString());
- throw new ServletModuleUserException("Problem getting hits!");
- }
- searcher.close();
}
- catch (IOException e){
- theLog.printDebugInfo("Can't close searcher: " + e.toString());
- throw new ServletModuleUserException("Problem closing searcher!");
+ catch (Exception e) {
+ logger.debug("Can't iterate over hits: " + e.toString());
+ throw new ServletModuleUserException("Problem getting hits!");
}
+
+ mergeData.put("queryString",queryString);
+ deliver(req,res,mergeData,searchResultsTemplate);
+ }
+ catch (NullPointerException n){
+ n.printStackTrace();
+ throw new ServletModuleUserException("Null Pointer"+n.toString());
}
- mergeData.put("queryString",queryString);
- deliver(req,res,mergeData,searchResultsTemplate);
}
-
+
/*
* Method for dynamically generating a pdf from a fo file
*/
//pregenerating PDF's
if (generateFO.equals("yes") && generatePDF.equals("no")){
//fop complains unless you do the logging this way
- Logger log = null;
+ org.apache.log.Logger log = null;
Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
log = hierarchy.getLoggerFor("fop");
log.setPriority(Priority.WARN);
private void _throwBadContentType (String fileName, String contentType)
throws ServletModuleUserException {
- theLog.printDebugInfo("Wrong file type uploaded!: " + fileName+" "
+ logger.error("Wrong file type uploaded!: " + fileName+" "
+contentType);
throw new ServletModuleUserException("The file you uploaded is of the "
+"following mime-type: "+contentType