From: <bra...@us...> - 2007-07-16 22:32:44
|
Revision: 1771 http://archive-access.svn.sourceforge.net/archive-access/?rev=1771&view=rev Author: bradtofel Date: 2007-07-16 15:32:47 -0700 (Mon, 16 Jul 2007) Log Message: ----------- INITIAL REV: possibly transient explicit separation of search result types: url and capture Modified Paths: -------------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java Added Paths: ----------- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UrlSearchResults.java Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/CaptureSearchResults.java 2007-07-16 22:32:47 UTC (rev 1771) @@ -0,0 +1,97 @@ +/* CaptureSearchResults + * + * $Id$ + * + * Created on 4:05:33 PM Apr 19, 2007. + * + * Copyright (C) 2007 Internet Archive. + * + * This file is part of wayback-core. + * + * wayback-core is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback-core is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback-core; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.core; + +import java.text.ParseException; +import java.util.Iterator; + +import org.archive.wayback.WaybackConstants; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class CaptureSearchResults extends SearchResults { + public String getResultsType() { + return WaybackConstants.RESULTS_TYPE_CAPTURE; + } + /** + * append a result + * @param result + */ + public void addSearchResult(final SearchResult result) { + addSearchResult(result,true); + } + /** + * add a result to this results, at either the begginning or at the end, + * depending on the append argument + * @param result + * SearchResult to add to this set + * @param append + */ + public void addSearchResult(final SearchResult result, final boolean append) { + String resultDate = result.get(WaybackConstants.RESULT_CAPTURE_DATE); + if((firstResultDate == null) || + (firstResultDate.compareTo(resultDate) > 0)) { + firstResultDate = resultDate; + } + if((lastResultDate == null) || + (lastResultDate.compareTo(resultDate) < 0)) { + lastResultDate = resultDate; + } + addSearchResultRaw(result,append); + } + /** + * @param wbRequest + * @return The closest SearchResult to the request. + * @throws ParseException + */ + public SearchResult getClosest(WaybackRequest wbRequest) { + + SearchResult closest = null; + long closestDistance = 0; + SearchResult cur = null; + Timestamp wantTimestamp; + wantTimestamp = Timestamp.parseBefore(wbRequest + .get(WaybackConstants.REQUEST_EXACT_DATE)); + + Iterator itr = results.iterator(); + while (itr.hasNext()) { + cur = (SearchResult) itr.next(); + long curDistance; + Timestamp curTimestamp = Timestamp.parseBefore(cur + .get(WaybackConstants.RESULT_CAPTURE_DATE)); + curDistance = curTimestamp.absDistanceFromTimestamp(wantTimestamp); + + if ((closest == null) || (curDistance < closestDistance)) { + closest = cur; + closestDistance = curDistance; + } + } + return closest; + } +} Modified: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java 2007-07-16 22:30:57 UTC (rev 1770) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/SearchResults.java 2007-07-16 22:32:47 UTC (rev 1771) @@ -24,32 +24,29 @@ */ package org.archive.wayback.core; -import java.text.ParseException; import java.util.ArrayList; import java.util.Iterator; import java.util.Properties; -import org.archive.wayback.WaybackConstants; - /** * * * @author brad * @version $Date$, $Revision$ */ -public class SearchResults { +public abstract class SearchResults { /** * List of SearchResult objects for index records matching a query */ - private ArrayList<SearchResult> results = null; + protected ArrayList<SearchResult> results = null; /** * 14-digit timestamp of first capture date contained in the SearchResults */ - private String firstResultDate; + protected String firstResultDate; /** * 14-digit timestamp of last capture date contained in the SearchResults */ - private String lastResultDate; + protected String lastResultDate; /** * Expandable data bag for tuples associated with the search results, * likely examples might be "total matching documents", "index of first @@ -72,35 +69,39 @@ } /** - * append a result * @param result + * @param append */ - public void addSearchResult(final SearchResult result) { - addSearchResult(result,true); + public void addSearchResultRaw(final SearchResult result, + final boolean append) { + + if(append) { + results.add(result); + } else { + results.add(0,result); + } } + /** + * @return one of "Url" or "Capture" depending on the type of results + * contained in this object + */ + public abstract String getResultsType(); + + /** + * append a result + * @param result + */ + public abstract void addSearchResult(final SearchResult result); + /** * add a result to this results, at either the begginning or at the end, * depending on the append argument * @param result * SearchResult to add to this set * @param append */ - public void addSearchResult(final SearchResult result, final boolean append) { - String resultDate = result.get(WaybackConstants.RESULT_CAPTURE_DATE); - if((firstResultDate == null) || - (firstResultDate.compareTo(resultDate) > 0)) { - firstResultDate = resultDate; - } - if((lastResultDate == null) || - (lastResultDate.compareTo(resultDate) < 0)) { - lastResultDate = resultDate; - } - if(append) { - results.add(result); - } else { - results.add(0,result); - } - } + public abstract void addSearchResult(final SearchResult result, + final boolean append); /** * @return number of SearchResult objects contained in these SearchResults @@ -158,33 +159,4 @@ public Properties getFilters() { return filters; } - /** - * @param wbRequest - * @return The closest SearchResult to the request. - * @throws ParseException - */ - public SearchResult getClosest(WaybackRequest wbRequest) { - - SearchResult closest = null; - long closestDistance = 0; - SearchResult cur = null; - Timestamp wantTimestamp; - wantTimestamp = Timestamp.parseBefore(wbRequest - .get(WaybackConstants.REQUEST_EXACT_DATE)); - - Iterator itr = results.iterator(); - while (itr.hasNext()) { - cur = (SearchResult) itr.next(); - long curDistance; - Timestamp curTimestamp = Timestamp.parseBefore(cur - .get(WaybackConstants.RESULT_CAPTURE_DATE)); - curDistance = curTimestamp.absDistanceFromTimestamp(wantTimestamp); - - if ((closest == null) || (curDistance < closestDistance)) { - closest = cur; - closestDistance = curDistance; - } - } - return closest; - } } Added: trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UrlSearchResults.java =================================================================== --- trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UrlSearchResults.java (rev 0) +++ trunk/archive-access/projects/wayback/wayback-core/src/main/java/org/archive/wayback/core/UrlSearchResults.java 2007-07-16 22:32:47 UTC (rev 1771) @@ -0,0 +1,58 @@ +/* UrlSearchResults + * + * $Id$ + * + * Created on 4:06:03 PM Apr 19, 2007. + * + * Copyright (C) 2007 Internet Archive. + * + * This file is part of wayback-core. + * + * wayback-core is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * any later version. + * + * wayback-core is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser Public License for more details. + * + * You should have received a copy of the GNU Lesser Public License + * along with wayback-core; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +package org.archive.wayback.core; + +import org.archive.wayback.WaybackConstants; + +/** + * + * + * @author brad + * @version $Date$, $Revision$ + */ +public class UrlSearchResults extends SearchResults { + private UrlSearchResultAccumulator accumulator = null; + + public String getResultsType() { + return WaybackConstants.RESULTS_TYPE_URL; + } + public void addSearchResult(SearchResult result) { + addSearchResult(result,true); + } + + /* (non-Javadoc) + * @see org.archive.wayback.core.SearchResults#addSearchResult(org.archive.wayback.core.SearchResult, boolean) + */ + @Override + public void addSearchResult(SearchResult result, boolean append) { + addSearchResultRaw(result,append); +// if(accumulator != null && accumulator.sameUrl(result)) { +// accumulator.addSearchResult(result); +// } else { +// accumulator = new UrlSearchResultAccumulator(result); +// addSearchResultRaw(accumulator.getResult(),append); +// } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |