# HG changeset patch # User Zoe Hong # Date 1449235724 -3600 # Node ID 37840afb7b801f4534555ae62a98197975e7f7e8 # Parent 8b7a204fa92939871b0d01679ed0cb079bf88fe6 new: full text search diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/bo/LGFullTextSearchFile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/bo/LGFullTextSearchFile.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,85 @@ +package de.mpiwg.gazetteer.bo; + +import java.io.Serializable; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; + +import cl.maps.duplex.DuplexKey; + + +@Entity +@Table(name="FullTextSearchFile") +@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) +public class LGFullTextSearchFile extends DBEntry implements Cloneable, Serializable { + private static final long serialVersionUID = 7805209462045170778L; + + + @Column(name="userId") + private Long userId; + + @Column(name="searchTerms") + private String searchTerms; + + @Column(name="fileName") + private String fileName; + + + + public boolean isEmpty() { + if (this.fileName == null) { + return true; + } else { + return false; + } + } + + + + public Long getUserId() { + return userId; + } + + + + public void setUserId(Long userId) { + this.userId = userId; + } + + + public String getSearchTerms() { + return searchTerms; + } + + + + public void setSearchTerms(String searchTerms) { + this.searchTerms = searchTerms; + } + + + + public String getFileName() { + return fileName; + } + + + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + + public DuplexKey getKey(){ + return new DuplexKey(this.userId, this.id); + } + + + +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/db/DBBook.java --- a/src/main/java/de/mpiwg/gazetteer/db/DBBook.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBBook.java Fri Dec 04 14:28:44 2015 +0100 @@ -16,8 +16,8 @@ private String volume; private String dynasty; - private String level1; - private String level2; + private String level1 = ""; + private String level2 = ""; private String admin_type; private String in_jibengujiku; @@ -27,6 +27,7 @@ private String toc_correction; + private DBSectionVersion currentSectionVersion; @@ -49,9 +50,11 @@ this.start_year = rs.getInt("start_year"); this.end_year = rs.getInt("end_year"); this.comments = rs.getString("comments"); - //this.toc_correction = Integer.parseInt(rs.getString("toc_correction")); + this.toc_correction = rs.getString("toc_correction"); + + } @Override diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/db/DBContents.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBContents.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,127 @@ +package de.mpiwg.gazetteer.db; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import de.mpiwg.gazetteer.utils.DBService; + + + +public class DBContents implements Comparable{ + + private Long id; + + private String bookId; + private Integer page; + private String content; + + private DBSection section; // section already contain DBBook + private Integer inx = null; // local index for each row + + private DBCoordinatesBook coordinatesBook = null; + + private boolean isRemoved = false; + + + public DBContents(ResultSet rs) throws SQLException{ + + this.id = rs.getLong("id"); + this.bookId = rs.getString("books_id"); + this.page = rs.getInt("line"); + this.content = rs.getString("content"); + + // set this.section by bookId and page + this.section = DBService.getInstance().getSectionByBookIdAndPage(this.bookId, this.page); + + // set this.coordinatesBook by bookId + this.coordinatesBook = DBService.getInstance().getCoordinatesBook(bookId); + + } + + + public Long getId() { + return id; + } + public void setId(Long id) { + this.id = id; + } + + + public String getBookId() { + return bookId; + } + + public void setBookId(String bookId) { + this.bookId = bookId; + } + + + + public String getContent() { + return content; + } + + + public void setContent(String content) { + this.content = content; + } + + + public DBSection getSection() { + return section; + } + + + public void setSection(DBSection section) { + this.section = section; + } + + + + public Integer getPage() { + return page; + } + + + public void setPage(Integer page) { + this.page = page; + } + + + public Integer getInx() { + return inx; + } + + + public void setInx(Integer inx) { + this.inx = inx; + } + + + + public DBCoordinatesBook getCoordinatesBook() { + return coordinatesBook; + } + + + public void setCoordinatesBook(DBCoordinatesBook coordinatesBook) { + this.coordinatesBook = coordinatesBook; + } + + + public boolean isRemoved() { + return isRemoved; + } + + + public void setRemoved(boolean isRemoved) { + this.isRemoved = isRemoved; + } + + + @Override + public int compareTo(DBContents o) { + return this.getInx().compareTo(o.getInx()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/db/DBCoordinatesBook.java --- a/src/main/java/de/mpiwg/gazetteer/db/DBCoordinatesBook.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBCoordinatesBook.java Fri Dec 04 14:28:44 2015 +0100 @@ -18,7 +18,7 @@ this.books_id = rs.getString("books_id"); this.place_name = rs.getString("place_name"); this.x = rs.getString("x"); - this.y = rs.getString("y"); + this.y = rs.getString("y"); } diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/rest/GetFullTextSearchHtmlFile.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,69 @@ +package de.mpiwg.gazetteer.rest; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.json.JSONObject; + +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.gazetteer.utils.FileManager; +import de.mpiwg.gazetteer.utils.HTTPUtils; +import de.mpiwg.gazetteer.utils.exceptions.GazetteerException; +import de.mpiwg.web.jsp.FullTextSearchPage; + +public class GetFullTextSearchHtmlFile extends AbstractServletMethod { + public static String name = "getFullTextSearchHtmlFile"; + + private static Logger logger = Logger.getLogger(GetFullTextSearchHtmlFile.class); + + + public static void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{ + + Long fileId = getQueryLongParam(request, "fileId"); + + logger.debug("getting full text search html file."); + + // get html file from /gazetteer-server/ftsearch-data/html/... + if(fileId != null){ + + LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId); + if(file != null){ + + String text = FileManager.getFullTextSearchHtmlFileText(file); + PrintWriter out = response.getWriter(); + out.print(text); + out.flush(); + response.setContentType("text/plain; charset=UTF-8"); + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "File no found (" + fileId + ")"); + json.put("code", GazetteerException.CODE); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + + + + }else{ + response.setContentType("application/json"); + JSONObject json = new JSONObject(); + json.put("status", "error"); + json.put("message", "Following parameters are mandatory: fileId, userId"); + PrintWriter out = response.getWriter(); + out.print(json.toString()); + out.flush(); + } + + } + +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/rest/TextServlet.java --- a/src/main/java/de/mpiwg/gazetteer/rest/TextServlet.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/rest/TextServlet.java Fri Dec 04 14:28:44 2015 +0100 @@ -65,6 +65,8 @@ GetTable4File.execute(request, response); }else if(StringUtils.equals(GetTabDelimited4File.name, method)){ GetTabDelimited4File.execute(request, response); + }else if(StringUtils.equals(GetFullTextSearchHtmlFile.name, method)){ + GetFullTextSearchHtmlFile.execute(request, response); }else{ writeError(response, "Content-type wrong. It should be: multipart/form-data"); } diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/utils/AbstractDataProvider.java --- a/src/main/java/de/mpiwg/gazetteer/utils/AbstractDataProvider.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/AbstractDataProvider.java Fri Dec 04 14:28:44 2015 +0100 @@ -5,6 +5,7 @@ import cl.maps.duplex.DuplexMap; import de.mpiwg.gazetteer.bo.LGBranch; import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; public class AbstractDataProvider { @@ -48,4 +49,28 @@ } + private DuplexMap fullTextSearchFileMap = null; + + protected DuplexMap getFullTextSearchFileMap(){ + if(fullTextSearchFileMap == null){ + loadFullTextSearchFiles(); + } + return fullTextSearchFileMap; + } + + + public void setFullTextSearchFileMap( + DuplexMap fullTextSearchFileMap) { + this.fullTextSearchFileMap = fullTextSearchFileMap; + } + + private void loadFullTextSearchFiles(){ + List list = DBService.getAllLGFullTextSearchFileFromDB(); + this.fullTextSearchFileMap = new DuplexMap(); + for(LGFullTextSearchFile file : list){ + this.fullTextSearchFileMap.put(file.getKey(), file); + } + } + + } diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/utils/DBService.java --- a/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Fri Dec 04 14:28:44 2015 +0100 @@ -19,7 +19,9 @@ import de.mpiwg.gazetteer.bo.DBEntry; import de.mpiwg.gazetteer.bo.LGBranch; import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBContents; import de.mpiwg.gazetteer.db.DBCoordinatesBook; import de.mpiwg.gazetteer.db.DBSection; import de.mpiwg.gazetteer.db.DBSectionVersion; @@ -229,7 +231,8 @@ return list; } - public static List searchFullText(List termList) throws SQLException{ + /* + public static List searchFullText0(List termList) throws SQLException{ Long start = System.currentTimeMillis(); String condition = ""; @@ -258,6 +261,7 @@ Connection conn = null; Statement stmt = null; List resultSet = new ArrayList(); + // TODO new structure for the result of full text search? try { conn = getNewConnection(); stmt = conn.createStatement(); @@ -284,7 +288,97 @@ return resultSet; } + */ + + public DBSection getSectionByBookIdAndPage(String bookId, int page) throws SQLException { + + Connection conn = null; + Statement stmt = null; + + DBSection section = null; + + String query = "SELECT * FROM "+ SECTIONS_TABLE +" WHERE books_id='" + bookId + "' " + + "and start_page<=" + page + " and end_page>=" + page; + + try { + Class.forName(JDBC_DRIVER); + conn = getNewConnection(); + stmt = conn.createStatement(); + + ResultSet rs = stmt.executeQuery(query); + + while (rs.next()) { + section = new DBSection(rs); + DBBook book = getInstance().getBook(bookId); + section.setBook(book); + + } + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + + + return section; + + } + + + public static List searchFullText(List termList) throws SQLException{ + Long start = System.currentTimeMillis(); + + String condition = "("; + for(int i=0; i0){ + condition += " OR "; + } + + condition += " content like '%" + term + "%' "; + } + condition += ")"; + + + String sql = "SELECT contents.id, contents.books_id AS books_id, contents.line AS line, contents.content AS content " + + "FROM contents " + + "WHERE " + condition + "and (books_id='00204' or books_id='00219')"; // TODO: remove the books_id condition after debug + + //logger.debug("sql: " + sql); + + Connection conn = null; + Statement stmt = null; + List resultSet = new ArrayList(); + try { + conn = getNewConnection(); + stmt = conn.createStatement(); + + Integer count = 0; + ResultSet rs = stmt.executeQuery(sql); + while (rs.next()) { + count++; + DBContents content = new DBContents(rs); + content.setInx(count); // local index for row + resultSet.add(content); + } + logger.debug("************************* Count " + count + " **********************************"); + rs.close(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + conn.close(); + } + + long end = System.currentTimeMillis(); + logger.debug("Time execution full text search [ms]: " + (end - start)); + + return resultSet; + } + + + /** * This methods search from a list of terms. * Every term is considered a subsequence of whole section name. @@ -636,6 +730,20 @@ return list; } + + protected static List getAllLGFullTextSearchFileFromDB() { + List list = null; + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + Query query = session.createQuery("from LGFullTextSearchFile"); + list = query.list(); + session.getTransaction().commit(); + + return list; + + } + protected static List getAllLGFileFromDB(){ List list = null; @@ -712,7 +820,7 @@ // query in sections_versions table. // Each line is a current version (with largest version number) for a book. String query = "SELECT * FROM sections_versions s1 " + - "JOIN ( " + + "JOIN ( " + "SELECT books_id, MAX(version) AS version " + "FROM sections_versions " + "GROUP BY books_id) AS s2 " + @@ -778,5 +886,27 @@ } - + public static LGFullTextSearchFile getExistFullTextSearchFile(Long userId, String fileName) { + //logger.info("getExistFullTextSearchFile: (userId,fileName)=" + userId + ","+fileName); + List list = new ArrayList(); + + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + Query query = session.createQuery("from LGFullTextSearchFile where userId = :userId and fileName = :fileName"); + query.setLong("userId", userId); + query.setString("fileName", fileName); + + list = query.list(); + session.getTransaction().commit(); + + if (list.size() != 0) { + //logger.info("existing record."); + return list.get(0); + } else { + //logger.info("new record."); + return null; + } + + } + } diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java --- a/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Fri Dec 04 14:28:44 2015 +0100 @@ -8,8 +8,11 @@ import org.apache.log4j.Logger; import org.hibernate.Session; +import cl.maps.duplex.DuplexKey; import de.mpiwg.gazetteer.bo.LGBranch; import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; +import de.mpiwg.gazetteer.db.DBContents; import de.mpiwg.gazetteer.utils.exceptions.NoAuthorizedException; import de.mpiwg.gazetteer.utils.exceptions.VersioningException; @@ -255,4 +258,63 @@ return branch.getId(); } + + + public List getSearchFileList4User(Long userId) { + + List list = new ArrayList(); + + for(LGFullTextSearchFile searchFile : getFullTextSearchFileMap().values()){ + if(searchFile.getUserId() == userId){ + list.add(searchFile); + } + } + + return list; + } + + public LGFullTextSearchFile saveLGFullTextSearchFile(List list, Long userId, String fileName, String searchTerms) throws Exception { + // save as csv and html file in filesystem, and records in db `FullTextSearchFile + // List list is the filteredList of searching result + + Date date = new Date(); + + // check if record with (userId, fileName) already existed, update it; otherwise, create one + + LGFullTextSearchFile searchFile = DBService.getExistFullTextSearchFile(userId, fileName); + if (searchFile == null) { + searchFile = new LGFullTextSearchFile(); + searchFile.setFileName(fileName); + searchFile.setUserId(userId); + } + + searchFile.setSearchTerms(searchTerms); + + //Saving into DB + //################################## + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + session.getTransaction().begin(); + + DBService.saveDBEntry0(session, searchFile, date); + + //Saving physical file in the operating system + FileManager.saveFullTextSearchFileAsCsv(searchFile, userId, list); // save csv file to LGMap's datasets folder + FileManager.saveFullTextSearchFileAsHtml(searchFile, userId, list); // save html file to ftsearch-data folder + + session.getTransaction().commit(); + //################################## + + return searchFile; + } + + public LGFullTextSearchFile getFullTextSearchFile(Long fileId) { + + LGFullTextSearchFile file = getFullTextSearchFileMap().getValuesByOwnKey(fileId); + + return file; + } + + + + } diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/gazetteer/utils/FileManager.java --- a/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java Fri Dec 04 14:28:44 2015 +0100 @@ -1,20 +1,23 @@ package de.mpiwg.gazetteer.utils; import java.io.File; +import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Paths; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.UUID; +import java.util.List; -import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import de.mpiwg.gazetteer.bo.LGBranch; import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; +import de.mpiwg.gazetteer.db.DBBook; +import de.mpiwg.gazetteer.db.DBContents; public class FileManager { @@ -40,6 +43,140 @@ return base; } + + public static void saveFullTextSearchFileAsCsv(LGFullTextSearchFile file, Long userId, List list) throws Exception{ + + // String absolutePath = PropertiesUtils.getPropValue("ftsearch_root") + "/csv/" + userId.toString() + "/"; + String absolutePath = PropertiesUtils.getPropValue("lgmap_datasets") + "/"; + + String fileName = file.getUserId() + "_" + file.getFileName() + ".csv"; + + File folder = new File(absolutePath); + folder.mkdirs(); + + logger.info("Trying to save file " + absolutePath + fileName + "."); + + PrintWriter out = new PrintWriter(absolutePath + fileName); + + String text = new String(); // make it from list + text += "Address,LEVEL1,LEVEL2,Name,PERIOD,TimeSpan:begin,TimeSpan:end,Longitude,Latitude,PAGE,SECTION,CONTENT,BOOK_ID,Description\n"; + + for (DBContents r : list) { + + DBBook book = r.getSection().getBook(); + + String description = book.getVolume() + "/" + book.getAuthor() + "/" + book.getEdition(); + + text += r.getCoordinatesBook().getPlace_name() + "," + + book.getLevel1() + "," + + book.getLevel2() + "," + + book.getName() + "," + + book.getPeriod() + "," + + book.getStart_year() + "," + + book.getEnd_year() + "," + + r.getCoordinatesBook().getX() + "," + + r.getCoordinatesBook().getY() + "," + + r.getPage() + "," + + r.getSection().getName() + "," + + r.getContent() + "," + + r.getBookId() + "," + + description + "\n"; + + } + + text = text.substring(0, text.length()-2); // cut the last 2 chars, which are "\n" here + + out.println(text); + out.close(); + + logger.info("The file " + fileName + " has been saved correctly."); + + + } + + + private static String getLGMapUrl(LGFullTextSearchFile file) throws IOException{ + String lgmap = PropertiesUtils.getPropValue("lgmap") + "&file=" + file.getUserId().toString() + "_" + file.getFileName() + ".csv&name=" + file.getSearchTerms(); + + return lgmap; + } + + public static void saveFullTextSearchFileAsHtml(LGFullTextSearchFile file, Long userId, List list) throws Exception{ + + String absolutePath = PropertiesUtils.getPropValue("ftsearch_root") + "/html/" + userId.toString() + "/"; + String fileName = file.getFileName() + ".html"; + + File folder = new File(absolutePath); + folder.mkdirs(); + + logger.info("Trying to save file " + absolutePath + fileName + "."); + + PrintWriter out = new PrintWriter(absolutePath + fileName); + + String text = new String(); + String header = new String(); + text += ""; + + String root_server = PropertiesUtils.getPropValue("root_server"); + + header = "" + + "" + + + "" + + "" + + "" + + + ""; + + text += header; + text += "" + + "
Table name: " + file.getFileName() + "
" + + "
" + list.size() + " result(s) in the table." + + "
searching by keywords (possibly with filters): " + '"' + "" + file.getSearchTerms() + "" + '"' + "
" + + "
view on LGMap
" + + "
" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + for (DBContents r : list) { + + DBBook book = r.getSection().getBook(); + + text += "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + } + + text += "
#book idbook namelevel1level2periodsection namepagecontent
" + r.getInx() + "" + r.getBookId() + "" + book.getName() + "" + book.getLevel1() + "" + book.getLevel2() + "" + book.getPeriod() + "" + r.getSection().getName() + "" + r.getPage() + "" + r.getContent() + "
"; + + out.println(text); + out.close(); + + logger.info("The file " + fileName + " has been saved correctly."); + + + } + + + public static String saveFile(LGBranch branch, LGFile file, Date date, Long userId) throws Exception{ String absolutePath = getRootPath() + branch.getSectionId() + "/"; @@ -82,6 +219,17 @@ System.out.println("Loading: " + absolutePath); return new File(absolutePath); } + + + public static String getFullTextSearchHtmlFileText(LGFullTextSearchFile file) throws Exception { + + String absolutePath = PropertiesUtils.getPropValue("ftsearch_root") + "/html/" + file.getUserId().toString() + "/" + file.getFileName() + ".html"; + System.out.println("Loading: " + absolutePath); + + byte[] encoded = Files.readAllBytes(Paths.get(absolutePath)); + return new String(encoded, "UTF8"); + + } } diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByAdminType.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByAdminType.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,16 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; + + +public class SortContentByAdminType implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getSection() == null || o2.getSection() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getSection().getBook().getAdmin_type().compareTo(o2.getSection().getBook().getAdmin_type()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByBookId.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByBookId.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,15 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; + +public class SortContentByBookId implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getSection() == null || o2.getSection() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getSection().getBook().getId().compareTo(o2.getSection().getBook().getId()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByBookName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByBookName.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,16 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; +import de.mpiwg.gazetteer.db.DBSection; + +public class SortContentByBookName implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getSection() == null || o2.getSection() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getSection().getBook().getName().compareTo(o2.getSection().getBook().getName()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByDynasty.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByDynasty.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,16 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; +import de.mpiwg.gazetteer.db.DBSection; + +public class SortContentByDynasty implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getSection() == null || o2.getSection() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getSection().getBook().getDynasty().compareTo(o2.getSection().getBook().getDynasty()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentById.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentById.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,12 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; + +public class SortContentById implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + return o1.getId().compareTo(o2.getId()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByInx.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByInx.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,16 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; + + +public class SortContentByInx implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getInx() == null || o2.getInx() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getInx().compareTo(o2.getInx()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByLevel1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByLevel1.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,16 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; +import de.mpiwg.gazetteer.db.DBSection; + +public class SortContentByLevel1 implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getSection() == null || o2.getSection() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getSection().getBook().getLevel1().compareTo(o2.getSection().getBook().getLevel1()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByLevel2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByLevel2.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,15 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; + +public class SortContentByLevel2 implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getSection() == null || o2.getSection() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getSection().getBook().getLevel2().compareTo(o2.getSection().getBook().getLevel2()); + } +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByPeriod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByPeriod.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,16 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; + +public class SortContentByPeriod implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getSection() == null || o2.getSection() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getSection().getBook().getPeriod().compareTo(o2.getSection().getBook().getPeriod()); + } + +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/fullTextSearch/SortContentByStartPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/fullTextSearch/SortContentByStartPage.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,17 @@ +package de.mpiwg.web.fullTextSearch; + +import java.util.Comparator; + +import de.mpiwg.gazetteer.db.DBContents; + +public class SortContentByStartPage implements Comparator{ + + public int compare(DBContents o1, DBContents o2) { + if(o1.getSection() == null || o2.getSection() == null){ + return o1.getId().compareTo(o2.getId()); + } + return o1.getSection().getStart_page().compareTo(o2.getSection().getStart_page()); + } + + +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,662 @@ +package de.mpiwg.web.jsp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; + +import de.mpiwg.gazetteer.bo.LGBranch; +import de.mpiwg.gazetteer.bo.LGFile; +import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; +import de.mpiwg.gazetteer.dataverse.bo.VDCUser; +import de.mpiwg.gazetteer.db.DBContents; +import de.mpiwg.gazetteer.db.DBSection; +import de.mpiwg.gazetteer.utils.DBService; +import de.mpiwg.gazetteer.utils.DataProvider; +import de.mpiwg.web.fullTextSearch.SortContentByAdminType; +import de.mpiwg.web.fullTextSearch.SortContentByBookId; +import de.mpiwg.web.fullTextSearch.SortContentByBookName; +import de.mpiwg.web.fullTextSearch.SortContentByDynasty; +import de.mpiwg.web.fullTextSearch.SortContentById; +import de.mpiwg.web.fullTextSearch.SortContentByInx; +import de.mpiwg.web.fullTextSearch.SortContentByLevel1; +import de.mpiwg.web.fullTextSearch.SortContentByLevel2; +import de.mpiwg.web.fullTextSearch.SortContentByPeriod; +import de.mpiwg.web.fullTextSearch.SortContentByStartPage; +import de.mpiwg.web.search.SortSectionByAdminType; +import de.mpiwg.web.search.SortSectionByAuthor; +import de.mpiwg.web.search.SortSectionByBookId; +import de.mpiwg.web.search.SortSectionByBookName; +import de.mpiwg.web.search.SortSectionByDynasty; +import de.mpiwg.web.search.SortSectionByEdition; +import de.mpiwg.web.search.SortSectionById; +import de.mpiwg.web.search.SortSectionByLevel1; +import de.mpiwg.web.search.SortSectionByPeriod; +import de.mpiwg.web.search.SortSectionByStartPage; +import de.mpiwg.web.search.SortSectionByVolume; + +public class FullTextSearchPage extends AbstractJSPPage{ + + private static Logger logger = Logger.getLogger(FullTextSearchPage.class); + + public static String bean = "fullTextSearchBean"; + public static String page = "pages/fullTextSearch.jsp"; + + + private List completeList; + private List filteredList; + private List displayList; + + private String searchTerm = new String(); + + private String dynastyFilter = new String(); + private String adminTypeFilter = new String(); + private String level1Filter = new String(); + + private DataPaginator paginator = new DataPaginator(); + private String searchMessage; + private String filteringMessage; + + private String bookIdFilter = new String(); + private String bookNameFilter = new String(); + private String level2Filter = new String(); + private String periodFilter = new String(); + private String sectionNameFilter = new String(); + + + private Map> filesMap; + private List fileList = null; + private String fileName = new String(); + + private String focusedContentId = new String(); + + @Override + public void init(){ + super.init(); + } + + public void loadParameters(HttpServletRequest request, HttpServletResponse response){ + this.request = request; + this.response = response; + + this.searchTerm = getParameter("searchTerm"); + + this.bookIdFilter = getParameter("bookIdFilter"); + this.bookNameFilter = getParameter("bookNameFilter"); + + this.dynastyFilter = getParameter("dynastyFilter"); + this.adminTypeFilter = getParameter("adminTypeFilter"); + this.level1Filter = getParameter("level1Filter"); + this.level2Filter = getParameter("level2Filter"); + + this.periodFilter = getParameter("periodFilter"); + this.sectionNameFilter = getParameter("sectionNameFilter"); + + this.fileName = getParameter("fileName"); + + this.focusedContentId = getParameter("focusedContentId"); + + } + + + public void search(){ + logger.debug("Searching: " + this.searchTerm); + + this.dynastyFilter = new String(); + this.level1Filter = new String(); + this.adminTypeFilter = new String(); + + if(StringUtils.isNotEmpty(this.searchTerm)){ + try { + List terms = splitTerms(); + System.out.println("Full Text Search: " + terms.toString()); + + this.completeList = DBService.searchFullText(terms); + + if (this.completeList != null ){ + Collections.sort(this.completeList); + filter(); + } + + } catch (Exception e) { + internalError(e); + } + } + } + + + public void forceLoadFileList(){ + logger.debug("forceLoadFileList"); + logger.debug(this.getSearchTerm()); + + if(getSessionBean().getUser() != null){ + //logger.debug("userId="+ getSessionBean().getUser().getId()); + + // set FileList for the user + DataProvider.getInstance().setFullTextSearchFileMap(null); // set fullTextSearchFileMap to null, to force reload + this.setFileList(DataProvider.getInstance().getSearchFileList4User(getSessionBean().getUser().getId())); + } + + } + + + + public void save() { + logger.debug("saving table..."); + logger.debug(this.getFileName() + ", " + this.getSearchTerm() + ", userId= "+ getSessionBean().getUser().getId()); + + //logger.debug(this.getFilteredList()); + + if (StringUtils.equals(this.getFileName(), "") ) { + addMsg("Save failed. Table name cannot be empty."); + return; + } + + + /* Update db table `LGFullTextSearchFile`: new row with userId, file name, ...*/ + + Long userId = getSessionBean().getUser().getId(); + + LGFullTextSearchFile file; + try { + // save only those contents that are not removed + List cleanList = new ArrayList(); + for (DBContents t: this.getFilteredList()) { + if (!t.isRemoved()) { + cleanList.add(t); + } + } + + file = DataProvider.getInstance().saveLGFullTextSearchFile(cleanList, userId, this.getFileName(), this.getSearchTerm()); + addMsg("The table has been saved!"); + + logger.debug(file.getInfo()); + + } catch (Exception e) { + addMsg("Saving fails!"); + e.printStackTrace(); + internalError(e); + } + + // update FileList + DataProvider.getInstance().setFullTextSearchFileMap(null); // set fullTextSearchFileMap to null, to force reload + this.setFileList(DataProvider.getInstance().getSearchFileList4User(getSessionBean().getUser().getId())); + } + + + + public void filter(){ + this.filteredList = new ArrayList(); + for(DBContents content : this.completeList){ + if(!this.filteredList.contains(content)){ + + if( (StringUtils.isEmpty(dynastyFilter) || StringUtils.startsWith(content.getSection().getBook().getDynasty(), dynastyFilter)) && + (StringUtils.isEmpty(level1Filter) || StringUtils.startsWith(content.getSection().getBook().getLevel1(), level1Filter)) && + (StringUtils.isEmpty(level2Filter) || StringUtils.startsWith(content.getSection().getBook().getLevel2(), level2Filter)) && + (StringUtils.isEmpty(adminTypeFilter) || StringUtils.startsWith(content.getSection().getBook().getAdmin_type(), adminTypeFilter)) && + (StringUtils.isEmpty(bookIdFilter) || StringUtils.startsWith(content.getBookId(), bookIdFilter)) && + (StringUtils.isEmpty(bookNameFilter) || StringUtils.startsWith(content.getSection().getBook().getName(), bookNameFilter)) && + (StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(content.getSection().getName(), sectionNameFilter)) + + ){ + this.filteredList.add(content); + } + } + } + + if(completeList.size() > 0){ + this.searchMessage = completeList.size() + " section(s) found for the term(s): " + this.searchTerm; + this.filteringMessage = this.filteredList.size() + " section(s) listed after the filtering"; + + this.paginator.setCurrentPage(0); + this.paginator.resetNumberOfPages(filteredList.size()); + + }else{ + this.searchMessage = "No sections found for the term(s): " + this.searchTerm; + this.filteredList = null; + this.filteringMessage = ""; + + this.paginator.setCurrentPage(0); + this.paginator.resetNumberOfPages(0); + } + + this.updateCurrentSections(); + + } + + + private void updateCurrentSections() { + /* + this.paginator.initCount(); + int startRecord = this.paginator.getCurrentPage() + * this.paginator.getItemsPerPage(); + if(this.paginator.getNumberOfPages() == 0){ + this.displayList = new ArrayList(); + }else if((this.paginator.getCurrentPage() + 1) == this.paginator.getNumberOfPages()){ + int mod = this.filteredList.size() % paginator.getItemsPerPage(); + if(mod == 0){ + this.displayList = filteredList.subList(startRecord, startRecord + this.paginator.getItemsPerPage()); + }else{ + this.displayList = filteredList.subList(startRecord, startRecord + mod); + } + + }else{ + this.displayList = filteredList.subList(startRecord, startRecord + this.paginator.getItemsPerPage()); + } + + for(DBContents content : this.displayList){ + //section.setBranches(this.branchesMap.get(section.getId())); + } + */ + } + + + private List splitTerms(){ + List rs = new ArrayList(); + + String[] array = this.searchTerm.split(","); + + for(String tmp : array){ + tmp = tmp.replace(" ", ""); + if(StringUtils.isNotEmpty(tmp)){ + rs.add(tmp); + } + } + return rs; + } + + public List suggestDynasty(String term, int limit){ + List list = new ArrayList(); + for(DBContents content : this.completeList){ + String dynasty = content.getSection().getBook().getDynasty(); + if(!list.contains(dynasty) && dynasty.startsWith(term)){ + list.add(dynasty); + } + if(limit == list.size()){ + break; + } + } + return list; + } + + public List suggestLevel1(String term, int limit){ + List list = new ArrayList(); + for(DBContents content : this.completeList){ + String level1 = content.getSection().getBook().getLevel1(); + if(!list.contains(level1) && level1.startsWith(term)){ + list.add(level1); + } + if(limit == list.size()){ + break; + } + } + return list; + } + + public List suggestAdminType(String term, int limit){ + List list = new ArrayList(); + for(DBContents content : this.completeList){ + String adminType = content.getSection().getBook().getAdmin_type(); + if(!list.contains(adminType) && adminType.startsWith(term)){ + list.add(adminType); + } + if(limit == list.size()){ + break; + } + } + return list; + } + + + + public List getFileList() { + return fileList; + } + + public void setFileList(List fileList) { + this.fileList = fileList; + } + + + + public List getCompleteList() { + return completeList; + } + + + public Map> getFilesMap() { + return filesMap; + } + + public void setFilesMap(Map> filesMap) { + this.filesMap = filesMap; + } + + public void setCompleteList(List completeList) { + this.completeList = completeList; + } + + + public String getSearchTerm() { + return searchTerm; + } + + + public void setSearchTerm(String searchTerm) { + this.searchTerm = searchTerm; + } + + public List getFilteredList() { + return filteredList; + } + + public void setFilteredList(List filteredList) { + this.filteredList = filteredList; + } + + + public List getDisplayList() { + return displayList; + } + + public void setDisplayList(List displayList) { + this.displayList = displayList; + } + + + public DataPaginator getPaginator() { + return paginator; + } + + public void setPaginator(DataPaginator paginator) { + this.paginator = paginator; + } + + public void firstPage() { + this.paginator.first(); + this.updateCurrentSections(); + } + + public void lastPage() { + this.paginator.last(); + this.updateCurrentSections(); + } + + public void fastForward() { + this.paginator.fastForward(); + this.updateCurrentSections(); + } + + public void fastRewind() { + this.paginator.fastRewind(); + this.updateCurrentSections(); + } + + public void previousPage() { + this.paginator.previous(); + this.updateCurrentSections(); + } + + public void nextPage() { + this.paginator.next(); + this.updateCurrentSections(); + } + + public String getSearchMessage() { + return searchMessage; + } + + public void setSearchMessage(String searchMessage) { + this.searchMessage = searchMessage; + } + + public String getFilteringMessage() { + return filteringMessage; + } + + public void setFilteringMessage(String filteringMessage) { + this.filteringMessage = filteringMessage; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public String getDynastyFilter() { + return dynastyFilter; + } + + public void setDynastyFilter(String dynastyFilter) { + this.dynastyFilter = dynastyFilter; + } + + public String getAdminTypeFilter() { + return adminTypeFilter; + } + + public void setAdminTypeFilter(String adminTypeFilter) { + this.adminTypeFilter = adminTypeFilter; + } + + public String getLevel1Filter() { + return level1Filter; + } + + public void setLevel1Filter(String level1Filter) { + this.level1Filter = level1Filter; + } + + + + /////// Sorting + + public String getFocusedContentId() { + return focusedContentId; + } + + public void setFocusedContentId(String focusedContentId) { + this.focusedContentId = focusedContentId; + } + + public String getBookIdFilter() { + return bookIdFilter; + } + + public void setBookIdFilter(String bookIdFilter) { + this.bookIdFilter = bookIdFilter; + } + + public String getBookNameFilter() { + return bookNameFilter; + } + + public void setBookNameFilter(String bookNameFilter) { + this.bookNameFilter = bookNameFilter; + } + + public String getLevel2Filter() { + return level2Filter; + } + + public void setLevel2Filter(String level2Filter) { + this.level2Filter = level2Filter; + } + + public String getPeriodFilter() { + return periodFilter; + } + + public void setPeriodFilter(String periodFilter) { + this.periodFilter = periodFilter; + } + + public String getSectionNameFilter() { + return sectionNameFilter; + } + + public void setSectionNameFilter(String sectionNameFilter) { + this.sectionNameFilter = sectionNameFilter; + } + + public void sortByBookNameUp(){ + Collections.sort(this.completeList, new SortContentByBookName()); + filter(); + } + + public void sortByBookNameDown(){ + Collections.sort(this.completeList, new SortContentByBookName()); + Collections.reverse(this.completeList); + filter(); + } + + public void sortBySectionNameUp(){ + Collections.sort(this.completeList); + filter(); + } + + public void sortBySectionNameDown(){ + Collections.sort(this.completeList); + Collections.reverse(this.completeList); + filter(); + } + + + + public void sortByPeriodUp(){ + Collections.sort(this.completeList, new SortContentByPeriod()); + filter(); + } + + public void sortByPeriodDown(){ + Collections.sort(this.completeList, new SortContentByPeriod()); + Collections.reverse(this.completeList); + filter(); + } + + + + public void sortByIdUp(){ + Collections.sort(this.completeList, new SortContentById()); + this.filter(); + } + + public void sortByIdDown(){ + Collections.sort(this.completeList, new SortContentById()); + Collections.reverse(completeList); + this.filter(); + } + + + public void sortByDynastyUp(){ + Collections.sort(this.completeList, new SortContentByDynasty()); + filter(); + } + + public void sortByDynastyDown(){ + Collections.sort(this.completeList, new SortContentByDynasty()); + Collections.reverse(completeList); + filter(); + } + + public void sortByBookIdUp(){ + Collections.sort(this.completeList, new SortContentByBookId()); + filter(); + } + + public void sortByBookIdDown(){ + Collections.sort(this.completeList, new SortContentByBookId()); + Collections.reverse(completeList); + filter(); + } + + public void sortByLevel1Up(){ + Collections.sort(this.completeList, new SortContentByLevel1()); + filter(); + } + + public void sortByLevel1Down(){ + Collections.sort(this.completeList, new SortContentByLevel1()); + Collections.reverse(completeList); + filter(); + } + public void sortByLevel2Up(){ + Collections.sort(this.completeList, new SortContentByLevel2()); + filter(); + } + + public void sortByLevel2Down(){ + Collections.sort(this.completeList, new SortContentByLevel2()); + Collections.reverse(completeList); + filter(); + } + + public void sortByAdminTypeUp(){ + Collections.sort(this.completeList, new SortContentByAdminType()); + filter(); + } + + public void sortByAdminTypeDown(){ + Collections.sort(this.completeList, new SortContentByAdminType()); + Collections.reverse(completeList); + filter(); + } + + public void sortByStartPageUp(){ + Collections.sort(this.completeList, new SortContentByStartPage()); + filter(); + } + + public void sortByStartPageDown(){ + Collections.sort(this.completeList, new SortContentByStartPage()); + Collections.reverse(completeList); + filter(); + } + public void sortByInxUp(){ + Collections.sort(this.completeList, new SortContentByInx()); + filter(); + } + + public void sortByInxDown(){ + Collections.sort(this.completeList, new SortContentByInx()); + Collections.reverse(completeList); + filter(); + } + + public void removeFocusedContent(boolean status) { + + // TODO set isRemove for the content with id=this.focusedContentId + // status is true: remove; + // status is false: recover (unremove) + + for (DBContents content: this.completeList) { + if (StringUtils.equals(content.getId().toString(), this.focusedContentId)) { + + //if(content.getId().toString() == this.focusedContentId) { + content.setRemoved(status); + logger.debug("set remove content id=" + content.getId().toString()); + break; + } + } + + + + Collections.sort(this.completeList); + filter(); + } + + + + + +} diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/jsp/JSPProxy.java --- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Fri Dec 04 14:28:44 2015 +0100 @@ -60,8 +60,8 @@ } return CreateFilePage.page; - - }else if(StringUtils.equals(bean, HomePage.bean)){ + + } else if(StringUtils.equals(bean, HomePage.bean)){ getSessionBean().getHomePage().loadParameters(request, response); @@ -141,7 +141,6 @@ getSessionBean().logout(); } - //return BooksPage.page; // TMP: make the default page after login to be "Books" page for TOC editing task return "pages/home.jsp"; }else if(StringUtils.equals(bean, SearchPage.bean)){ @@ -209,6 +208,83 @@ return SearchPage.page; + } else if(StringUtils.equals(bean, FullTextSearchPage.bean)){ + getSessionBean().getFullTextSearchPage().loadParameters(request, response); + + if(StringUtils.equals(action, "search")){ + getSessionBean().getFullTextSearchPage().search(); + } else if(StringUtils.equals(action, "filter")){ + getSessionBean().getFullTextSearchPage().filter(); + } else if(StringUtils.equals(action, "save")){ + getSessionBean().getFullTextSearchPage().save(); + } else if(StringUtils.equals(action, "removeFocusedContent")){ + getSessionBean().getFullTextSearchPage().removeFocusedContent(true); + } else if(StringUtils.equals(action, "recoverFocusedContent")){ + getSessionBean().getFullTextSearchPage().removeFocusedContent(false); + + + //PAGINATOR + } else if(StringUtils.equals(action, "firstPage")){ + getSessionBean().getFullTextSearchPage().firstPage(); + } else if(StringUtils.equals(action, "fastRewind")){ + getSessionBean().getFullTextSearchPage().fastRewind(); + } else if(StringUtils.equals(action, "previousPage")){ + getSessionBean().getFullTextSearchPage().previousPage(); + } else if(StringUtils.equals(action, "nextPage")){ + getSessionBean().getFullTextSearchPage().nextPage(); + } else if(StringUtils.equals(action, "fastForward")){ + getSessionBean().getFullTextSearchPage().fastForward(); + } else if(StringUtils.equals(action, "lastPage")){ + getSessionBean().getFullTextSearchPage().lastPage(); + + //SORTING + } else if(StringUtils.equals(action, "sortByInxUp")){ + getSessionBean().getFullTextSearchPage().sortByInxUp(); + } else if(StringUtils.equals(action, "sortByInxDown")){ + getSessionBean().getFullTextSearchPage().sortByInxDown(); + } else if(StringUtils.equals(action, "sortByBookIdUp")){ + getSessionBean().getFullTextSearchPage().sortByBookIdUp(); + } else if(StringUtils.equals(action, "sortByBookIdDown")){ + getSessionBean().getFullTextSearchPage().sortByBookIdDown(); + } else if(StringUtils.equals(action, "sortByBookNameUp")){ + getSessionBean().getFullTextSearchPage().sortByBookNameUp(); + } else if(StringUtils.equals(action, "sortByBookNameDown")){ + getSessionBean().getFullTextSearchPage().sortByBookNameDown(); + } else if(StringUtils.equals(action, "sortByDynastyUp")){ + getSessionBean().getFullTextSearchPage().sortByDynastyUp(); + } else if(StringUtils.equals(action, "sortByDynastyDown")){ + getSessionBean().getFullTextSearchPage().sortByDynastyDown(); + } else if(StringUtils.equals(action, "sortByPeriodUp")){ + getSessionBean().getFullTextSearchPage().sortByPeriodUp(); + } else if(StringUtils.equals(action, "sortByPeriodDown")){ + getSessionBean().getFullTextSearchPage().sortByPeriodDown(); + } else if(StringUtils.equals(action, "sortBySectionNameUp")){ + getSessionBean().getFullTextSearchPage().sortBySectionNameUp(); + } else if(StringUtils.equals(action, "sortBySectionNameDown")){ + getSessionBean().getFullTextSearchPage().sortBySectionNameDown(); + + } else if(StringUtils.equals(action, "sortByLevel1Up")){ + getSessionBean().getFullTextSearchPage().sortByLevel1Up(); + } else if(StringUtils.equals(action, "sortByLevel1Down")){ + getSessionBean().getFullTextSearchPage().sortByLevel1Down(); + } else if(StringUtils.equals(action, "sortByLevel2Up")){ + getSessionBean().getFullTextSearchPage().sortByLevel2Up(); + } else if(StringUtils.equals(action, "sortByLevel2Down")){ + getSessionBean().getFullTextSearchPage().sortByLevel2Down(); + } else if(StringUtils.equals(action, "sortByAdminTypeUp")){ + getSessionBean().getFullTextSearchPage().sortByAdminTypeUp(); + } else if(StringUtils.equals(action, "sortByAdminTypeDown")){ + getSessionBean().getFullTextSearchPage().sortByAdminTypeDown(); + + } else if(StringUtils.equals(action, "sortByStartPageUp")){ + getSessionBean().getFullTextSearchPage().sortByStartPageUp(); + } else if(StringUtils.equals(action, "sortByStartPageDown")){ + getSessionBean().getFullTextSearchPage().sortByStartPageDown(); + } + + + return FullTextSearchPage.page; + } else if(StringUtils.equals(bean, BooksPage.bean)){ getSessionBean().getBooksPage().loadParameters(request, response); diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/jsp/SearchPage.java --- a/src/main/java/de/mpiwg/web/jsp/SearchPage.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/web/jsp/SearchPage.java Fri Dec 04 14:28:44 2015 +0100 @@ -35,10 +35,10 @@ public static String bean = "searchBean"; public static String page = "pages/search.jsp"; + private static Integer SEARCH_IN_SECTION_NAME = 0; private static Integer SEARCH_IN_BOOK_NAME = 1; - private static Integer SEARCH_FULL_TEXT = 2; - + //private static Integer SEARCH_FULL_TEXT = 2; private Map> branchesMap; @@ -57,6 +57,8 @@ private String searchMessage; private String filteringMessage; + + @Override public void init(){ super.init(); @@ -74,7 +76,7 @@ } - public void search(){ + public void search(){ logger.debug("Searching: " + this.searchTerm); this.dynastyFilter = new String(); @@ -87,20 +89,21 @@ List terms = splitTerms(); if(SEARCH_IN_SECTION_NAME.equals(this.searchIn)){ - System.out.println("Search in Section Name"); + System.out.println("Section Search in Section Name"); this.completeSectionList = DBService.searchSection(terms); + }else if(SEARCH_IN_BOOK_NAME.equals(this.searchIn)){ - System.out.println("Search in Book Name"); + System.out.println("Section Search in Book Name"); this.completeSectionList = DBService.searchBook(terms, "name"); - }/*else if(SEARCH_FULL_TEXT.equals(this.searchIn)){ - System.out.println("Search Full Text"); - DBService.searchFullText(terms); - }*/ + + } /*else if (SEARCH_FULL_TEXT.equals(this.searchIn)) { + System.out.println("Full Text Search"); + DBService.searchFullText(terms); + } + */ Collections.sort(this.completeSectionList); - filter(); - } catch (Exception e) { internalError(e); @@ -108,11 +111,11 @@ } } - public void filter(){ + public void filter(){ this.filteredSectionList = new ArrayList(); for(DBSection section : this.completeSectionList){ if(!this.filteredSectionList.contains(section)){ - + if( (StringUtils.isEmpty(dynastyFilter) || StringUtils.startsWith(section.getBook().getDynasty(), dynastyFilter)) && (StringUtils.isEmpty(level1Filter) || StringUtils.startsWith(section.getBook().getLevel1(), level1Filter)) && (StringUtils.isEmpty(adminTypeFilter) || StringUtils.startsWith(section.getBook().getAdmin_type(), adminTypeFilter)) @@ -121,17 +124,25 @@ } } } - + if(completeSectionList.size() > 0){ this.searchMessage = completeSectionList.size() + " section(s) found for the term(s): " + this.searchTerm; this.filteringMessage = this.filteredSectionList.size() + " section(s) listed after the filtering"; + this.paginator.setCurrentPage(0); this.paginator.resetNumberOfPages(filteredSectionList.size()); - this.updateCurrentSections(); + }else{ this.searchMessage = "No sections found for the term(s): " + this.searchTerm; this.filteredSectionList = null; + this.filteringMessage = ""; + + this.paginator.setCurrentPage(0); + this.paginator.resetNumberOfPages(0); } + + this.updateCurrentSections(); + } private void updateCurrentSections() { diff -r 8b7a204fa929 -r 37840afb7b80 src/main/java/de/mpiwg/web/jsp/SessionBean.java --- a/src/main/java/de/mpiwg/web/jsp/SessionBean.java Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/java/de/mpiwg/web/jsp/SessionBean.java Fri Dec 04 14:28:44 2015 +0100 @@ -32,7 +32,7 @@ private BranchPage branchPage = new BranchPage(); private BooksPage booksPage = new BooksPage(); - + private FullTextSearchPage fullTextSearchPage = new FullTextSearchPage(); public SessionBean(){ logger.info("\n\n### SessionBean #####\n\n"); @@ -180,6 +180,16 @@ public void setBranchPage(BranchPage branchPage) { this.branchPage = branchPage; } - - + + + public FullTextSearchPage getFullTextSearchPage() { + return fullTextSearchPage; + } + + + public void setFullTextSearchPage(FullTextSearchPage fullTextSearchPage) { + this.fullTextSearchPage = fullTextSearchPage; + } + + } diff -r 8b7a204fa929 -r 37840afb7b80 src/main/resources/config.properties --- a/src/main/resources/config.properties Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/resources/config.properties Fri Dec 04 14:28:44 2015 +0100 @@ -1,5 +1,7 @@ db_gazetter_name=Gazetteer files_root=/gazetteer-server/data +ftsearch_root=/gazetteer-server/ftsearch-data + #Local db_gazetter_username=root @@ -11,6 +13,8 @@ toc_interface=http://localhost:1080/localgazetteers-dev/LGToc extraction_interface=http://localhost:1080/localgazetteers-dev/extraction-interface localgazetteers_dvId=185 +lgmap=http://localhost:1080/localgazetteers-dev/LGMap/map.php?mode=1 +lgmap_datasets=/Applications/MAMP/htdocs/localgazetteers-dev/LGMap/datasets # Production one: #localgazetteers-dev -> localgazetteers @@ -22,6 +26,9 @@ #root_server=http://localgazetteers.mpiwg-berlin.mpg.de/LGServices #toc_interface=http://localgazetteers.mpiwg-berlin.mpg.de/LGToc #extraction_interface=http://localgazetteers.mpiwg-berlin.mpg.de/extraction-interface +#lgmap=http://localgazetteers.mpiwg-berlin.mpg.de/LGMap/map.php?mode=1 +#lgmap_datasets=/var/www/html/LGMap/datasets + # Development one: #localgazetteers -> localgazetteers-test @@ -34,3 +41,5 @@ #toc_interface=http://localgazetteers-test.mpiwg-berlin.mpg.de/LGToc #extraction_interface=http://localgazetteers-test.mpiwg-berlin.mpg.de/extraction-interface #localgazetteers_dvId=2 +#lgmap=http://localgazetteers-test.mpiwg-berlin.mpg.de/LGMap/map.php?mode=1 +#lgmap_datasets=/var/www/html/LGMap/datasets diff -r 8b7a204fa929 -r 37840afb7b80 src/main/resources/hibernate.cfg.xml --- a/src/main/resources/hibernate.cfg.xml Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/resources/hibernate.cfg.xml Fri Dec 04 14:28:44 2015 +0100 @@ -36,7 +36,8 @@ --> - + + diff -r 8b7a204fa929 -r 37840afb7b80 src/main/webapp/componentes/paginator.jsp --- a/src/main/webapp/componentes/paginator.jsp Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/webapp/componentes/paginator.jsp Fri Dec 04 14:28:44 2015 +0100 @@ -31,6 +31,9 @@ <% } else if (formName.equals("searchForm")) { %> <%=sessionBean.getSearchPage().getPaginator().getRecordStatus() %> + <% } else if (formName.equals("fullTextSearchForm")) { %> + <%=sessionBean.getFullTextSearchPage().getPaginator().getRecordStatus() %> + <% } %> diff -r 8b7a204fa929 -r 37840afb7b80 src/main/webapp/componentes/template.jsp --- a/src/main/webapp/componentes/template.jsp Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/webapp/componentes/template.jsp Fri Dec 04 14:28:44 2015 +0100 @@ -5,8 +5,7 @@
@@ -19,12 +18,21 @@ <% sessionBean.resetMsgList(); %> <% } %> + + + +
Loading...
+ -
@@ -53,7 +61,7 @@ Logged in as: <%=sessionBean.getUser().getUserName() %> | - Go To Dataverse + Go To LGDataverse <% } %> @@ -64,7 +72,13 @@ \ No newline at end of file +
+ + + diff -r 8b7a204fa929 -r 37840afb7b80 src/main/webapp/pages/fullTextSearch.jsp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/webapp/pages/fullTextSearch.jsp Fri Dec 04 14:28:44 2015 +0100 @@ -0,0 +1,604 @@ +<%@page import="de.mpiwg.gazetteer.bo.LGBranch"%> +<%@page import="org.apache.commons.lang.StringUtils"%> +<%@page import="de.mpiwg.gazetteer.db.DBSection"%> +<%@page import="de.mpiwg.gazetteer.db.DBContents"%> +<%@page import="de.mpiwg.gazetteer.bo.LGFullTextSearchFile"%> + + +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + + + + + + + + + + + + + + +
+ +
+ + <% if(sessionBean.getUser() == null) { %> + + <% } else { + + if (sessionBean.getFullTextSearchPage().getFileList() == null){ + sessionBean.getFullTextSearchPage().loadParameters(request, response); + sessionBean.getFullTextSearchPage().forceLoadFileList(); + } + + %> + +
+
+ + + + + + +
+ + + + +
+
+ +
+ +
+ + + + + + + + <% for (LGFullTextSearchFile aFile : sessionBean.getFullTextSearchPage().getFileList() ){%> + + + + + + + <% } %> + +
Table namehtml
<%= aFile.getFileName() %> + + Show text in html + +
+ + +
+ + +
+ + + + + + + + + + + + + + +
+ + + +
+ + +
+ + + + <% + if (sessionBean.getFullTextSearchPage().getCompleteList() != null) { + %> + + + +
+ + + + + + + + + + + + + + + + + + + + + <% + for (DBContents content : sessionBean.getFullTextSearchPage().getFilteredList() ) { + %> + + <% if ( content.isRemoved() ) { %> + + <% } else { %> + + <% } %> + + + + + + + + + + + + + + + + + <% + } + %> + + +
+ + + + + +
+ + + +
+ +
+ +
+
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + + + + + +
+ + + +
+ +
+ +
+
+ + + +
+
+ + + + + +
+ + + +
+ +
+ +
+
+
+ + + + + +
+ + + +
+ +
+ +
+
+ +
<%=content.getInx() %><%=content.getSection().getBook().getId() %><%=content.getSection().getBook().getName()%><%=content.getSection().getBook().getLevel1()%><%=content.getSection().getBook().getLevel2()%><%=content.getSection().getBook().getDynasty()%><%=content.getSection().getBook().getPeriod()%><%=content.getSection().getBook().getAdmin_type() %><%=content.getSection().getName() %><%=content.getSection().getPages()%><%=content.getPage() %><%=content.getContent()%> + <% if ( content.isRemoved() ) { %> + + + + <% } else { %> + + + + <% } %> + + + +
+ + + <% + } + %> + +
+ + +
+ + <% } %> + +
+ + + diff -r 8b7a204fa929 -r 37840afb7b80 src/main/webapp/pages/home.jsp --- a/src/main/webapp/pages/home.jsp Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/webapp/pages/home.jsp Fri Dec 04 14:28:44 2015 +0100 @@ -101,7 +101,7 @@ - + - + - + - + - + - + - + - + - + @@ -171,7 +173,7 @@ -
@@ -283,7 +285,7 @@ - + - + - + = 0) { + text = text.substring(0,index) + "" + text.substring(index, index+keywordsArray[j].length) + "" + text.substring(index+keywordsArray[j].length); + content[i].innerHTML = text; + } + }; + + }; +} \ No newline at end of file diff -r 8b7a204fa929 -r 37840afb7b80 src/main/webapp/resources/js/general.js --- a/src/main/webapp/resources/js/general.js Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/webapp/resources/js/general.js Fri Dec 04 14:28:44 2015 +0100 @@ -101,4 +101,5 @@ $(document).ready(function() { $('.double-scroll').doubleScroll(); + }); \ No newline at end of file diff -r 8b7a204fa929 -r 37840afb7b80 src/main/webapp/resources/js/proxyMethods.js --- a/src/main/webapp/resources/js/proxyMethods.js Fri Nov 20 15:37:04 2015 +0100 +++ b/src/main/webapp/resources/js/proxyMethods.js Fri Dec 04 14:28:44 2015 +0100 @@ -1,6 +1,7 @@ - function setAction(action, formName){ + $("#loading").show(); + var theForm = document.forms[formName]; var input = document.createElement('input'); input.type = 'hidden';