public static String[] getSearchEngine(Visit v) { String url = v.URL; if (StringUtil.isEmpty(url)) { return null; } if (url.indexOf("Result.jsp") > 0) { String keyword = SearchAPI.getParameter(url, "query"); return new String[] {"站内搜索", keyword}; } url = v.Referer; String domain = StatUtil.getDomain(url); Mapx map = ServletUtil.getMapFromQueryString(url); String name = null; String keyword = null; if (domain.indexOf("baidu.") > 0) { keyword = StringUtil.urlDecode(map.getString("wd"), "GBK"); name = "百度"; } else if (domain.indexOf("google.") > 0) { String charset = map.getString("ie"); if (StringUtil.isEmpty(charset)) { charset = "UTF-8"; } keyword = StringUtil.urlDecode(map.getString("q"), charset); name = "谷歌"; } else if (domain.indexOf("yahoo.") > 0) { String charset = map.getString("ei"); if (StringUtil.isEmpty(charset)) { charset = "UTF-8"; } keyword = StringUtil.urlDecode(map.getString("p"), charset); name = "雅虎"; } else if (domain.indexOf("msn.") > 0) { keyword = StringUtil.urlDecode(map.getString("q"), "UTF-8"); name = "MSN"; } else if (domain.indexOf("soso.") > 0) { keyword = StringUtil.urlDecode(map.getString("w"), "GBK"); name = "搜搜"; } else if (domain.indexOf("sogou.") > 0) { keyword = StringUtil.urlDecode(map.getString("query"), "GBK"); name = "搜狗"; } else if (domain.indexOf("zhongsou.") > 0) { keyword = StringUtil.urlDecode(map.getString("word"), "GBK"); name = "中搜"; } else if (domain.indexOf("youdao.") > 0) { String charset = map.getString("ue"); if (StringUtil.isEmpty(charset)) { charset = "UTF-8"; } keyword = StringUtil.urlDecode(map.getString("q"), charset); name = "有道"; } else if (domain.indexOf("live.") > 0) { keyword = StringUtil.urlDecode(map.getString("q"), "UTF-8"); name = "Live.com"; } if (StringUtil.isNotEmpty(keyword)) { return new String[] {name, keyword}; } return null; }
public static SearchResult search(Mapx map) { SearchParameters sps = new SearchParameters(); String site = map.getString("site"); String id = map.getString("id"); String catalog = map.getString("catalog"); if (StringUtil.isEmpty(catalog)) { catalog = map.getString("Catalog"); } String order = map.getString("order"); String time = map.getString("time"); String keyword = map.getString("keyword"); String query = map.getString("query"); if (StringUtil.isEmpty(keyword)) { keyword = query; } String page = map.getString("page"); String size = map.getString("size"); if (StringUtil.isEmpty(id)) { id = SearchAPI.getIndexIDBySiteID(site); } if (StringUtil.isNotEmpty(keyword)) { sps.addFulltextField("Title", keyword, false); sps.addFulltextField("Content", keyword, false); sps.addFulltextField("_Keyword", keyword, true); } if ("time".equalsIgnoreCase(order)) { sps.setSortField("PublishDate", 3, true); } if (StringUtil.isNotEmpty(time)) { Date today = new Date(); String StartDate = DateUtil.toString(DateUtil.addDay(today, -36500)); if (time.equals("week")) StartDate = DateUtil.toString(DateUtil.addDay(today, -7)); else if (time.equals("month")) StartDate = DateUtil.toString(DateUtil.addDay(today, -30)); else if (time.equals("quarter")) { StartDate = DateUtil.toString(DateUtil.addDay(today, -90)); } String EndDate = "2999-01-01"; sps.setDateRange("PublishDate", StartDate, EndDate); } if (StringUtil.isNotEmpty(catalog)) { sps.addLeftLikeField("CatalogInnerCode", catalog); } if (StringUtil.isNotEmpty(page)) { sps.setPageIndex(Integer.parseInt(page) - 1); } if (StringUtil.isNotEmpty(size)) { sps.setPageSize(Integer.parseInt(size)); } if (StringUtil.isEmpty(id)) { SearchResult sr = new SearchResult(); sr.Data = new DataTable(); return sr; } sps.setIndexID(Long.parseLong(id)); return ArticleIndexer.search(sps); }
public static SearchResult tagSearch(Mapx map) { SearchParameters sps = new SearchParameters(); String site = map.getString("site"); String order = map.getString("order"); String keyword = map.getString("keyword"); String query = map.getString("query"); if (StringUtil.isEmpty(keyword)) { keyword = query; } String page = map.getString("page"); String size = map.getString("size"); if (StringUtil.isNotEmpty(keyword)) { sps.addLikeField("Tag", keyword, false); } if ("time".equalsIgnoreCase(order)) { sps.setSortField("PublishDate", 3, true); } if (StringUtil.isNotEmpty(page)) { sps.setPageIndex(Integer.parseInt(page) - 1); } if (StringUtil.isNotEmpty(size)) { sps.setPageSize(Integer.parseInt(size)); } String id = SearchAPI.getIndexIDBySiteID(site); sps.setIndexID(Long.parseLong(id)); return ArticleIndexer.search(sps); }
public static SearchResult advanceSearch(Mapx map) { SearchParameters sps = new SearchParameters(); String site = map.getString("site"); String id = map.getString("id"); String startDate = map.getString("startdate"); String endDate = map.getString("enddate"); String catalog = map.getString("catalog"); String author = map.getString("author"); String title = map.getString("title"); String content = map.getString("content"); String keyword = map.getString("keyword"); String query = map.getString("query"); if (StringUtil.isEmpty(keyword)) { keyword = query; } String orderField = map.getString("orderfield"); String descFlag = map.getString("descflag"); String page = map.getString("page"); String size = map.getString("size"); if (StringUtil.isEmpty(id)) { id = SearchAPI.getIndexIDBySiteID(site); } if ((StringUtil.isNotEmpty(startDate)) && (StringUtil.isEmpty(endDate))) { endDate = "2099-01-01"; } if ((StringUtil.isNotEmpty(endDate)) && (StringUtil.isEmpty(startDate))) { startDate = "1900-01-01"; } if (StringUtil.isNotEmpty(startDate)) { sps.setDateRange("PublishDate", startDate, endDate); } if (StringUtil.isNotEmpty(catalog)) { sps.addLeftLikeField("CatalogInnerCode", catalog, true); } if (StringUtil.isNotEmpty(title)) { sps.addFulltextField("Title", title); } if (StringUtil.isNotEmpty(content)) { sps.addFulltextField("Content", content); } if (StringUtil.isNotEmpty(keyword)) { sps.addFulltextField("Title", keyword, false); sps.addFulltextField("Content", keyword, false); sps.addFulltextField("_Keyword", keyword, true); } if (StringUtil.isNotEmpty(orderField)) { boolean isDesc = "true".equals(descFlag); sps.setSortField(orderField, 3, isDesc); } if (StringUtil.isNotEmpty(author)) { sps.addEqualField("Author", author); } if (StringUtil.isNotEmpty(page)) { sps.setPageIndex(Integer.parseInt(page) - 1); } if (StringUtil.isNotEmpty(size)) { sps.setPageSize(Integer.parseInt(size)); } if (StringUtil.isEmpty(id)) { SearchResult sr = new SearchResult(); sr.Data = new DataTable(); return sr; } sps.setIndexID(Long.parseLong(id)); return ArticleIndexer.search(sps); }