From 2a593ddac16e06f1ff55edca22ea568f07b068ba Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 02 四月 2021 19:15:18 +0800
Subject: [PATCH] 3.9.0bug修改
---
src/main/java/com/yeshi/buwan/util/SolrUtil.java | 947 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 478 insertions(+), 469 deletions(-)
diff --git a/src/main/java/com/yeshi/buwan/util/SolrUtil.java b/src/main/java/com/yeshi/buwan/util/SolrUtil.java
index 5dc0090..126db1b 100644
--- a/src/main/java/com/yeshi/buwan/util/SolrUtil.java
+++ b/src/main/java/com/yeshi/buwan/util/SolrUtil.java
@@ -18,535 +18,544 @@
public class SolrUtil {
- // 鑵捐浜�
- static String IP_OUT = "203.195.196.115";
- static String IP_IN = "172.16.16.12";// 10.165.56.110 10.129.37.198
+ // 鑵捐浜�
+ static String IP_OUT = "203.195.196.115";
+ static String IP_IN = "172.16.16.12";// 10.165.56.110 10.129.37.198
- private static String escapeQueryChars(String s) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- // These characters are part of the query syntax and must be escaped
- if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':' || c == '^'
- || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~' || c == '*' || c == '?'
- || c == '|' || c == '&' || c == ';' || c == '/' || Character.isWhitespace(c)) {
- sb.append('\\');
- }
- sb.append(c);
- }
- return sb.toString();
- }
+ private static String escapeQueryChars(String s) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+ // These characters are part of the query syntax and must be escaped
+ if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':' || c == '^'
+ || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~' || c == '*' || c == '?'
+ || c == '|' || c == '&' || c == ';' || c == '/' || Character.isWhitespace(c)) {
+ sb.append('\\');
+ }
+ sb.append(c);
+ }
+ return sb.toString();
+ }
- public static List<VideoInfo> searchStarVideos(String key, int pageIndex) {
- List<VideoInfo> list = new ArrayList<VideoInfo>();
- try {
- String url = String.format("http://%s:8983/solr/buwan/select?q=%s&fq=show:1&fq=contenttype:1&start="
- + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount + "&wt=json&indent=true&_="// 10.165.56.110
- // 121.42.58.49
- + System.currentTimeMillis(), Constant.IsOutNet ? IP_IN : IP_OUT,
- "mainactor:" + URLEncoder.encode(escapeQueryChars(key), "UTF-8"));
- Map<String, String> map = new HashMap<String, String>();
- map.put("Accept", "application/json, text/javascript, */*; q=0.01");
+ public static List<VideoInfo> searchStarVideos(String key, int pageIndex) {
+ List<VideoInfo> list = new ArrayList<VideoInfo>();
+ try {
+ String url = String.format("http://%s:8983/solr/buwan/select?q=%s&fq=show:1&fq=contenttype:1&start="
+ + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount + "&wt=json&indent=true&_="// 10.165.56.110
+ // 121.42.58.49
+ + System.currentTimeMillis(), Constant.IsOutNet ? IP_IN : IP_OUT,
+ "mainactor:" + URLEncoder.encode(escapeQueryChars(key), "UTF-8"));
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("Accept", "application/json, text/javascript, */*; q=0.01");
- InputStream is = HttpUtil.getAsInputStream(url);
- BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- StringBuffer buffer = new StringBuffer();
- String line = "";
- try {
- while ((line = in.readLine()) != null) {
- buffer.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ InputStream is = HttpUtil.getAsInputStream(url);
+ BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ StringBuffer buffer = new StringBuffer();
+ String line = "";
+ try {
+ while ((line = in.readLine()) != null) {
+ buffer.append(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- JSONObject data = JSONObject.fromObject(buffer.toString());
- JSONArray array = data.optJSONObject("response").optJSONArray("docs");
- for (int i = 0; i < array.size(); i++) {
- JSONObject obj = array.optJSONObject(i);
- list.add(convertJSONTOVideo(obj));
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return list;
- }
+ JSONObject data = JSONObject.fromObject(buffer.toString());
+ JSONArray array = data.optJSONObject("response").optJSONArray("docs");
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject obj = array.optJSONObject(i);
+ list.add(convertJSONTOVideo(obj));
+ }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return list;
+ }
- public static List<VideoInfo> search(String key, int pageIndex) {
- List<VideoInfo> list = new ArrayList<VideoInfo>();
- try {
- String url = String.format("http://%s:8983/solr/buwan/select?q=%s&fq=show:1&start="
- + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount + "&wt=json&indent=true&_="// 10.165.56.110
- // 121.42.58.49
- + System.currentTimeMillis(), Constant.IsOutNet ? IP_IN : IP_OUT,
- "name:" + URLEncoder.encode(escapeQueryChars(key) + "", "UTF-8"));
- Map<String, String> map = new HashMap<String, String>();
- map.put("Accept", "application/json, text/javascript, */*; q=0.01");
+ public static List<VideoInfo> search(String key, int pageIndex) {
+ List<VideoInfo> list = new ArrayList<VideoInfo>();
+ try {
+ String url = String.format("http://%s:8983/solr/buwan/select?q=%s&fq=show:1&start="
+ + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount + "&wt=json&indent=true&_="// 10.165.56.110
+ // 121.42.58.49
+ + System.currentTimeMillis(), Constant.IsOutNet ? IP_IN : IP_OUT,
+ "name:" + URLEncoder.encode("\"" + escapeQueryChars(key) + "\"", "UTF-8"));
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("Accept", "application/json, text/javascript, */*; q=0.01");
- InputStream is = HttpUtil.getAsInputStream(url);
- BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- StringBuffer buffer = new StringBuffer();
- String line = "";
- try {
- while ((line = in.readLine()) != null) {
- buffer.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ InputStream is = HttpUtil.getAsInputStream(url);
+ BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ StringBuffer buffer = new StringBuffer();
+ String line = "";
+ try {
+ while ((line = in.readLine()) != null) {
+ buffer.append(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- JSONObject data = JSONObject.fromObject(buffer.toString());
- JSONArray array = data.optJSONObject("response").optJSONArray("docs");
- for (int i = 0; i < array.size(); i++) {
- JSONObject obj = array.optJSONObject(i);
- list.add(convertJSONTOVideo(obj));
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return list;
- }
+ JSONObject data = JSONObject.fromObject(buffer.toString());
+ JSONArray array = data.optJSONObject("response").optJSONArray("docs");
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject obj = array.optJSONObject(i);
+ list.add(convertJSONTOVideo(obj));
+ }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
- public static List<VideoInfo> searchZhengPian(String key, int pageIndex) {
- List<VideoInfo> list = new ArrayList<VideoInfo>();
- try {
- String url = String.format("http://%s:8983/solr/buwan/select?q=%s&fq=%s&fq=show:1&start="
- + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount + "&wt=json&indent=true&_="// 10.165.56.110
- // //
- // 121.42.58.49
- + System.currentTimeMillis(), Constant.IsOutNet ? IP_IN : IP_OUT,
- "name:" + URLEncoder.encode(escapeQueryChars(key), "UTF-8"), "contenttype:1");
- Map<String, String> map = new HashMap<String, String>();
- map.put("Accept", "application/json, text/javascript, */*; q=0.01");
+ }
+ return list;
+ }
- InputStream is = HttpUtil.getAsInputStream(url);
- BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- StringBuffer buffer = new StringBuffer();
- String line = "";
- try {
- while ((line = in.readLine()) != null) {
- buffer.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ public static List<VideoInfo> searchZhengPian(String key, int pageIndex) {
+ List<VideoInfo> list = new ArrayList<VideoInfo>();
+ try {
+ String url = String.format("http://%s:8983/solr/buwan/select?q=%s&fq=%s&fq=show:1&start="
+ + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount + "&wt=json&indent=true&_="// 10.165.56.110
+ // //
+ // 121.42.58.49
+ + System.currentTimeMillis(), Constant.IsOutNet ? IP_IN : IP_OUT,
+ "name:" + URLEncoder.encode(escapeQueryChars(key), "UTF-8"), "contenttype:1");
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("Accept", "application/json, text/javascript, */*; q=0.01");
- JSONObject data = JSONObject.fromObject(buffer.toString());
- JSONArray array = data.optJSONObject("response").optJSONArray("docs");
- for (int i = 0; i < array.size(); i++) {
- JSONObject obj = array.optJSONObject(i);
- list.add(convertJSONTOVideo(obj));
- }
+ InputStream is = HttpUtil.getAsInputStream(url);
+ BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ StringBuffer buffer = new StringBuffer();
+ String line = "";
+ try {
+ while ((line = in.readLine()) != null) {
+ buffer.append(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return list;
- }
+ JSONObject data = JSONObject.fromObject(buffer.toString());
+ JSONArray array = data.optJSONObject("response").optJSONArray("docs");
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject obj = array.optJSONObject(i);
+ list.add(convertJSONTOVideo(obj));
+ }
- public static List<VideoInfo> searchZhuanJi(String key, int pageIndex) {
- List<VideoInfo> list = new ArrayList<VideoInfo>();
- try {
- String url = String.format("http://%s:8983/solr/buwan/select?q=%s&fq=%s&fq=show:1&start="
- + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount + "&wt=json&indent=true&_="// 10.165.56.110
- // //
- // 121.42.58.49
- + System.currentTimeMillis(), Constant.IsOutNet ? IP_IN : IP_OUT,
- "name:" + URLEncoder.encode(escapeQueryChars(key), "UTF-8"),
- URLEncoder.encode(("videocount:[2 TO *]"), "UTF-8"));
- Map<String, String> map = new HashMap<String, String>();
- map.put("Accept", "application/json, text/javascript, */*; q=0.01");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return list;
+ }
- InputStream is = HttpUtil.getAsInputStream(url);
- BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- StringBuffer buffer = new StringBuffer();
- String line = "";
- try {
- while ((line = in.readLine()) != null) {
- buffer.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ public static List<VideoInfo> searchZhuanJi(String key, int pageIndex) {
+ List<VideoInfo> list = new ArrayList<VideoInfo>();
+ try {
+ String url = String.format("http://%s:8983/solr/buwan/select?q=%s&fq=%s&fq=show:1&start="
+ + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount + "&wt=json&indent=true&_="// 10.165.56.110
+ // //
+ // 121.42.58.49
+ + System.currentTimeMillis(), Constant.IsOutNet ? IP_IN : IP_OUT,
+ "name:" + URLEncoder.encode(escapeQueryChars(key), "UTF-8"),
+ URLEncoder.encode(("videocount:[2 TO *]"), "UTF-8"));
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("Accept", "application/json, text/javascript, */*; q=0.01");
- JSONObject data = JSONObject.fromObject(buffer.toString());
- JSONArray array = data.optJSONObject("response").optJSONArray("docs");
- for (int i = 0; i < array.size(); i++) {
- JSONObject obj = array.optJSONObject(i);
- list.add(convertJSONTOVideo(obj));
- }
+ InputStream is = HttpUtil.getAsInputStream(url);
+ BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ StringBuffer buffer = new StringBuffer();
+ String line = "";
+ try {
+ while ((line = in.readLine()) != null) {
+ buffer.append(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- return list;
- }
+ JSONObject data = JSONObject.fromObject(buffer.toString());
+ JSONArray array = data.optJSONObject("response").optJSONArray("docs");
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject obj = array.optJSONObject(i);
+ list.add(convertJSONTOVideo(obj));
+ }
- private static VideoInfo convertJSONTOVideo(JSONObject obj) {
- VideoInfo info = new VideoInfo();
- info.setId(obj.optString("id"));
- info.setArea(obj.optString("area"));
- info.setContentType(obj.optInt("contenttype"));
- info.setDirector(obj.optString("director"));
- info.setDuration(obj.optString("duration"));
- info.setHpicture(obj.optString("hpicture"));
- info.setMainActor(obj.optString("mainactor"));
- info.setName(obj.optString("name"));
- info.setPicture(obj.optString("picture"));
- info.setScore(obj.optString("score"));
- info.setShow(obj.optString("show"));
- info.setTag(obj.optString("tag"));
- info.setVpicture(obj.optString("vpicture"));
- info.setWatchCount(obj.optString("watchcount"));
- info.setUpdatetime(obj.optString("updatetime"));
- info.setCreatetime(obj.optLong("createtime"));
- info.setCommentCount(StringUtil.isNullOrEmpty(obj.optString("commentcount")) ? 0
- : Integer.parseInt(obj.optString("commentcount")));
- info.setVideocount(obj.optInt("videocount"));
- return info;
- }
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ return list;
+ }
- @SuppressWarnings("deprecation")
- public static void deleteVideoIndex(String id) {
- String url = String.format(
- "http://%s:8983/solr/buwan/update?stream.body=%s&stream.contentType=text/xml;charset=utf-8&commit=true",
- Constant.IsOutNet ? IP_IN : IP_OUT, URLEncoder.encode("<delete><id>" + id + "</id></delete>"));
- String result = HttpUtil.get(url);
- System.out.println(result);
- }
+ private static VideoInfo convertJSONTOVideo(JSONObject obj) {
+ VideoInfo info = new VideoInfo();
+ info.setId(obj.optString("id"));
+ info.setArea(obj.optString("area"));
+ info.setContentType(obj.optInt("contenttype"));
+ info.setDirector(obj.optString("director"));
+ info.setDuration(obj.optString("duration"));
+ info.setHpicture(obj.optString("hpicture"));
+ info.setMainActor(obj.optString("mainactor"));
+ info.setName(obj.optString("name"));
+ info.setPicture(obj.optString("picture"));
+ info.setScore(obj.optString("score"));
+ info.setShow(obj.optString("show"));
+ info.setTag(obj.optString("tag"));
+ info.setVpicture(obj.optString("vpicture"));
+ info.setWatchCount(obj.optString("watchcount"));
+ info.setUpdatetime(obj.optString("updatetime"));
+ info.setCreatetime(obj.optLong("createtime"));
+ info.setCommentCount(StringUtil.isNullOrEmpty(obj.optString("commentcount")) ? 0
+ : Integer.parseInt(obj.optString("commentcount")));
+ info.setVideocount(obj.optInt("videocount"));
+ return info;
+ }
- public static Map<String, Object> getCategoryVideoList(int pageIndex, String key, int contenttype,
- List<Long> videoTypeIds, String sort) {
- Map<String, Object> map = new HashMap<String, Object>();
+ @SuppressWarnings("deprecation")
+ public static void deleteVideoIndex(String id) {
+ String url = String.format(
+ "http://%s:8983/solr/buwan/update?stream.body=%s&stream.contentType=text/xml;charset=utf-8&commit=true",
+ Constant.IsOutNet ? IP_IN : IP_OUT, URLEncoder.encode("<delete><id>" + id + "</id></delete>"));
+ String result = HttpUtil.get(url);
+ System.out.println(result);
+ }
- String q = "";
- q += "q=";
- if (videoTypeIds != null && videoTypeIds.size() > 0) {
+ public static Map<String, Object> getCategoryVideoList(int pageIndex, String key, int contenttype,
+ List<Long> videoTypeIds, String sort) {
+ Map<String, Object> map = new HashMap<String, Object>();
- String qparmas = "(";
- for (Long type : videoTypeIds) {
- qparmas += String.format("videotypeid:%s OR ", type + "");
- }
+ String q = "";
+ q += "q=";
+ if (videoTypeIds != null && videoTypeIds.size() > 0) {
- if (qparmas.endsWith("OR "))
- qparmas = qparmas.substring(0, qparmas.length() - 3);
+ String qparmas = "(";
+ for (Long type : videoTypeIds) {
+ qparmas += String.format("videotypeid:%s OR ", type + "");
+ }
- qparmas += ")";
- if (!StringUtil.isNullOrEmpty(key)) {
- qparmas += String.format(" AND (name:%s)", "\"" + key + "\"");
- }
+ if (qparmas.endsWith("OR "))
+ qparmas = qparmas.substring(0, qparmas.length() - 3);
- try {
- q += URLEncoder.encode(qparmas, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- } else {
- String qparmas = "";
- if (!StringUtil.isNullOrEmpty(key)) {
- qparmas += String.format("name:%s", "\"" + key + "\"");
- } else {
- qparmas += "*:*";
- }
- try {
- q += URLEncoder.encode(qparmas, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
+ qparmas += ")";
+ if (!StringUtil.isNullOrEmpty(key)) {
+ qparmas += String.format(" AND (name:%s)", "\"" + key + "\"");
+ }
- }
+ try {
+ q += URLEncoder.encode(qparmas, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ } else {
+ String qparmas = "";
+ if (!StringUtil.isNullOrEmpty(key)) {
+ qparmas += String.format("name:%s", "\"" + key + "\"");
+ } else {
+ qparmas += "*:*";
+ }
+ try {
+ q += URLEncoder.encode(qparmas, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
- if (sort != null) {
- try {
- sort = URLEncoder.encode(sort, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- }
+ }
- String fq = "";
+ if (sort != null) {
+ try {
+ sort = URLEncoder.encode(sort, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
- if (contenttype == 1)
- fq += "contenttype:1";
- else if (contenttype > 1) {
- fq += "contenttype:[2 TO 100]";
- }
+ String fq = "";
- fq = StringUtil.isNullOrEmpty(fq) ? "" : "fq=" + URLEncoder.encode(fq);
+ if (contenttype == 1)
+ fq += "contenttype:1";
+ else if (contenttype > 1) {
+ fq += "contenttype:[2 TO 100]";
+ }
- String url = String.format(
- "http://%s:8983/solr/buwan_videotype_video/select?%s&%s&group=true&group.field=videoid&sort=%s&start="
- + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount
- + "&wt=json&indent=true&_=" + System.currentTimeMillis(),
- Constant.IsOutNet ? IP_IN : IP_OUT, q, fq, sort);
+ fq = StringUtil.isNullOrEmpty(fq) ? "" : "fq=" + URLEncoder.encode(fq);
- try {
- InputStream is = HttpUtil.getAsInputStream(url);
- BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- StringBuffer buffer = new StringBuffer();
- String line = "";
- try {
- while ((line = in.readLine()) != null) {
- buffer.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ String url = String.format(
+ "http://%s:8983/solr/buwan_videotype_video/select?%s&%s&group=true&group.field=videoid&sort=%s&start="
+ + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount
+ + "&wt=json&indent=true&_=" + System.currentTimeMillis(),
+ Constant.IsOutNet ? IP_IN : IP_OUT, q, fq, sort);
- JSONObject data = JSONObject.fromObject(buffer.toString());
- int count = data.optJSONObject("grouped").optJSONObject("videoid").optInt("matches");
- map.put("count", count);
- JSONArray array = data.optJSONObject("grouped").optJSONObject("videoid").optJSONArray("groups");
- List<Long> videoIdList = new ArrayList<Long>();
- for (int i = 0; i < array.size(); i++) {
- JSONArray docsArray = array.optJSONObject(i).optJSONObject("doclist").optJSONArray("docs");
- if (docsArray.size() > 0) {
- videoIdList.add(docsArray.optJSONObject(0).optLong("videoid"));
- }
- }
+ try {
+ InputStream is = HttpUtil.getAsInputStream(url);
+ BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ StringBuffer buffer = new StringBuffer();
+ String line = "";
+ try {
+ while ((line = in.readLine()) != null) {
+ buffer.append(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- if (videoIdList.size() > 0) {// 鏈夎棰戞暟鎹�
- List<VideoInfo> videoList = new ArrayList<VideoInfo>();
+ JSONObject data = JSONObject.fromObject(buffer.toString());
+ int count = data.optJSONObject("grouped").optJSONObject("videoid").optInt("matches");
+ map.put("count", count);
+ JSONArray array = data.optJSONObject("grouped").optJSONObject("videoid").optJSONArray("groups");
+ List<Long> videoIdList = new ArrayList<Long>();
+ for (int i = 0; i < array.size(); i++) {
+ JSONArray docsArray = array.optJSONObject(i).optJSONObject("doclist").optJSONArray("docs");
+ if (docsArray.size() > 0) {
+ videoIdList.add(docsArray.optJSONObject(0).optLong("videoid"));
+ }
+ }
- q = "q=";
- String qparams = "";
- for (long videoid : videoIdList) {
- qparams += String.format("id:%s or ", videoid);
- }
- if (qparams.endsWith("or "))
- qparams = qparams.substring(0, qparams.length() - 3);
- q += URLEncoder.encode(qparams, "UTF-8");
- url = String.format(
- "http://%s:8983/solr/buwan/select?%s&sort=%s&rows=" + Constant.pageCount + ""
- + "&wt=json&indent=true&_t=" + System.currentTimeMillis(),
- Constant.IsOutNet ? IP_IN : IP_OUT, q, sort);
- is = HttpUtil.getAsInputStream(url);
- in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- buffer = new StringBuffer();
- line = "";
- try {
- while ((line = in.readLine()) != null) {
- buffer.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ if (videoIdList.size() > 0) {// 鏈夎棰戞暟鎹�
+ List<VideoInfo> videoList = new ArrayList<VideoInfo>();
- data = JSONObject.fromObject(buffer.toString());
- array = data.optJSONObject("response").optJSONArray("docs");
- for (int i = 0; i < array.size(); i++) {
- JSONObject obj = array.optJSONObject(i);
- videoList.add(convertJSONTOVideo(obj));
- }
- map.put("data", videoList);
- return map;
- }
+ q = "q=";
+ String qparams = "";
+ for (long videoid : videoIdList) {
+ qparams += String.format("id:%s or ", videoid);
+ }
+ if (qparams.endsWith("or "))
+ qparams = qparams.substring(0, qparams.length() - 3);
+ q += URLEncoder.encode(qparams, "UTF-8");
+ url = String.format(
+ "http://%s:8983/solr/buwan/select?%s&sort=%s&rows=" + Constant.pageCount + ""
+ + "&wt=json&indent=true&_t=" + System.currentTimeMillis(),
+ Constant.IsOutNet ? IP_IN : IP_OUT, q, sort);
+ is = HttpUtil.getAsInputStream(url);
+ in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ buffer = new StringBuffer();
+ line = "";
+ try {
+ while ((line = in.readLine()) != null) {
+ buffer.append(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- } catch (Exception e) {
- e.fillInStackTrace();
- }
- return null;
+ data = JSONObject.fromObject(buffer.toString());
+ array = data.optJSONObject("response").optJSONArray("docs");
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject obj = array.optJSONObject(i);
+ videoList.add(convertJSONTOVideo(obj));
+ }
+ map.put("data", videoList);
+ return map;
+ }
- }
+ } catch (Exception e) {
+ e.fillInStackTrace();
+ }
+ return null;
- public static Map<String, Object> getCategoryVideoList(int pageIndex, String key, int contenttype,
- List<Long> videoTypeIds) {
- Map<String, Object> map = new HashMap<String, Object>();
+ }
- String q = "";
- q += "q=";
- if (videoTypeIds != null && videoTypeIds.size() > 0) {
+ public static Map<String, Object> getCategoryVideoList(int pageIndex, String key, int contenttype,
+ List<Long> videoTypeIds) {
+ Map<String, Object> map = new HashMap<String, Object>();
- String qparmas = "(";
- for (Long type : videoTypeIds) {
- qparmas += String.format("videotypeid:%s or ", type + "");
- }
+ String q = "";
+ q += "q=";
+ if (videoTypeIds != null && videoTypeIds.size() > 0) {
- if (qparmas.endsWith("or "))
- qparmas = qparmas.substring(0, qparmas.length() - 3);
+ String qparmas = "(";
+ for (Long type : videoTypeIds) {
+ qparmas += String.format("videotypeid:%s or ", type + "");
+ }
- qparmas += ")";
- if (!StringUtil.isNullOrEmpty(key)) {
- qparmas += String.format(" and (name:%s)", key);
- }
+ if (qparmas.endsWith("or "))
+ qparmas = qparmas.substring(0, qparmas.length() - 3);
- try {
- q += URLEncoder.encode(qparmas, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- } else {
- String qparmas = "";
- if (!StringUtil.isNullOrEmpty(key)) {
- qparmas += String.format("name:%s", key);
- } else {
- qparmas += "*:*";
- }
- try {
- q += URLEncoder.encode(qparmas, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
+ qparmas += ")";
+ if (!StringUtil.isNullOrEmpty(key)) {
+ qparmas += String.format(" and (name:%s)", key);
+ }
- }
+ try {
+ q += URLEncoder.encode(qparmas, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ } else {
+ String qparmas = "";
+ if (!StringUtil.isNullOrEmpty(key)) {
+ qparmas += String.format("name:%s", key);
+ } else {
+ qparmas += "*:*";
+ }
+ try {
+ q += URLEncoder.encode(qparmas, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
- String sort = "";
- try {
- if (StringUtil.isNullOrEmpty(key))
- sort = URLEncoder.encode("createtime desc", "UTF-8");
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
+ }
- String fq = "";
+ String sort = "";
+ try {
+ if (StringUtil.isNullOrEmpty(key))
+ sort = URLEncoder.encode("createtime desc", "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
- if (contenttype == 1)
- fq += "contenttype:1";
- else if (contenttype > 1) {
- fq += "contenttype:[2 TO 100]";
- }
+ String fq = "";
- fq = StringUtil.isNullOrEmpty(fq) ? "" : "fq=" + URLEncoder.encode(fq);
+ if (contenttype == 1)
+ fq += "contenttype:1";
+ else if (contenttype > 1) {
+ fq += "contenttype:[2 TO 100]";
+ }
- String url = String.format(
- "http://%s:8983/solr/buwan_videotype_video/select?%s&%s&group=true&group.field=videoid&sort=%s&start="
- + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount
- + "&wt=json&indent=true&_=" + System.currentTimeMillis(),
- Constant.IsOutNet ? IP_IN : IP_OUT, q, fq, sort);
+ fq = StringUtil.isNullOrEmpty(fq) ? "" : "fq=" + URLEncoder.encode(fq);
- try {
- InputStream is = HttpUtil.getAsInputStream(url);
- BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- StringBuffer buffer = new StringBuffer();
- String line = "";
- try {
- while ((line = in.readLine()) != null) {
- buffer.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ String url = String.format(
+ "http://%s:8983/solr/buwan_videotype_video/select?%s&%s&group=true&group.field=videoid&sort=%s&start="
+ + (pageIndex - 1) * Constant.pageCount + "&rows=" + Constant.pageCount
+ + "&wt=json&indent=true&_=" + System.currentTimeMillis(),
+ Constant.IsOutNet ? IP_IN : IP_OUT, q, fq, sort);
- JSONObject data = JSONObject.fromObject(buffer.toString());
- int count = data.optJSONObject("grouped").optJSONObject("videoid").optInt("matches");
- map.put("count", count);
- JSONArray array = data.optJSONObject("grouped").optJSONObject("videoid").optJSONArray("groups");
- List<Long> videoIdList = new ArrayList<Long>();
- for (int i = 0; i < array.size(); i++) {
- JSONArray docsArray = array.optJSONObject(i).optJSONObject("doclist").optJSONArray("docs");
- if (docsArray.size() > 0) {
- videoIdList.add(docsArray.optJSONObject(0).optLong("videoid"));
- }
- }
+ try {
+ InputStream is = HttpUtil.getAsInputStream(url);
+ BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ StringBuffer buffer = new StringBuffer();
+ String line = "";
+ try {
+ while ((line = in.readLine()) != null) {
+ buffer.append(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- if (videoIdList.size() > 0) {// 鏈夎棰戞暟鎹�
- List<VideoInfo> videoList = new ArrayList<VideoInfo>();
+ JSONObject data = JSONObject.fromObject(buffer.toString());
+ int count = data.optJSONObject("grouped").optJSONObject("videoid").optInt("matches");
+ map.put("count", count);
+ JSONArray array = data.optJSONObject("grouped").optJSONObject("videoid").optJSONArray("groups");
+ List<Long> videoIdList = new ArrayList<Long>();
+ for (int i = 0; i < array.size(); i++) {
+ JSONArray docsArray = array.optJSONObject(i).optJSONObject("doclist").optJSONArray("docs");
+ if (docsArray.size() > 0) {
+ videoIdList.add(docsArray.optJSONObject(0).optLong("videoid"));
+ }
+ }
- q = "q=";
- String qparams = "";
- for (long videoid : videoIdList) {
- qparams += String.format("id:%s or ", videoid);
- }
- if (qparams.endsWith("or "))
- qparams = qparams.substring(0, qparams.length() - 3);
- q += URLEncoder.encode(qparams, "UTF-8");
- url = String.format(
- "http://%s:8983/solr/buwan/select?%s&sort=%s&rows=" + Constant.pageCount + ""
- + "&wt=json&indent=true&_t=" + System.currentTimeMillis(),
- Constant.IsOutNet ? IP_IN : IP_OUT, q, sort);
- is = HttpUtil.getAsInputStream(url);
- in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- buffer = new StringBuffer();
- line = "";
- try {
- while ((line = in.readLine()) != null) {
- buffer.append(line);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ if (videoIdList.size() > 0) {// 鏈夎棰戞暟鎹�
+ List<VideoInfo> videoList = new ArrayList<VideoInfo>();
- data = JSONObject.fromObject(buffer.toString());
- array = data.optJSONObject("response").optJSONArray("docs");
- for (int i = 0; i < array.size(); i++) {
- JSONObject obj = array.optJSONObject(i);
- videoList.add(convertJSONTOVideo(obj));
- }
- map.put("data", videoList);
- return map;
- }
+ q = "q=";
+ String qparams = "";
+ for (long videoid : videoIdList) {
+ qparams += String.format("id:%s or ", videoid);
+ }
+ if (qparams.endsWith("or "))
+ qparams = qparams.substring(0, qparams.length() - 3);
+ q += URLEncoder.encode(qparams, "UTF-8");
+ url = String.format(
+ "http://%s:8983/solr/buwan/select?%s&sort=%s&rows=" + Constant.pageCount + ""
+ + "&wt=json&indent=true&_t=" + System.currentTimeMillis(),
+ Constant.IsOutNet ? IP_IN : IP_OUT, q, sort);
+ is = HttpUtil.getAsInputStream(url);
+ in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ buffer = new StringBuffer();
+ line = "";
+ try {
+ while ((line = in.readLine()) != null) {
+ buffer.append(line);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- } catch (Exception e) {
+ data = JSONObject.fromObject(buffer.toString());
+ array = data.optJSONObject("response").optJSONArray("docs");
+ for (int i = 0; i < array.size(); i++) {
+ JSONObject obj = array.optJSONObject(i);
+ videoList.add(convertJSONTOVideo(obj));
+ }
+ map.put("data", videoList);
+ return map;
+ }
- }
- return null;
- }
+ } catch (Exception e) {
- // 澧為噺鏇存柊Video
- public static void deltaimportVideo() {
- String url = String.format(
- "http://%s:8983/solr/buwan/deltaimport?command=delta-import&commit=true&wt=json&indent=true&verbose=false&clean=false&optimize=false&debug=false",
- Constant.IsOutNet ? IP_IN : IP_OUT);
- HttpUtil.get(url);
- // Map<String, String> map = new HashMap<String, String>();
- // map.put("command", "delta-import");
- // map.put("commit", "true");
- // map.put("wt", "json");
- // map.put("indent", "true");
- // map.put("entity", "video");
- // map.put("start", "0");
- // map.put("rows", "50000");
- // map.put("verbose", "false");
- // map.put("clean", "false");
- // map.put("optimize", "false");
- // map.put("debug", "false");
- // String result = HttpUtil.post("http://" + (Constant.IsOutNet ? IP_IN
- // : IP_OUT) + ":8983/solr/buwan/deltaimport",
- // map);
- }
+ }
+ return null;
+ }
- // 鍏ㄩ噺鏇存柊
- public static void dataimportVideo() {
- // 鍒嗛〉璇锋眰
- int pageSize = 10000;
- for (int i = 0; i < 200; i++) {
- String url = String.format("http://%s:8983/solr/new_video/dataimport?_=%s&indent=on&wt=json",
- Constant.IsOutNet ? IP_IN : IP_OUT, System.currentTimeMillis() + "");
+ // 澧為噺鏇存柊Video
+ public static void deltaimportVideo() {
+ String url = String.format(
+ "http://%s:8983/solr/buwan/deltaimport?command=delta-import&commit=true&wt=json&indent=true&verbose=false&clean=false&optimize=false&debug=false",
+ Constant.IsOutNet ? IP_IN : IP_OUT);
+ HttpUtil.get(url);
+ // Map<String, String> map = new HashMap<String, String>();
+ // map.put("command", "delta-import");
+ // map.put("commit", "true");
+ // map.put("wt", "json");
+ // map.put("indent", "true");
+ // map.put("entity", "juhe");
+ // map.put("start", "0");
+ // map.put("rows", "50000");
+ // map.put("verbose", "false");
+ // map.put("clean", "false");
+ // map.put("optimize", "false");
+ // map.put("debug", "false");
+ // String result = HttpUtil.post("http://" + (Constant.IsOutNet ? IP_IN
+ // : IP_OUT) + ":8983/solr/buwan/deltaimport",
+ // map);
+ }
- Map<String, String> map = new HashMap<>();
- map.put("command", "full-import");
- map.put("verbose", "false");
- map.put("clean", "false");
- map.put("commit", "true");
- map.put("core", "new_video");
- map.put("entity", "video");
- map.put("startIndex", i * pageSize + "");
- map.put("count", pageSize + "");
- map.put("name", "dataimport");
- HttpUtil.post(url, map);
- try {
- Thread.sleep(1000 * 20);// 闂撮殧1鍒嗛挓
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
+ // 鍏ㄩ噺鏇存柊
+ public static void dataimportVideo() {
+ dataimportVideo("new_video");
- }
+ }
- // 鍏ㄩ噺鏇存柊
- public static void dataimportCategoryVideo() {
- String url = String.format(
- "http://%s:8983/solr/buwan_videotype_video/dataimport?command=full-import&commit=true&wt=json&indent=true&verbose=false&optimize=false&debug=false",
- Constant.IsOutNet ? IP_IN : IP_OUT);
- HttpUtil.get(url);
- }
+ public static void dataimportVideo(String core) {
+ // 鍒嗛〉璇锋眰
+ int pageSize = 10000;
+ for (int i = 0; i < 200; i++) {
+ String url = String.format("http://%s:8983/solr/%s/dataimport?_=%s&indent=on&wt=json",
+ Constant.IsOutNet ? IP_IN : IP_OUT, core, System.currentTimeMillis() + "");
- // 澧為噺鏇存柊
- public static void deltaimportCategoryVideo() {
- String url = String.format(
- "http://%s:8983/solr/buwan_videotype_video/deltaimport?command=delta-import&commit=true&wt=json&indent=true&verbose=false&clean=false&optimize=false&debug=false",
- Constant.IsOutNet ? IP_IN : IP_OUT);
- HttpUtil.get(url);
- };
+ Map<String, String> map = new HashMap<>();
+ map.put("command", "full-import");
+ map.put("verbose", "false");
+ map.put("clean", "false");
+ map.put("commit", "true");
+ map.put("core", core);
+ map.put("entity", "video");
+ map.put("startIndex", i * pageSize + "");
+ map.put("count", pageSize + "");
+ map.put("name", "dataimport");
+ HttpUtil.post(url, map);
+ try {
+ Thread.sleep(1000 * 20);// 闂撮殧20s
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ // 鍏ㄩ噺鏇存柊
+ public static void dataimportCategoryVideo() {
+ String url = String.format(
+ "http://%s:8983/solr/buwan_videotype_video/dataimport?command=full-import&commit=true&wt=json&indent=true&verbose=false&optimize=false&debug=false",
+ Constant.IsOutNet ? IP_IN : IP_OUT);
+ HttpUtil.get(url);
+ }
+
+ // 澧為噺鏇存柊
+ public static void deltaimportCategoryVideo() {
+ String url = String.format(
+ "http://%s:8983/solr/buwan_videotype_video/deltaimport?command=delta-import&commit=true&wt=json&indent=true&verbose=false&clean=false&optimize=false&debug=false",
+ Constant.IsOutNet ? IP_IN : IP_OUT);
+ HttpUtil.get(url);
+ }
+
+ ;
}
--
Gitblit v1.8.0