Adding search box, make searches case insensitive

This commit is contained in:
Erik Forkalsrud 2010-10-23 16:36:13 -07:00
parent 7eeb7d9bae
commit 1ce75d2da8
7 changed files with 33 additions and 13 deletions

View file

@ -21,7 +21,7 @@ import org.forkalsrud.album.db.DirectoryProps;
/**
* @author knut
*/
public class DirectoryEntry extends EntryWithChildren {
public class DirectoryEntry extends EntryWithChildren<Entry> {
final static String CACHE_FILE = "cache.properties";
final static String OVERRIDE_FILE = "album.properties";
@ -195,4 +195,9 @@ public class DirectoryEntry extends EntryWithChildren {
loadChildren();
return earliest;
}
@Override
public boolean groupByYear() {
return parent == null;
}
}

View file

@ -116,4 +116,9 @@ public abstract class Entry {
public Date getEarliest() {
return getDate();
}
public boolean groupByYear() {
return false;
}
}

View file

@ -11,9 +11,9 @@ import java.util.List;
* @author knut
*
*/
public class EntryWithChildren extends Entry {
public class EntryWithChildren<T extends Entry> extends Entry {
protected List<Entry> children = new ArrayList<Entry>();
protected List<T> children = new ArrayList<T>();
protected EntryWithChildren(Entry root) {
super(root);
@ -46,12 +46,12 @@ public class EntryWithChildren extends Entry {
}
}
public List<Entry> getContents() {
public List<T> getContents() {
return children;
}
public void addContents(Entry entry) {
public void addContents(T entry) {
children.add(entry);
}

View file

@ -22,6 +22,7 @@ public class SearchEngine {
DirectoryEntry next = queue.removeFirst();
processDirectory(next, query);
}
results.sort();
results.fillLinkedList();
return results;
}
@ -52,7 +53,7 @@ public class SearchEngine {
}
boolean isMatch(String candidate, String query) {
return candidate != null && candidate.indexOf(query) >= 0;
return candidate != null && candidate.toUpperCase().contains(query.toUpperCase());
}
}

View file

@ -1,11 +1,12 @@
package org.forkalsrud.album.exif;
import java.io.File;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
public class SearchResults extends EntryWithChildren {
public class SearchResults extends EntryWithChildren<SearchEntry> {
protected HashMap<File, SearchEntry> dupes = new HashMap<File, SearchEntry>();
Comparator<SearchEntry> sort = new Comparator<SearchEntry>() {
@ -34,6 +35,10 @@ public class SearchResults extends EntryWithChildren {
}
}
public void sort() {
Collections.sort(children, sort);
}
}

View file

@ -187,6 +187,9 @@ public class AlbumServlet
String pathInfo = req.getPathInfo();
if (pathInfo != null && pathInfo.startsWith(basePrefix)) {
pathInfo = pathInfo.substring(basePrefix.length());
} else if (pathInfo.equals("/search")) {
handleSearch(req, res, (DirectoryEntry)resolveEntry("/"));
return;
} else {
res.sendError(HttpServletResponse.SC_NOT_FOUND, "pathinfo=" + pathInfo);
return;
@ -210,11 +213,6 @@ public class AlbumServlet
return;
}
if (pathInfo.endsWith(".search")) {
pathInfo = pathInfo.substring(0, pathInfo.length() - ".search".length());
handleSearch(req, res, (DirectoryEntry)resolveEntry(pathInfo));
return;
}
File file = new File(base, pathInfo);
if (!file.canRead()) {
@ -299,6 +297,7 @@ public class AlbumServlet
SearchResults results = search.search(query);
res.setContentType("text/html");
req.setAttribute("search", query);
req.setAttribute("entry", results);
req.setAttribute("thmb", new Integer(250));
req.setAttribute("full", new Integer(800));

View file

@ -27,6 +27,10 @@
h1 {
text-align: left;
}
form {
float: right;
display: inline;
}
h2 {
margin-left: 30px;
text-align: left;
@ -89,6 +93,7 @@ $(document).ready(function() {
</script>
</head>
<body>
<form action="${base}/search" method="get"><input name="q" value="$!search"></form>
#macro(navlink $entry)${base}$mapper.map(${entry.getPath()}).#if($entry.isFile())photo#{else}album#end#end
#macro(navbutton $entry $direction)#if($entry)<a href="#navlink($entry)"><img class="nav" width="26" height="32" src="${assets}/${direction}.png"/></a>#else<img class="nav" width="26" height="32" src="${assets}/${direction}-inactive.png"/>#end#end
<h1>#navbutton(${entry.prev()} "left")#navbutton(${entry.parent()} "up")#navbutton(${entry.next()} "right") $entry.name</h1>
@ -100,7 +105,7 @@ $(document).ready(function() {
#set($thpath = $mapper.map(${en.thumbnail.getPath()}))
#set($cdate = ${en.earliest})
#set($cyr = $mapper.year($cdate))
#if($cyr != $yr && !${entry.parent()})
#if($cyr != $yr && ${entry.groupByYear()})
#set($yr = $cyr)
<h2>$yr</h2>
#end