Mercurial > hg > LGServices
diff src/main/java/de/mpiwg/web/jsp/FullTextSearchPage.java @ 49:7c2e1b14b77d
new: load existing full text searching result into searching table
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 26 Jan 2016 11:46:10 +0100 |
parents | 13555aff1f88 |
children | cf747a960516 |
line wrap: on
line diff
--- 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<LGFullTextSearchFile> 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<DBContents> completListFromParsedFile = new ArrayList<DBContents>(); + + 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(); } + + + +