solr7定时任务同步数据库

一. 我用的solr7.73版本的,jdk1.8 用自带jetty容器 准备资源:

  1. 定时任务包:solr-dataimport-scheduler.7x版本.jar,下载地址:https://pan.baidu.com/s/16Wmje67x-nD8u2nC8F0__Q 提取码:y0zk
  2. solr分词器:下载地址:https://pan.baidu.com/s/1fGO0dfQ7H4Cs92lcLRt2fA 提取码:1eb0
  3. solr7.x的包 可以直接去官网下载,速度蛮快的。附上官网地址:https://lucene.apache.org/solr/downloads.html window下载 solr-7.7.3.zip
    二 .开始:
  4. 进入solr 的 bin 目录下 打开cmd 输入命令 solr start 启动solr
    在这里插入图片描述
    进入页面 localhost:8983 查看页面,如下效果则启动成功
    在这里插入图片描述
    2.将如下目录中的conf文件夹与core.properties文件copy
    在这里插入图片描述
    在如下目录创建一个文件夹mycore
    然后我们将上面的conf文件夹和core.properties文件copy到此文件夹中
    在这里插入图片描述
    然后重新启动 solr
    在这里插入图片描述
    3.配置中文分词器:将下载好的jar包放在如下目录,D:\svnCode\solr-7.7.3\server\solr-webapp\webapp\WEB-INF\lib
    在这里插入图片描述

然后到D:\svnCode\solr-7.7.3\server\solr\mycore\con目录中打开managed-schema文件
在配置文件中加入以下代码:

<!-- ik分词器 -->
<fieldType name="text_ik" class="solr.TextField">
  <analyzer type="index">
      <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
      <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
      <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
      <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

然后重启solr
在这里插入图片描述
4.配置数据库,并设置updaet_date 字段
数据库 字段 ,字段属性 datetim 也可以
在这里插入图片描述
5.配置监听器:打开:web.xml 文件添加如下代码
在这里插入图片描述
代码:

	<listener>
          <listener-class>
                org.apache.solr.handler.dataimport.scheduler.ApplicationListener
          </listener-class>
	</listener>

在这里插入图片描述
mycore/conf 目录下 创建:db-data-congif.xml
在这里插入图片描述
配置如下:

<dataConfig>
    <dataSource driver="com.mysql.jdbc.Driver" 
				url="jdbc:mysql://127.0.0.2:3306/gjjnet?charactorEncoding=utf-8" 
				user="root" 
				password="root" />
    <document>
        <entity name="cms_article" query="select * from cms_article" 
							deltaImportQuery="select * from cms_article  where id ='${dih.delta.id}'"						
							deltaQuery="select id from cms_article where update_date > '${dataimporter.last_index_time}'" 
							pk="id" >
            <field column="id" name="id" />
			<field column="CATEGORY_ID" name="category_id" />
			<field column="TITLE" name="title" />
			<field column="LINK" name="link" />
			<field column="DESCRIPTION" name="description" />
			<field column="IMAGE" name="image" />
			<field column="KEYWORDS" name="keywords" />
			<field column="UPDATE_DATE" name="update_date" />
			<entity name="cms_category" query="select id,module,name,custom_list_view,custom_content_view from cms_category where id ='${cms_article.category_id}'" pk="id" >					
					<field column="MODULE" name="module" />
					<field column="NAME" name="name" />
					<field column="CUSTOM_LIST_VIEW" name="custom_list_view" />
					<field column="CUSTOM_CONTENT_VIEW" name="custom_content_view" />
			</entity>
			<entity name="cms_article_data" query="select content,copyfrom from cms_article_data where id ='${cms_article.id}'" pk="id" >					
					<field column="CONTENT" name="content" />
					<field column="COPYFROM" name="copyfrom" />
			</entity>
		</entity>
    </document>
</dataConfig>

mycore/conf 目录下 managed-schema 添加如下代码

