# HG changeset patch # User Zoe Hong # Date 1449504417 -3600 # Node ID 35ed4e650a539c11676cd833b13e559382b8cc15 # Parent 37840afb7b801f4534555ae62a98197975e7f7e8 bug fixed: full text search when section not found in section_index table. add paginator diff -r 37840afb7b80 -r 35ed4e650a53 src/main/java/de/mpiwg/gazetteer/db/DBBook.java --- a/src/main/java/de/mpiwg/gazetteer/db/DBBook.java Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBBook.java Mon Dec 07 17:06:57 2015 +0100 @@ -6,25 +6,25 @@ public class DBBook implements Comparable{ - private String id; - private String name; - private Integer line; - private String period; + private String id = ""; + private String name = ""; + private Integer line = 0; + private String period = ""; // - private String author; - private String edition; - private String volume; - private String dynasty; + private String author = ""; + private String edition = ""; + private String volume = ""; + private String dynasty = ""; private String level1 = ""; private String level2 = ""; - private String admin_type; - private String in_jibengujiku; + private String admin_type = ""; + private String in_jibengujiku = ""; - private Integer start_year; - private Integer end_year; - private String comments; - private String toc_correction; + private Integer start_year = 0; + private Integer end_year = 0; + private String comments = ""; + private String toc_correction = ""; diff -r 37840afb7b80 -r 35ed4e650a53 src/main/java/de/mpiwg/gazetteer/db/DBContents.java --- a/src/main/java/de/mpiwg/gazetteer/db/DBContents.java Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBContents.java Mon Dec 07 17:06:57 2015 +0100 @@ -12,11 +12,11 @@ private Long id; - private String bookId; - private Integer page; - private String content; + private String bookId = ""; + private Integer page = 0; + private String content = ""; - private DBSection section; // section already contain DBBook + private DBSection section = null; // section already contain DBBook private Integer inx = null; // local index for each row private DBCoordinatesBook coordinatesBook = null; @@ -31,12 +31,6 @@ 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); - } @@ -120,8 +114,10 @@ } + @Override public int compareTo(DBContents o) { - return this.getInx().compareTo(o.getInx()); + return this.getId().compareTo(o.getId()); } + } diff -r 37840afb7b80 -r 35ed4e650a53 src/main/java/de/mpiwg/gazetteer/db/DBSection.java --- a/src/main/java/de/mpiwg/gazetteer/db/DBSection.java Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBSection.java Mon Dec 07 17:06:57 2015 +0100 @@ -32,6 +32,14 @@ this.bookId = bookId; }*/ + public DBSection() { + this.name = "-"; + this.id = null; + this.bookId = null; + this.start_page = null; + this.end_page = null; + } + public DBSection(ResultSet rs) throws SQLException{ this.name = rs.getString("name"); this.id = rs.getLong("id"); diff -r 37840afb7b80 -r 35ed4e650a53 src/main/java/de/mpiwg/gazetteer/utils/DBService.java --- a/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java Mon Dec 07 17:06:57 2015 +0100 @@ -315,12 +315,21 @@ } rs.close(); + } catch (Exception e) { e.printStackTrace(); } finally { conn.close(); } + if (section == null) { + // section_index table is not completely correct by TOC_edit task (done by human), so query finds null in section + + section = new DBSection(); + section.setBookId(bookId); + DBBook book = getInstance().getBook(bookId); + section.setBook(book); + } return section; @@ -344,7 +353,7 @@ 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 + "WHERE " + condition;//+ "and (books_id='00204' or books_id='00219')"; // remove the books_id condition after debug //logger.debug("sql: " + sql); @@ -371,6 +380,17 @@ conn.close(); } + // setting section in each DBContents content + for (DBContents content : resultSet) { + // set this.section by bookId and page + content.setSection(DBService.getInstance().getSectionByBookIdAndPage(content.getBookId(), content.getPage())); + + // set this.coordinatesBook by bookId + content.setCoordinatesBook(DBService.getInstance().getCoordinatesBook(content.getBookId())); + } + + + long end = System.currentTimeMillis(); logger.debug("Time execution full text search [ms]: " + (end - start)); @@ -886,6 +906,9 @@ } + + // remove it + /* public static LGFullTextSearchFile getExistFullTextSearchFile(Long userId, String fileName) { //logger.info("getExistFullTextSearchFile: (userId,fileName)=" + userId + ","+fileName); List list = new ArrayList(); @@ -908,5 +931,5 @@ } } - + */ } diff -r 37840afb7b80 -r 35ed4e650a53 src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java --- a/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Mon Dec 07 17:06:57 2015 +0100 @@ -273,23 +273,12 @@ return list; } - public LGFullTextSearchFile saveLGFullTextSearchFile(List list, Long userId, String fileName, String searchTerms) throws Exception { + public LGFullTextSearchFile saveLGFullTextSearchFile(List list, Long userId, LGFullTextSearchFile searchFile) 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(); diff -r 37840afb7b80 -r 35ed4e650a53 src/main/java/de/mpiwg/gazetteer/utils/FileManager.java --- a/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java Mon Dec 07 17:06:57 2015 +0100 @@ -61,27 +61,29 @@ 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(); + for (DBContents c : list) { - 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"; - + if (c.getSection() != null && !c.isRemoved()){ + + DBBook book = c.getSection().getBook(); + + String description = book.getVolume() + "/" + book.getAuthor() + "/" + book.getEdition(); + + text += c.getCoordinatesBook().getPlace_name() + "," + + book.getLevel1() + "," + + book.getLevel2() + "," + + book.getName() + "," + + book.getPeriod() + "," + + book.getStart_year() + "," + + book.getEnd_year() + "," + + c.getCoordinatesBook().getX() + "," + + c.getCoordinatesBook().getY() + "," + + c.getPage() + "," + + c.getSection().getName() + "," + + c.getContent() + "," + + c.getBookId() + "," + + description + "\n"; + } } text = text.substring(0, text.length()-2); // cut the last 2 chars, which are "\n" here @@ -147,22 +149,24 @@ + "page" + "content" + ""; - for (DBContents r : list) { - - DBBook book = r.getSection().getBook(); - - text += "" + - "" + r.getInx() + "" + - "" + r.getBookId() + "" + - "" + book.getName() + "" + - "" + book.getLevel1() + "" + - "" + book.getLevel2() + "" + - "" + book.getPeriod() + "" + - "" + r.getSection().getName() + "" + - "" + r.getPage() + "" + - "" + r.getContent() + "" + - ""; + for (DBContents c : list) { + if ( c.getSection() != null && !c.isRemoved()){ + + DBBook book = c.getSection().getBook(); + + text += "" + + "" + c.getInx() + "" + + "" + c.getBookId() + "" + + "" + book.getName() + "" + + "" + book.getLevel1() + "" + + "" + book.getLevel2() + "" + + "" + book.getPeriod() + "" + + "" + c.getSection().getName() + "" + + "" + c.getPage() + "" + + "" + c.getContent() + "" + + ""; + } } text += ""; diff -r 37840afb7b80 -r 35ed4e650a53 src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java --- a/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java Mon Dec 07 17:06:57 2015 +0100 @@ -71,7 +71,6 @@ private String sectionNameFilter = new String(); - private Map> filesMap; private List fileList = null; private String fileName = new String(); @@ -166,15 +165,26 @@ 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); + + // check if record with (userId, fileName) already existed, update it; otherwise, create one + LGFullTextSearchFile searchFile = new LGFullTextSearchFile(); + + for (LGFullTextSearchFile aFile: this.getFileList()) { + if ( StringUtils.equals(aFile.getFileName(), fileName) && aFile.getUserId().equals(userId)) { + searchFile = aFile; + break; } } - file = DataProvider.getInstance().saveLGFullTextSearchFile(cleanList, userId, this.getFileName(), this.getSearchTerm()); + if (searchFile.isEmpty() ) { + searchFile.setFileName(fileName); + searchFile.setUserId(userId); + } + + searchFile.setSearchTerms(this.searchTerm); + + + file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getFilteredList(), userId, searchFile); addMsg("The table has been saved!"); logger.debug(file.getInfo()); @@ -210,7 +220,7 @@ } } } - + 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"; @@ -233,7 +243,7 @@ private void updateCurrentSections() { - /* + this.paginator.initCount(); int startRecord = this.paginator.getCurrentPage() * this.paginator.getItemsPerPage(); @@ -251,10 +261,6 @@ this.displayList = filteredList.subList(startRecord, startRecord + this.paginator.getItemsPerPage()); } - for(DBContents content : this.displayList){ - //section.setBranches(this.branchesMap.get(section.getId())); - } - */ } @@ -331,13 +337,6 @@ } - public Map> getFilesMap() { - return filesMap; - } - - public void setFilesMap(Map> filesMap) { - this.filesMap = filesMap; - } public void setCompleteList(List completeList) { this.completeList = completeList; @@ -635,24 +634,25 @@ public void removeFocusedContent(boolean status) { - // TODO set isRemove for the content with id=this.focusedContentId + // 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; } } - - + + int currentPage = this.getPaginator().getCurrentPage(); Collections.sort(this.completeList); filter(); + + this.getPaginator().setCurrentPage(currentPage); + this.updateCurrentSections(); } diff -r 37840afb7b80 -r 35ed4e650a53 src/main/java/de/mpiwg/web/jsp/JSPProxy.java --- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Mon Dec 07 17:06:57 2015 +0100 @@ -385,14 +385,13 @@ e.printStackTrace(); addMsg("There is an internal error: " + e.getLocalizedMessage()); - return BooksPage.page; - //return HomePage.page; + return HomePage.page; } - - - //Default Page - return BooksPage.page; + + //Default Page: + //return BooksPage.page; + return HomePage.page; //return "pages/search.jsp"; } diff -r 37840afb7b80 -r 35ed4e650a53 src/main/webapp/pages/fullTextSearch.jsp --- a/src/main/webapp/pages/fullTextSearch.jsp Fri Dec 04 14:28:44 2015 +0100 +++ b/src/main/webapp/pages/fullTextSearch.jsp Mon Dec 07 17:06:57 2015 +0100 @@ -207,11 +207,11 @@ if (sessionBean.getFullTextSearchPage().getCompleteList() != null) { %> - +
@@ -536,7 +536,7 @@ <% - for (DBContents content : sessionBean.getFullTextSearchPage().getFilteredList() ) { + for (DBContents content : sessionBean.getFullTextSearchPage().getDisplayList() ) { %> <% if ( content.isRemoved() ) { %> @@ -546,7 +546,7 @@ <% } %> - + @@ -588,11 +588,11 @@ %> - + diff -r 37840afb7b80 -r 35ed4e650a53 src/main/webapp/resources/.DS_Store Binary file src/main/webapp/resources/.DS_Store has changed
<%=content.getInx() %><%=content.getSection().getBook().getId() %><%=content.getBookId() %> <%=content.getSection().getBook().getName()%> <%=content.getSection().getBook().getLevel1()%> <%=content.getSection().getBook().getLevel2()%>