# HG changeset patch # User Zoe Hong # Date 1453805170 -3600 # Node ID 7c2e1b14b77d16eeb807616e7e514bbcdce11f44 # Parent 13555aff1f88e0b0337eb81702577f0f19ac2c54 new: load existing full text searching result into searching table diff -r 13555aff1f88 -r 7c2e1b14b77d pom.xml --- a/pom.xml Thu Jan 21 11:56:30 2016 +0100 +++ b/pom.xml Tue Jan 26 11:46:10 2016 +0100 @@ -134,10 +134,18 @@ mysql-connector-java 5.1.6 - + + + + org.jsoup + jsoup + 1.8.3 + + + LGServices diff -r 13555aff1f88 -r 7c2e1b14b77d src/main/java/de/mpiwg/gazetteer/db/DBContents.java --- a/src/main/java/de/mpiwg/gazetteer/db/DBContents.java Thu Jan 21 11:56:30 2016 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/db/DBContents.java Tue Jan 26 11:46:10 2016 +0100 @@ -23,6 +23,9 @@ private boolean isRemoved = false; + public DBContents(){ + + } public DBContents(ResultSet rs) throws SQLException{ diff -r 13555aff1f88 -r 7c2e1b14b77d src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java --- a/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Thu Jan 21 11:56:30 2016 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/DataProvider.java Tue Jan 26 11:46:10 2016 +0100 @@ -295,9 +295,10 @@ return list; } + 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 + // List list is the filteredList of searching result with isRemoved field Date date = new Date(); @@ -310,8 +311,8 @@ //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 - + FileManager.saveFullTextSearchFileAsHtml(searchFile, userId, list); // save html file to LGMap's datasets folder + session.getTransaction().commit(); //################################## diff -r 13555aff1f88 -r 7c2e1b14b77d src/main/java/de/mpiwg/gazetteer/utils/FileManager.java --- a/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java Thu Jan 21 11:56:30 2016 +0100 +++ b/src/main/java/de/mpiwg/gazetteer/utils/FileManager.java Tue Jan 26 11:46:10 2016 +0100 @@ -59,12 +59,12 @@ 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"; + text += "Address,LEVEL1,LEVEL2,Name,DYNASTY,PERIOD,ADMIN_TYPE,TimeSpan:begin,TimeSpan:end,Longitude,Latitude,PAGE,SECTION,CONTENT,BOOK_ID,Description\n"; for (DBContents c : list) { - if (c.getSection() != null && !c.isRemoved()){ - + if (c.getSection() != null && !c.isRemoved()){ // only those are not removed to csv which means to LGMap + DBBook book = c.getSection().getBook(); String description = book.getVolume() + "/" + book.getAuthor() + "/" + book.getEdition(); @@ -73,7 +73,9 @@ book.getLevel1() + "," + book.getLevel2() + "," + book.getName() + "," + + book.getDynasty() + "," + book.getPeriod() + "," + + book.getAdmin_type() + "," + book.getStart_year() + "," + book.getEnd_year() + "," + c.getCoordinatesBook().getX() + "," + @@ -134,7 +136,7 @@ text += "" + "
Table name: " + file.getFileName() + "
" + "
" + list.size() + " result(s) in the table." - + "
searching by keywords (possibly with filters): " + '"' + "" + file.getSearchTerms() + "" + '"' + "
" + + "
searching by keywords: " + '"' + "" + file.getSearchTerms() + "" + '"' + "
" + "
view on LGMap
" + "
" + "" @@ -144,15 +146,21 @@ + "" + "" + "" + + "" + "" + + "" + "" + "" + "" + + "" + + "" + + ""; for (DBContents c : list) { - if ( c.getSection() != null && !c.isRemoved()){ - + //if ( c.getSection() != null && !c.isRemoved()){ + if ( c.getSection() != null){ + DBBook book = c.getSection().getBook(); text += "" + @@ -161,11 +169,15 @@ "" + "" + "" + + "" + "" + + "" + "" + "" + "" + - ""; + "" + + "" + + ""; } } diff -r 13555aff1f88 -r 7c2e1b14b77d src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java --- a/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java Thu Jan 21 11:56:30 2016 +0100 +++ b/src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java Tue Jan 26 11:46:10 2016 +0100 @@ -2,24 +2,23 @@ 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 org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; -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.gazetteer.utils.FileManager; import de.mpiwg.web.fullTextSearch.SortContentByAdminType; import de.mpiwg.web.fullTextSearch.SortContentByBookId; import de.mpiwg.web.fullTextSearch.SortContentByBookName; @@ -30,17 +29,8 @@ 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{ @@ -71,7 +61,7 @@ private String level2Filter = new String(); private String periodFilter = new String(); private String sectionNameFilter = new String(); - + private String contentFilter = new String(); private List fileList = null; private String fileName = new String(); @@ -101,11 +91,13 @@ this.periodFilter = getParameter("periodFilter"); this.sectionNameFilter = getParameter("sectionNameFilter"); + this.contentFilter = getParameter("contentFilter"); this.fileName = getParameter("fileName"); - + this.focusedContentId = getParameter("focusedContentId"); + } @@ -201,6 +193,94 @@ } + public void loadFile() { + Long fileId = getLongParameter("fileId"); + logger.debug("loading fileId=" + fileId); + + if(fileId != null){ + // TODO load from html? or csv? file into searching result table + + LGFullTextSearchFile file = DataProvider.getInstance().getFullTextSearchFile(fileId); + if(file != null){ + String html; + try { + html = FileManager.getFullTextSearchHtmlFileText(file); + + Document doc = Jsoup.parse(html); + + Element body = doc.body(); + + this.setSearchTerm(body.getElementById("searchTerm").text()); + + Element pageTableBody = body.getElementsByTag("tbody").first(); + + Elements rows = pageTableBody.children(); + + // set completeList by parsing html file + List completListFromParsedFile = new ArrayList(); + + for (Element row : rows) { + // make complteListFromParsedFile... + + Elements cols = row.children(); + //logger.debug(cols.size()); + if (cols.size() < 13) { + + } else if (StringUtils.equals("#", cols.get(0).text())) { + // the table header + + } else { + DBContents content = new DBContents(); + + String bookId = cols.get(1).text(); + + Integer contentPage = Integer.parseInt(cols.get(9).text()); + + String contentText = cols.get(10).text(); + Long contentId = Long.parseLong(cols.get(11).text()); + + boolean isRemoved = true; + if (StringUtils.equals(cols.get(12).text(), "false")) { + isRemoved = false; + } + + + content.setInx(Integer.parseInt(cols.get(0).text())); + content.setId(contentId); + + content.setBookId(cols.get(1).text()); + + // set this.section by bookId and page + content.setSection(DBService.getInstance().getSectionByBookIdAndPage(bookId, contentPage)); + // set this.coordinatesBook by bookId + content.setCoordinatesBook(DBService.getInstance().getCoordinatesBook(bookId)); + + content.setContent(contentText); + content.setPage(contentPage); + content.setRemoved(isRemoved); + + completListFromParsedFile.add(content); + } + } + + + this.setCompleteList(completListFromParsedFile); + + if (this.completeList != null ){ + Collections.sort(this.completeList); + filter(); + } + + } catch (Exception e) { + logger.debug("getFullTextSearchHtmlFileText failed."); + e.printStackTrace(); + } + + } + } + + } + public void save() { logger.debug("saving table..."); @@ -238,10 +318,14 @@ searchFile.setSearchTerms(this.searchTerm); - file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getFilteredList(), userId, searchFile); + //file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getFilteredList(), userId, searchFile); + file = DataProvider.getInstance().saveLGFullTextSearchFile(this.getCompleteList(), userId, searchFile); + + + logger.debug("file: " + file.getInfo()); + addMsg("The table has been saved!"); - logger.debug(file.getInfo()); } catch (Exception e) { addMsg("Saving fails!"); @@ -267,8 +351,10 @@ (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)) - + (StringUtils.isEmpty(sectionNameFilter) || StringUtils.startsWith(content.getSection().getName(), sectionNameFilter)) && + (StringUtils.isEmpty(contentFilter) || StringUtils.contains(content.getContent(), contentFilter)) + + ){ this.filteredList.add(content); } @@ -531,10 +617,13 @@ public void setLevel1Filter(String level1Filter) { this.level1Filter = level1Filter; } - - - - /////// Sorting + public String getContentFilter() { + return contentFilter; + } + + public void setContentFilter(String contentFilter) { + this.contentFilter = contentFilter; + } public String getFocusedContentId() { return focusedContentId; @@ -584,6 +673,11 @@ this.sectionNameFilter = sectionNameFilter; } + + + /////// Sorting + + public void sortByBookNameUp(){ Collections.sort(this.completeList, new SortContentByBookName()); filter(); @@ -607,7 +701,6 @@ } - public void sortByPeriodUp(){ Collections.sort(this.completeList, new SortContentByPeriod()); filter(); @@ -707,6 +800,8 @@ Collections.reverse(completeList); filter(); } + + public void removeFocusedContent(boolean status) { @@ -731,6 +826,10 @@ this.updateCurrentSections(); } + + + + diff -r 13555aff1f88 -r 7c2e1b14b77d src/main/java/de/mpiwg/web/jsp/JSPProxy.java --- a/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Thu Jan 21 11:56:30 2016 +0100 +++ b/src/main/java/de/mpiwg/web/jsp/JSPProxy.java Tue Jan 26 11:46:10 2016 +0100 @@ -239,8 +239,11 @@ // for searching in batch keywords } else if(StringUtils.equals(action, "searchBatch")){ - getSessionBean().getFullTextSearchPage().searchBatch(); + getSessionBean().getFullTextSearchPage().searchBatch(); + // load existing searching result + } else if(StringUtils.equals(action, "loadFile")) { + getSessionBean().getFullTextSearchPage().loadFile(); //PAGINATOR } else if(StringUtils.equals(action, "firstPage")){ diff -r 13555aff1f88 -r 7c2e1b14b77d src/main/webapp/pages/fullTextSearch.jsp --- a/src/main/webapp/pages/fullTextSearch.jsp Thu Jan 21 11:56:30 2016 +0100 +++ b/src/main/webapp/pages/fullTextSearch.jsp Tue Jan 26 11:46:10 2016 +0100 @@ -142,6 +142,7 @@ + <% for (LGFullTextSearchFile aFile : sessionBean.getFullTextSearchPage().getFileList() ){%> @@ -149,12 +150,15 @@ - + <% } %> @@ -217,7 +221,7 @@ @@ -552,7 +556,27 @@
book namelevel1level2dynastyperiodadmin typesection namepagecontentcontent idisRemoved
" + book.getName() + "" + book.getLevel1() + "" + book.getLevel2() + "" + book.getDynasty() + "" + book.getPeriod() + "" + book.getAdmin_type() + "" + c.getSection().getName() + "" + c.getPage() + "" + c.getContent() + "
" + c.getId() + "" + c.isRemoved() + "
Table name html
<%= aFile.getFileName() %> + Show text in html + +
- +
- + + + + + + + + + + + + +
+ + + +
+ +