<field name="category_id" type="string" indexed="true" stored="true"/>
	<field name="title" type="text_ik" indexed="true" stored="true"/>
	<field name="link" type="string" indexed="true" stored="true"/>
	<field name="description" type="text_ik" indexed="true" stored="true"/>
	<field name="image" type="string" indexed="true" stored="true"/>
	<field name="keywords" type="string" indexed="true" stored="true"/>
	<field name="update_date" type="date" indexed="true" stored="true"/>
	 
	<field name="module" type="string" indexed="false" stored="true"/>
	<field name="name" type="string" indexed="false" stored="true"/>
	<field name="custom_list_view" type="string" indexed="true" stored="false"/>
	<field name="custom_content_view" type="string" indexed="true" stored="false"/>
	
	<field name="content" type="string" indexed="false" stored="true"/>
	<field name="copyfrom" type="string" indexed="false" stored="true"/>
	
    <!-- 索引复制,联合索引 -->
   <field name="keyword" type="text_ik" indexed="true" stored="true" omitNorms="true" multiValued="true"/>
   <copyField source="id" dest="keyword" maxChars="30000"/>
   <copyField source="title" dest="keyword" maxChars="30000"/>
   <copyField source="description" dest="keyword" maxChars="30000"/>
	

	<fieldType name="date" class="solr.TrieDateField" precisionStep="0" positionIncrementGap="0"/>

在这里插入图片描述
在 和 mycore 的同级目录下创建conf 文件夹 在conf目录里创建 dataimport.properties
在这里插入图片描述
黏贴如下内容:

#################################################

#                                               #

#       dataimport scheduler properties         #

#                                               #

#################################################

 

#  to sync or not to sync

#  1 - active; anything else - inactive

syncEnabled=1

 

#  which cores to schedule

#  in a multi-core environment you can decide which cores you want syncronized

#  leave empty or comment it out if using single-core deployment
#  多核心,在多个核心的情况下,有哪些核心需要参与到这次自动更新,逗号是分隔符
syncCores=mycore

 

#  solr server name or IP address

#  [defaults to localhost if empty]
#访问ip
server=localhost

 

#  solr server port

#  [defaults to 80 if empty]
#访问端口
port=8983

 

#  application name/context
#  [defaults to current ServletContextListener's context (app) name]
#项目访问名称
webapp=solr

 


#增量更新的url参数
params=/dataimport?command=delta-import&clean=false&commit=true

#增量更新的时间间隔,分钟数,为空则默认30分钟
interval=1

 

#  重做索引的时间间隔,单位分钟,默认7200,即5天;
#  为空,为0,或者注释掉:表示永不重做索引
reBuildIndexInterval=7200

 

#  重做全量索引的参数
reBuildIndexParams=/dataimport?command=full-import&clean=true&commit=true

 

#  重做索引时间间隔的计时开始时间,第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000;
#  两种格式:2012-04-11 03:10:00 或者  03:10:00,后一种会自动补全日期部分为服务启动时的日期

reBuildIndexBeginTime=03:10:00

至此,solr配置基本完成
java后台代码我也发一下:ssm集成solr的,

首先引入依赖:

	<!-- Solr -->
		<dependency>
			<groupId>org.apache.solr</groupId>
			<artifactId>solr-solrj</artifactId>
			<version>7.4.0</version>
		</dependency>

xml配置:

  <!-- Solr bean 注入配置	-->
    <bean id="httpSolrClient" class="org.apache.solr.client.solrj.impl.HttpSolrClient">
        <constructor-arg index="0" value="http://127.0.0.1:8983/solr/"/>
    </bean>

model 实体类我就不放了,根据自己业务来写

服务层代码

package com.thinkgem.jeesite.modules.cms.service;

import com.thinkgem.jeesite.modules.cms.entity.Article;
import com.thinkgem.jeesite.modules.cms.entity.ArticleData;
import com.thinkgem.jeesite.modules.cms.entity.Category;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
//@Transactional(readOnly = true)
public class SolrService {

    @Autowired
    private SolrClient client;

    /**
     * 高亮查询
     * @param collection
     * @param q
     * @param field
     * @return
     * @throws IOException
     * @throws SolrServerException
     */
    public List<Article> querySolr(String collection, String q, String field) throws IOException, SolrServerException {
        SolrQuery params = new SolrQuery();
        //查询条件, 这里的 q 对应 下面图片标红的地方
        params.set("q", q);
        //过滤条件
        // params.set("fq", "product_price:[100 TO 100000]");
        //排序
        // params.addSort("id", SolrQuery.ORDER.asc);
        //分页
        params.setStart(0);
        params.setRows(20);
        //默认域
        params.set("df", field);
        //只查询指定域
        // params.set("fl", content + ",content,id,title,author");
        //高亮
        //打开开关
        params.setHighlight(true);
        //指定高亮域
        params.addHighlightField("id");
        params.addHighlightField(field);
        params.addHighlightField("title");
        params.addHighlightField("description");
       // params.addHighlightField("author");

      //  params.addHighlightField("productName");
      //  params.addHighlightField("productDesc");

        //设置前缀
        params.setHighlightSimplePre("<span style='color:red'>");
        //设置后缀
        params.setHighlightSimplePost("</span>");

        QueryResponse queryResponse = client.query(collection,params);

        SolrDocumentList results = queryResponse.getResults();


        long numFound = results.getNumFound(); // 查询到的结果
        //获取高亮显示的结果, 高亮显示的结果和查询结果是分开放的
        Map<String, Map<String, List<String>>> highlight = queryResponse.getHighlighting();
        List articles = new ArrayList();
        for(SolrDocument result : results){ // 将高亮结果合并到查询结果中
            result.remove("keyword");
            highlight.forEach((k,v) ->{
                if(result.get("id").equals(k)){
                    v.forEach((k1,v1) -> {
                        if(!k1.equals("keyword")) result.setField(k1,v1); // 高亮列合并如结果
                    });
                }
            });

            Article article = (Article) toBean(result,Article.class);

            article.setId((String)result.get("id"));
            article.setUpdateDate((Date) result.get("update_date"));
            String category_id = (String)result.get("category_id");

            if(result.get("module") != null){
                article.setCategory(new Category(category_id,(String)result.get("module")));
            }else {
                article.setCategory(new Category((String)result.get("category_id")));
            }
            if (result.get("content") != null && result.get("copyfrom") != null){
                article.setArticleData(new ArticleData((String)result.get("content"),(String)result.get("copyfrom")));
            }
            article.setLink(article.getUrl());
            articles.add(article);
           //System.out.println(articles.toString());
        }


        return articles;
    }
    public static Object toBean(SolrDocument record, Class clazz){
        Object obj = null;
        try {
            obj = clazz.newInstance();
        } catch (InstantiationException e1) {
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        }
        Field[] fields = clazz.getDeclaredFields();
        for(Field field:fields){
            Object value = record.get(field.getName());
            try {
                ConvertUtils.register(new DateConverter(null), java.util.Date.class);
                BeanUtils.setProperty(obj, field.getName(), value);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
        return obj;
    }



    //根据id查询
    public SolrDocument getById(String collection, String id) throws IOException, SolrServerException {
        return client.getById(id);
    }


    //删除全部索引
    public void deleteAll(String collection) throws IOException, SolrServerException {
        client.deleteByQuery(collection,"*:*");
        client.commit(collection);
    }






}

控制层代码

package com.thinkgem.jeesite.modules.cms.web.front;

import com.thinkgem.jeesite.modules.cms.entity.Article;
import com.thinkgem.jeesite.modules.cms.entity.Category;
import com.thinkgem.jeesite.modules.cms.entity.Site;
import com.thinkgem.jeesite.modules.cms.service.SolrService;
import com.thinkgem.jeesite.modules.cms.utils.CmsUtils;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;

@Controller
@RequestMapping(value = "${frontPath}")
public class SolrController {

    private final String db_core = "mycore";

//    @Autowired
//    private SolrClient client;

    @Autowired
    private SolrService solrService;

//    @RequestMapping("")
//    public ModelAndView index1(){
//        ModelAndView mav = new ModelAndView("sear");
//        return mav;
//    }

    @RequestMapping("searchResult")
    public ModelAndView index2(String keyword) {
        Site site = CmsUtils.getSite(Site.defaultSiteId());
        List<Category> mainNavList = CmsUtils.getMainNavList(Site.defaultSiteId());
        ModelAndView mav = new ModelAndView("modules/cms/front/themes/basic/searchResult");
        mav.addObject("site", site);
        mav.addObject("isIndex", true);
        mav.addObject("mainNavList", mainNavList);
//        try {
//            keyword = new String(keyword.getBytes("iso-8859-1"), "UTF-8");
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        System.out.println(keyword);
        mav.addObject("keyword", keyword);
        return mav;
    }

    @RequestMapping("search/{q}")
    @ResponseBody
    public List<Article> search(@PathVariable String q) {
        List<Article> articles = null;
        try {
//            q = new String(q.getBytes("iso-8859-1"), "UTF-8");
            articles = solrService.querySolr(db_core, q, "keyword");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SolrServerException e) {
            e.printStackTrace();
        }
        //System.out.println("articles:" + querySolr.toString());

        return articles;
    }


}

视图层代码:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/modules/cms/front/include/taglib.jsp" %>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title> 欢迎光临 - ${site.title} - Powered By gjjnet</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=no"/>
    <%@include file="/WEB-INF/views/modules/cms/front/include/head.jsp" %>
    <!-- Baidu tongji analytics -->
    <script>var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?82116c626a8d504a5c0675073362ef6f";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();

    function fixedtop() {
        $("html,body").animate({scrollTop: "0px"});
    }

    $(window).scroll(function () {
        if ($(window).scrollTop() > 300) {
            $('.fixed_top').removeClass('fixed_top_ot')
        } else {
            $('.fixed_top').addClass('fixed_top_ot')
        }
    });
    </script>

</head>
<body>
<div class="hpf_logohead">
    <div class="container asd">
        <div class="navbar-header">
            <div class="col-md-12">
                <a class="hidden-sm hidden-xs">
                    <img alt="Brand" class="logoimg" src="${ctxStatic}/bootstrap/2.3.1/css_cerulean/img/logos.png">
                </a>
                <a class="logoinfo aa">
                    <img alt="Brand" class="logorimg" src="${ctxStatic}/bootstrap/2.3.1/css_cerulean/img/logor.png">
                </a>
            </div>
        </div>

        <div class="nav_time hidden-xs hidden-sm" style="margin-top: 22px">
            <div id="pDate" style="color: #ffffff;margin-right: -6px;"></div>
            <c:if test="${sessionScope.user_session.userAccount=='' || sessionScope.user_session.userAccount==undefined || sessionScope.user_session.userAccount==null}">
                <c:if test="${sessionScope.qquserInfo.nickname=='' || sessionScope.qquserInfo.nickname==undefined || sessionScope.qquserInfo.nickname==null}">
                    <c:if test="${sessionScope.wbuserInfo.screenName=='' || sessionScope.wbuserInfo.screenName==undefined || sessionScope.wbuserInfo.screenName==null}">

                        <div id="loginbtn" style="height: 50px;"><a href="${ctx}/login"
                                                                    style="color: #ffffff;">登录/注册</a></div>
                    </c:if></c:if></c:if>

            <div id="loginout" style="height: 50px; ">
                <c:if test="${(sessionScope.user_session.userAccount!='' && sessionScope.user_session.userAccount!=undefined && sessionScope.user_session.userAccount!=null)}">
                    <scpan style="color: #ffffff">
                        用户名:${sessionScope.user_session.userAccount}${sessionScope.qquserInfo.nickname}${sessionScope.wbuserInfo.screenName}</scpan>
                    <a href="${ctx}/loginout" style="color: #ffffff;">退出</a>
                </c:if>
                <c:if test="${sessionScope.qquserInfo.nickname!='' && sessionScope.qquserInfo.nickname!=undefined && sessionScope.qquserInfo.nickname!=null}">
                    <scpan style="color: #ffffff">用户名:${sessionScope.qquserInfo.nickname}</scpan>
                    <a href="${ctx}/loginout" style="color: #ffffff;">退出</a>
                </c:if>
                <c:if test="${sessionScope.wbuserInfo.screenName!='' && sessionScope.wbuserInfo.screenName!=undefined && sessionScope.wbuserInfo.screenName!=null}">
                <scpan style="color: #ffffff">用户名:${sessionScope.wbuserInfo.screenName}</scpan>
                <a href="${ctx}/loginout" style="color: #ffffff;">退出</a>
            </div>
            </c:if>

            <div style="margin-right: 22px;width: 365px;height:40px;border: black solid 1px;background-color: white;border-radius: 5px">

                <input type="text" class="form-control" placeholder="输入关键字搜索" value="" required="" id="keywordTop"
                       style="width: 310px;height:35px; display: inline;border: none;box-shadow: none;">
                <button type="button" onclick="search(1);"
                        style="float: right; width: 40px;height:35px;display: inline; cursor: pointer;border: none;outline: none; background: url(${ctxStatic}/images/2020041023154572317.png) no-repeat center">
                </button>
            </div>
            <%--            <div >--%>
            <%--                <input type="text" class="form-control" placeholder="输入关键字搜索" value="${keyword}" required="" id="keyword" style="width: 300px; display: inline">--%>
            <%--                <button type="button" onclick="search();" style="width: 60px;height:30px;display: inline;color: #0d0d0d">搜索</button>--%>
            <%--            </div>--%>
        </div>
    </div>
</div>


<div class="hpf_nav">
    <div class="container asd">
        <ul id="" class="nav hpf_navbar clearfix center_header">
            <li class="${not empty isIndex && isIndex ? 'active' : ''}"><a
                    href="${ctx}/index-1${fns:getUrlSuffix()}"><span>${site.id eq '1'?'首  页':'返回主站'}</span></a>
            </li>
            <c:forEach items="${fnc:getMainNavList(site.id)}" var="category" varStatus="status">
                <c:if test="${status.index lt 7}">
                    <c:set var="menuCategoryId" value=",${category.id},"/>
                    <li class="${requestScope.category.id eq category.id||fn:indexOf(requestScope.category.parentIds,menuCategoryId) ge 1?'active':''}">
                        <c:if test="${category.name eq '聚焦公积金'}">
                            <a href="${ctx}/more" target="${category.target}">
                                <span>${category.name}</span>
                            </a>
                        </c:if>
                        <c:if test="${category.name ne '聚焦公积金'}">
                            <a href="${category.url}" target="${category.target}">
                                <span>${category.name}</span>
                            </a>
                        </c:if>
                    </li>
                </c:if>
            </c:forEach>
        </ul>
    </div>
</div>
<%-- 手机端首页的头部--%>
<div class="ios_header">
    <a class="aa">
        <img alt="Brand" class="logorimg" src="${ctxStatic}/bootstrap/2.3.1/css_cerulean/img/logor.png">
    </a>
    <div class="menu_btn">
        <i class="iconfont iconlist2"></i>
    </div>
</div>
<%-- 手机端首页的头部--%>


<div class="content">
    <div class="container">
        <div style="margin-top: 20px">
            <input type="text" class="form-control" placeholder="输入关键字搜索" value="${keyword}" required="" id="keyword"
                   style="display: inline;width: 50%; height: 50px;line-height: 50px;padding: 0 20px;font-size: 16px; border: 1px solid #ddd;outline: 0;">
            <button type="button" onclick="search(2);"
                    style="display: inline;width: 100px; height: 50px;font-size: 16px; letter-spacing: 5px; border: none; text-indent: 5px; background: #0d63b0; color: #fff;">
                搜索
            </button>
        </div>
        <div style="height: 45px;margin-top: 20px"><span id="numFound" style="color: #999;"></span></div>
        <div class="" id="coreDiv"></div>
    </div>
    <hr style="margin:20px 0 10px;">
</div>

<%--solr 结果  start--%>
<div class=" " id="contentDiv" style="display: none">

    <div class="detail">

        <p>
            <spqn id="copyfrom"></spqn>
            <a href="" id="title" style="font-size: 22px;color: #0000cc"></a>
        </p>
        <br/>
        <p id="description"></p>
        <p class="footer ">
            <a href="#" id="keywords"></a> &nbsp;&nbsp; <a href="#" id="updateDate"></a>
        </p>
        <br/>
    </div>
</div>
<%--solr 结果  end--%>
<!-- /container -->
<div class="footer_info">
    <div class="container asd">
        <div class="row">
            <div class="col-md-12">
                <div class="foot_content">
                    <div class="foot_info clearfix">
                        <div class="clearfix">
                            <ul class="foot_ul clearfix">
                                <li><a href="${ctx}/guestbook" target="_blank">公共留言</a></li>
                                <li><a href="${ctx}/search" target="_blank">全站搜索</a></li>
                                <li><a href="${ctx}/map-${site.id}${fns:getUrlSuffix()}" target="_blank">站点地图</a></li>
                                <li><a href="mailto:thinkgem@163.com">技术支持</a></li>
                                <li class="youqing"><a href="javascript:;">友情链接</a></li>
                            </ul>
                            <div class="erweima">
                                <img src="${ctxStatic}/bootstrap/2.3.1/css_cerulean/img/erweima.png" alt="基正科技">
                            </div>
                        </div>
                        <div class="youqinglianjie ">
                            <ul class="shenghui clearfix">
                                <li>河南省</li>
                                <li>湖北省</li>
                                <li>天津省</li>
                                <li>辽宁省</li>
                                <li>河南省</li>
                                <li>湖北省</li>
                                <li>天津省</li>
                                <li>辽宁省</li>
                                <li>河南省</li>
                                <li>湖北省</li>
                                <li>天津省</li>
                                <li>辽宁省</li>
                            </ul>
                            <ul class="chengshi clearfix">
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                                <li><a href="javascript:;">郑州市</a></li>
                            </ul>
                        </div>
                    </div>

                    <div class="statement">
                        <ul class="foot_ul2 clearfix">
                            <li>联系电话:0371-685698458</li>
                            <li>服务邮箱:gjjmhw@163.com</li>
                            <li>豫ICP备06000497号</li>
                        </ul>
                        <div class="copyright">${site.copyright}</div>
                    </div>
                </div>
            </div>
            <%--			<div class="col-md-4 m_top">--%>

            <%--			</div>--%>
        </div>
    </div>
</div>
<div class="fixed_top fixed_top_ot">
    <span class="iconfont iconfanhuidingbu fixed_icon" onclick="fixedtop()"></span>
</div>


<script>

    $('.copyright a span').css('color', '#ffffff')

    //  手机端的按钮菜单
    $('.ios_header .menu_btn').click(function () {
        $('html, body').css({"height": "100%", "width": "100%", "overflow": "hidden"})
        // $('.hpf_nav').css('display','block')
        // $('.hpf_nav').append("<div class='guanbi'>×</div>")
        $('.guanbi').click(function () {
            $('html, body').css({"height": "auto", "width": "auto", "overflow": "auto"})
            // $('.hpf_nav').css('display','none')
        })
    })

    //设置高度
    if (window.screen.width < 600) {
        var contheight = window.screen.height - $(".ios_header").height() - $('.footer_info').height()
    } else {
        var contheight = document.documentElement.clientHeight - $(".hpf_logohead").height() - $('.footer_info').height()
    }
    $('.content').css('min-height', contheight)

    //获取当前农历日期

    var sWeek = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
    var dNow = new Date();
    var CalendarData = new Array(100);
    var madd = new Array(12);
    var tgString = "甲乙丙丁戊己庚辛壬癸";
    var dzString = "子丑寅卯辰巳午未申酉戌亥";
    var numString = "一二三四五六七八九十";
    var monString = "正二三四五六七八九十冬腊";
    var sx = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
    var cYear, cMonth, cDay, TheDate;
    CalendarData = new Array(0xA4B, 0x5164B, 0x6A5, 0x6D4, 0x415B5, 0x2B6, 0x957, 0x2092F, 0x497, 0x60C96, 0xD4A, 0xEA5, 0x50DA9, 0x5AD, 0x2B6, 0x3126E, 0x92E, 0x7192D, 0xC95, 0xD4A, 0x61B4A, 0xB55, 0x56A, 0x4155B, 0x25D, 0x92D, 0x2192B, 0xA95, 0x71695, 0x6CA, 0xB55, 0x50AB5, 0x4DA, 0xA5B, 0x30A57, 0x52B, 0x8152A, 0xE95, 0x6AA, 0x615AA, 0xAB5, 0x4B6, 0x414AE, 0xA57, 0x526, 0x31D26, 0xD95, 0x70B55, 0x56A, 0x96D, 0x5095D, 0x4AD, 0xA4D, 0x41A4D, 0xD25, 0x81AA5, 0xB54, 0xB6A, 0x612DA, 0x95B, 0x49B, 0x41497, 0xA4B, 0xA164B, 0x6A5, 0x6D4, 0x615B4, 0xAB6, 0x957, 0x5092F, 0x497, 0x64B, 0x30D4A, 0xEA5, 0x80D65, 0x5AC, 0xAB6, 0x5126D, 0x92E, 0xC96, 0x41A95, 0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5, 0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95);
    madd[0] = 0;
    madd[1] = 31;
    madd[2] = 59;
    madd[3] = 90;
    madd[4] = 120;
    madd[5] = 151;
    madd[6] = 181;
    madd[7] = 212;
    madd[8] = 243;
    madd[9] = 273;
    madd[10] = 304;
    madd[11] = 334;

    function GetBit(m, n) {
        return (m >> n) & 1;
    }

    function e2c() {
        TheDate = (arguments.length != 3) ? new Date() : new Date(arguments[0], arguments[1], arguments[2]);
        var total, m, n, k;
        var isEnd = false;
        var tmp = TheDate.getFullYear();
        total = (tmp - 1921) * 365 + Math.floor((tmp - 1921) / 4) + madd[TheDate.getMonth()] + TheDate.getDate() - 38;
        if (TheDate.getYear() % 4 == 0 && TheDate.getMonth() > 1) {
            total++;
        }
        for (m = 0; ; m++) {
            k = (CalendarData[m] < 0xfff) ? 11 : 12;
            for (n = k; n >= 0; n--) {
                if (total <= 29 + GetBit(CalendarData[m], n)) {
                    isEnd = true;
                    break;
                }
                total = total - 29 - GetBit(CalendarData[m], n);
            }
            if (isEnd) break;
        }
        cYear = 1921 + m;
        cMonth = k - n + 1;
        cDay = total;
        if (k == 12) {
            if (cMonth == Math.floor(CalendarData[m] / 0x10000) + 1) {
                cMonth = 1 - cMonth;
            }
            if (cMonth > Math.floor(CalendarData[m] / 0x10000) + 1) {
                cMonth--;
            }
        }
    }

    /*戊戌狗年 腊月廿*/
    function GetcDateString() {
        var tmp = "";
        tmp += tgString.charAt((cYear - 4) % 10);
        tmp += dzString.charAt((cYear - 4) % 12);
        tmp += "  ( " + sx.charAt((cYear - 4) % 12) + " )  ";
        tmp += " 年 ";
        if (cMonth < 1) {
            tmp += "(闰)";
            tmp += monString.charAt(-cMonth - 1);
        } else {
            tmp += monString.charAt(cMonth - 1);
        }
        tmp += "月";
        tmp += (cDay < 11) ? "初" : ((cDay < 20) ? "十" : ((cDay < 30) ? "廿十" : "三十"));
        if (cDay % 10 != 0 || cDay == 10) {
            tmp += numString.charAt((cDay - 1) % 10);
        }
        return tmp;
    }

    function GetLunarDay(solarYear, solarMonth, solarDay) {
        if (solarYear < 1921 || solarYear > 2020) {
            return "";
        } else {
            solarMonth = (parseInt(solarMonth) > 0) ? (solarMonth - 1) : 11;
            e2c(solarYear, solarMonth, solarDay);
            return GetcDateString();
        }
    }


    function getFullYear(d) { // 修正firefox下year错误
        yr = d.getYear();
        if (yr < 1000) yr += 1900;
        return yr;
    }

    /*写入页面*/
    function showDate() {

        var D = new Date();
        var yy = D.getFullYear();
        var mm = D.getMonth() + 1;
        var dd = D.getDate();
        var ww = D.getDay();
        var ss = parseInt(D.getTime() / 1000);
        var h = D.getHours();
        var m = D.getMinutes();
        var s = D.getSeconds();

        var sValue = getFullYear(dNow) + "年" + (dNow.getMonth() + 1) + "月" + dNow.getDate() + "日" + " " + sWeek[dNow.getDay()] + " ";
        sValue += " 【 " + GetLunarDay(yy, mm, dd) + "  】 ";
        // sValue += shapetime(h,m,s);
        document.getElementById("pDate").innerHTML = sValue;
        setTimeout("showDate()", 500);
    };

    /*格式化时间*/
    function shapetime(h, m, s) {
        if (s <= 9) s = "0" + s;
        if (m <= 9) m = "0" + m;
        if (h <= 9) h = "0" + h;
        return h + ":" + m + ":" + s
    }

    //	底部友情链接
    var youqing = 0
    $('.youqing').click(function () {
        if (youqing == 0) {
            $('.youqinglianjie ').css('display', 'block')
            youqing++
        } else {
            $('.youqinglianjie').css('display', 'none')
            youqing = 0
        }
    })

    $('.shenghui').on('click', 'li', function () {
        $(this).index()
        alert($(this).index())
    })

    /**
     *  搜索框
     */
    function search(whichOne) {

        var keyword = "";
        if (whichOne == 1) {
            keyword = $("#keywordTop").val();
        }
        if (whichOne == 2) {
            keyword = $("#keyword").val();
        }

        if ($.trim(keyword) == "") {
            alert("关键字不能为空。");
            return;
        }

        var url = "${ctx}/search/" + keyword;

        $.get(url, function (data) {
            $("#coreDiv").empty();
            $("#numFound").html("相关结果:" + data.length + "个");

            $.each(data, function (i, d) {
                var template = $("#contentDiv").clone();
                //0.来源
                if (d.articleData != '' && d.articleData != undefined) {

                    if (d.articleData.copyfrom != '' && d.articleData.copyfrom != undefined) {
                        template.find("#copyfrom").html("来源:" + d.articleData.copyfrom).attr('style', 'background-color: #d30b15; padding: 4px;color: #fff;font-size: 16px;');
                    }
                }
                // 1、标题
                if (d.title != '' && d.title != undefined) template.find("#title").html(d.title);
                if (d.link != '' && d.link != undefined) template.find("#title").attr('href', d.link);
                // 2、描述
                template.find("#description").html(d.description + d.description);
                // 3、作者
                if (d.keywords != '' && d.keywords != undefined) template.find("#keywords").html("作者:" + d.keywords);
                template.find("#updateDate").text(d.updateDate);
                template.show();
                //var html = template.html().replace(new RegExp('undefined','gm'),'')
                $("#coreDiv").append(template);
            })
        })
    }

    /**
     * 绑定键盘enter
     */
    // $('#keyword').keypress(function(event) {
    //     if (event.which == "13") {
    //         search();
    //     }
    // })
    //
    // $('#keywordTop').keypress(function(event) {
    //     if (event.which == "13") {
    //         search();
    //     }
    // })

    window.onload = function () {
        showDate();
        search(2);
    }

</script>
</body>
</html>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值