精华内容
下载资源
问答
  • SpringBoot集成Solr

    2020-09-03 16:45:25
    SpringBoot集成Solrsolr搜索引擎搭建详细过程多字段匹配配置到springboot项目中 solr小白,所以查了很多相关的博客,最终在项目中实现了全文搜索,思路大概为:下载solr,然后配置到Tomcat,在solr中先实现分词和全局...

    solr小白,所以查了很多相关的博客,最终在项目中实现了全文搜索,思路大概为:下载solr,然后配置到Tomcat,在solr中先实现分词和全局查询,再配置到项目中,代码控制即可。

    solr搜索引擎搭建详细过程

    参考:solr搜索引擎搭建详细过程

    多字段匹配

    schema.xml文件中做类似的配置

    <!-- tbaclarea -->
    	 <field name="pid" type="text_ik" indexed="true" stored="true"/>  
    	 <field name="shortname" type="text_ik" indexed="true" stored="true"/>  
    	 <field name="longitude" type="text_ik" indexed="true" stored="true"/>  
    	 <field name="latitude" type="text_ik" indexed="true" stored="true"/> 
    	 <field name="level" type="text_ik" indexed="true" stored="true"/> 
    	 <field name="sort" type="text_ik" indexed="true" stored="true"/> 
    	 <field name="status" type="text_ik" indexed="true" stored="true"/> 
    	 <!-- 综合查询-->
    	<field name="fault_all" type="text_ik" indexed="true" stored="true" multiValued="true"/>
    	
    	<!-- 将fault_name的分词复制到fault_reason、fault_solve中 按照fault_name检索时会检索这两个字段 -->
    	<defaultSearchField>fault_all</defaultSearchField>
    	<solrQueryParser defaultOperator="AND"/>
    	<copyField source="pid" dest="fault_all"/>
    	<copyField source="name" dest="fault_all"/>
    	<copyField source="shortname" dest="fault_all"/>
    	<copyField source="longitude" dest="fault_all"/>
    	<copyField source="latitude" dest="fault_all"/>
    	<copyField source="level" dest="fault_all"/>
    	<copyField source="sort" dest="fault_all"/>
    	<copyField source="status" dest="fault_all"/>
    

    配置到springboot项目中

    pom.xml中添加如下依赖

    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter-data-solr</artifactId>
    </dependency>
    

    application.yml中做如下配置

    spring:
      application:
        name: solr
      data:
        solr:
          host: http://127.0.0.1:8080/solr
    

    实体类文件

    package com.fc.test.model.auto;
    
    import org.apache.solr.client.solrj.beans.Field;
    import org.springframework.data.annotation.Id;
    import org.springframework.data.solr.core.mapping.Indexed;
    import org.springframework.data.solr.core.mapping.SolrDocument;
    import java.io.Serializable;
    import java.util.Date;
    
    @SolrDocument(collection="collection1")
    public class SolrTbAclUser implements Serializable {
    
        /** 人员uuid **/
        //@ApiModelProperty(value = "人员uuid")
        @Field("id")
        @Id
        private String useruuid;
    
        /** 用户名 **/
        //@ApiModelProperty(value = "用户名")
        @Indexed
        private String username;
    
        /** 登录名 **/
        //@ApiModelProperty(value = "登录名")
        @Indexed
        private String userlogin;
        
        ...
    

    实现类

    package com.fc.test.service;
    
    import com.fc.test.model.auto.SolrTbAclUser;
    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.data.domain.Page;
    import org.springframework.data.domain.Sort;
    import org.springframework.data.solr.core.SolrTemplate;
    import org.springframework.data.solr.core.query.SimpleQuery;
    import org.springframework.stereotype.Service;
    
    import java.io.IOException;
    import java.util.Collection;
    import java.util.Date;
    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;
    
    @Service
    public class SolrTbAclUserService{
    
        @Autowired
        private SolrClient solrClient;
        public void solrsearchtbacluser() throws IOException, SolrServerException {
            // 设置查询
    //        SolrTbAclUser solrTbAclUser = new SolrTbAclUser();
    //        solrTbAclUser.setUseruuid("admin74578578578578");
    //        solrTbAclUser.setCreateTime(new Date());
    //        solrTbAclUser.setUserlevel("11");
    //        solrClient.addBean(solrTbAclUser);
    //        solrClient.commit();
    //        String  id ="admin";
    //        SolrDocument solrDocument = solrClient.getById(id);
    
            SolrQuery query = new SolrQuery();
            query.set("q","user_all:物流*");
            //设置每页显示多少条
            query.setRows(10);
            //发起搜索请求
            QueryResponse response = solrClient.query(query);
    
            SolrDocumentList docs = response.getResults();
    
            // 查询结果总数
            long cnt = docs.getNumFound();
            System.out.println("总条数为"+cnt+"条");
            for (SolrDocument doc : docs) {
                System.out.println("object:"+ doc);
                System.out.println("fieldValueMap======"+doc.getFieldValueMap());
            }
            System.out.println("byobject=================="+docs);
            solrClient.close();
            //获取filedName
    //        Collection<String> fieldNames = solrDocument.getFieldNames();
            //获取file名和内容
    //        Map<String, Object> fieldValueMap = solrDocument.getFieldValueMap();
            //            int childDocumentCount = solrDocument.getChildDocumentCount();
    
    //        List<SolrDocument> childDocuments = solrDocument.getChildDocuments();
    //        System.out.println("byId=================="+solrDocument);
    //        System.out.println("fieldNames=================="+fieldNames);
    //        System.out.println("fieldValueMap=================="+fieldValueMap);
    //            System.out.println("childDocumentCount=================="+childDocumentCount);
    //        System.out.println("childDocuments=================="+childDocuments);
        }
    }
    
    展开全文
  • springboot 集成solr

    2019-08-20 17:01:36
    今天主要研究了一下solr如何集成springboot项目中,实现基本的CRUD。 1、首先向solr中导入mysql中的数据,用于开发测试。在solrhome文件夹中,找到conf文件夹,修改data-config.xml <dataConfig> <!-...

    对于solr的安装和基础入门,今天就不多说了,可以去看之前写的文章。今天主要研究了一下solr如何集成到springboot项目中,实现基本的CRUD。

    1、首先向solr中导入mysql中的数据,用于开发测试。在solrhome文件夹中,找到conf文件夹,修改data-config.xml

    <dataConfig>
        <!-- 这是mysql的配置,学会jdbc的都应该看得懂 -->
        <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/moe-csdp-test" user="root" password="Root123!"/>
        <document>
            <!-- name属性,就代表着一个文档,可以随便命名 -->
            <!-- query是一条sql,代表在数据库查找出来的数据 -->
            <entity name="product" query="select * from news">
                <!-- 每一个field映射着数据库中列与文档中的域,column是数据库列,name是solr的域(必须是在managed-schema文件中配置过的域才行) -->
                <field column="id" name="id"/>
                <field column="title" name="headline"/>
                <field column="introduction" name="introduction"/>
    			<field column="content" name="detail"/>
    			<field column="picture" name="picture"/>
    			<field column="upload_time" name="upload_time"/>
    			<field column="browser" name="browser"/>
    			<field column="isdisplayed" name="isdisplayed"/>
            </entity>
        </document>
    </dataConfig>

    2、data-config.xml中的name是solr的域,所以必须是在managed-schema文件中配置过相应的域才可以使用。对于managed-schema文件中各个标签的作用,在之前的solr基础中也有过记录。贴出部分代码

    <!-- moe-csdp-test数据库news表导入solr-->
    	<field name="headline" type="text_ik" indexed="true" stored="true"/>
    	<field name="introduction" type="text_ik" indexed="true" stored="true"/>
    	<field name="detail" type="text_ik" indexed="true" stored="true"/>
    	<field name="picture" type="text_ik" indexed="true" stored="true"/>
    	<field name="upload_time" type="text_ik" indexed="true" stored="true"/>
    	<field name="browser" type="text_ik" indexed="true" stored="true"/>
    	<field name="isdisplayed" type="text_ik" indexed="true" stored="true"/>

    这里使用的类型是ik分词器,由于分词器类型一旦设置,想要修改只能是重新导入数据,所以一定要提前想好。

     3、导入maven依赖

    <!-- springboot 集成solr-->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-data-solr</artifactId>
    		</dependency>

    4、配置 文件中配置solr

    #solr集成配置
    spring.data.solr.host=http://127.0.0.1:9006/solr/core1

     5、创建相应的实体bean,可以是我们springboot+mybatis正常CRUD的实体类,只不过需要指定需要映射的solr核心core。还需要将属性和solr字段对应。

    /**
     * 可以在实体类上添加上@SolrDocument(solrCoreName = "custom_core")这个注解,表明这个实体类可以转换成SolrDocument对象,
     * 此外一定不要忘了指定core的名称。如果实体类属性和solr的field对应不上,可以使用@Field(value="field名称")注解,
     * 实现实体类和solr field之间的对应关系。这样在像solr添加User对象的时候就不需要手动将其转换为SolrDocument了
     * @SolrDocument(solrCoreName = "custom_core")
        public class User {
    
        @Id
        @Field
        private int id;
        @Field
        private String userName;
        @Field
        private String sex;
    }
     */
    @SolrDocument(solrCoreName = "core1")
    public class News implements Serializable {
        @Id
        @Field
        private Integer id;
    
        @Field(value="headline")
        private String title;
    
        @Field
        private String introduction;
    
        @Field
        private String picture;
        
        private String picture1;
        
        private String picture2;
    
        @Field(value = "upload_time")
        private String uploadTime;
    
        private Date time;
    
        @Field
        private Integer browser;
    
        private Integer type;
    
        private String source;
    
        private String author;
    
        @Field
        private Integer isdisplayed;
    
        private Integer displayOrder;
    
        @Field(value = "detail")
        private String content;
        
        public Integer counts;
        
        private String recommend;
        
        private String link;
        
        private String label;
    
        public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }
    
        public String getLabel() {
    		return label;
    	}
    
    	public void setLabel(String label) {
    		this.label = label;
    	}
    
    	public String getTitle() {
            return title;
        }
    
        public void setTitle(String title) {
            this.title = title == null ? null : title.trim();
        }
    
        public String getIntroduction() {
            return introduction;
        }
    
        public void setIntroduction(String introduction) {
            this.introduction = introduction == null ? null : introduction.trim();
        }
    
        public String getPicture() {
            return picture;
        }
    
        public void setPicture(String picture) {
            this.picture = picture == null ? null : picture.trim();
        }
    
        public String getUploadTime() {
    		return uploadTime;
    	}
    
    	public void setUploadTime(String uploadTime) {
    		this.uploadTime = uploadTime;
    	}
    
    	public Date getTime() {
            return time;
        }
    
        public void setTime(Date time) {
            this.time = time;
        }
    
        public Integer getBrowser() {
            return browser;
        }
    
        public void setBrowser(Integer browser) {
            this.browser = browser;
        }
    
        public Integer getType() {
            return type;
        }
    
        public void setType(Integer type) {
            this.type = type;
        }
    
        public String getSource() {
            return source;
        }
    
        public void setSource(String source) {
            this.source = source == null ? null : source.trim();
        }
    
        public String getAuthor() {
            return author;
        }
    
        public void setAuthor(String author) {
            this.author = author == null ? null : author.trim();
        }
    
        public Integer getIsdisplayed() {
            return isdisplayed;
        }
    
        public void setIsdisplayed(Integer isdisplayed) {
            this.isdisplayed = isdisplayed;
        }
    
        public Integer getDisplayOrder() {
    		return displayOrder;
    	}
    
    	public void setDisplayOrder(Integer displayOrder) {
    		this.displayOrder = displayOrder;
    	}
    
    	public String getContent() {
            return content;
        }
    
        public void setContent(String content) {
            this.content = content == null ? null : content.trim();
        }
    
    	public Integer getCounts() {
    		return counts;
    	}
    
    	public void setCounts(Integer counts) {
    		this.counts = counts;
    	}
    
    	public String getRecommend() {
    		return recommend;
    	}
    
    	public void setRecommend(String recommend) {
    		this.recommend = recommend;
    	}
    
    	public String getPicture1() {
    		return picture1;
    	}
    
    	public void setPicture1(String picture1) {
    		this.picture1 = picture1;
    	}
    
    	public String getPicture2() {
    		return picture2;
    	}
    
    	public void setPicture2(String picture2) {
    		this.picture2 = picture2;
    	}
    
    	public String getLink() {
    		return link;
    	}
    
    	public void setLink(String link) {
    		this.link = link;
    	}
        
    }

    6、主要使用SolrClient和SolrQuery,我也没有封装,为了方便实践

     

    @Controller
    @RequestMapping("solr")
    public class SolrTestController {
    
        @Autowired
        private SolrClient solrClient;
    
    
        // 根据id查询
        @RequestMapping("queryById")
        @ResponseBody
        public List<News> queryById(int id){
    
            List<News> newsList = new ArrayList<News>();
    
            SolrQuery query = new SolrQuery();
    
            query.setQuery("id:"+String.valueOf(id));
            query.setStart(0);
            query.setRows(10);
    
            try {
                QueryResponse response = solrClient.query(query);
                SolrDocumentList documentList = response.getResults();
                News news ;
                for(SolrDocument document : documentList){
                    news = new News();
                    news.setId(Integer.valueOf(document.getFieldValue("id").toString()));
                    news.setTitle(document.getFieldValue("headline").toString());
                    news.setContent(document.getFieldValue("detail").toString());
                    news.setIntroduction(document.getFieldValue("introduction").toString());
                    news.setPicture(document.getFieldValue("picture").toString());
                    news.setUploadTime(document.getFieldValue("upload_time").toString());
                    news.setBrowser(Integer.valueOf(document.getFieldValue("browser").toString()));
                    news.setIsdisplayed(Integer.valueOf(document.getFieldValue("isdisplayed").toString()));
                    newsList.add(news);
                }
            } catch (SolrServerException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            return newsList;
        }
    
        // 查询全部
        @RequestMapping("queryAll")
        @ResponseBody
        public List<News> queryAll() {
            List<News> resultList1 = new ArrayList<News>();
    
            SolrQuery query = new SolrQuery();
    
            query.setQuery("*:*");
            query.setStart(0);
            query.setRows(20);
    
            try {
                QueryResponse response = solrClient.query(query);
                SolrDocumentList documentList = response.getResults();
                News news;
                for(SolrDocument document : documentList){
                    news = new News();
                    news.setId(Integer.valueOf(document.getFieldValue("id").toString()));
                    news.setTitle(document.getFieldValue("headline").toString());
                    news.setContent(document.getFieldValue("detail").toString());
                    news.setIntroduction(document.getFieldValue("introduction").toString());
                    news.setPicture(document.getFieldValue("picture").toString());
                    news.setUploadTime(document.getFieldValue("upload_time").toString());
                    news.setBrowser(Integer.valueOf(document.getFieldValue("browser").toString()));
                    news.setIsdisplayed(Integer.valueOf(document.getFieldValue("isdisplayed").toString()));
                    resultList1.add(news);
    
                }
            } catch (SolrServerException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            return resultList1;
    
        }
    
        // 向solr中添加对象
        @RequestMapping("add")
        @ResponseBody
        public String add(){
    
            News news = new News();
    
            // 这里的id 暂时自定义,后期实际开发时,不用mysql中自增的id,使用uuid
            news.setId(260);
            news.setTitle("这是向solr添加的第一条数据");
            news.setContent("这是向solr添加的第一条数据");
            news.setIntroduction("这是向solr添加的第一条数据");
            news.setPicture("123456");
            news.setUploadTime("2019-08-20");
            news.setBrowser(20);
            news.setIsdisplayed(1);
    
            try {
                UpdateResponse updateResponse = solrClient.addBean(news);
                int status = updateResponse.getStatus();
                if(status != 0){
                    solrClient.rollback();
                }else {
                    solrClient.commit();
                }
            } catch (IOException e) {
                e.printStackTrace();
            } catch (SolrServerException e) {
                e.printStackTrace();
            }
            return "SUCCESS";
        }
    
        // 搜索功能,模糊查询
        @RequestMapping("search")
        @ResponseBody
        public List<News> search(String key) {
    
            List<News> searchList = new ArrayList<News>();
    
            SolrQuery query = new SolrQuery();
    
            query.setQuery("headline:" + key);
            query.setStart(0);
            query.setRows(10);
    
            try {
                QueryResponse response = solrClient.query(query);
                SolrDocumentList documentList = response.getResults();
                News news;
                for (SolrDocument document : documentList) {
                    news = new News();
                    news.setId(Integer.valueOf(document.getFieldValue("id").toString()));
                    news.setTitle(document.getFieldValue("headline").toString());
                    news.setContent(document.getFieldValue("detail").toString());
                    news.setIntroduction(document.getFieldValue("introduction").toString());
                    news.setPicture(document.getFieldValue("picture").toString());
                    news.setUploadTime(document.getFieldValue("upload_time").toString());
                    news.setBrowser(Integer.valueOf(document.getFieldValue("browser").toString()));
                    news.setIsdisplayed(Integer.valueOf(document.getFieldValue("isdisplayed").toString()));
                    searchList.add(news);
                }
            } catch (SolrServerException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            return searchList;
        }
    }

     

     

     

    展开全文
  • SpringBoot集成solr

    2019-01-21 15:43:56
    1、windows10下配置solr环境,将solr官网下载好的压缩包解压到指定目录,solr的项目结构如下   cmd进入server/solr目录下启动...2、项目集成:  pom.xml文件添加依赖 &lt;dependency&gt; &lt;...

    1、windows10下配置solr环境,将solr官网下载好的压缩包解压到指定目录,solr的项目结构如下

      

    cmd进入server/solr目录下启动solr服务:

    浏览器访问:http://localhost:8983/solr

    创建核心文档

    2、项目集成:

         pom.xml文件添加依赖

     <dependency>
          <groupId>org.springframework.data</groupId>
           <artifactId>spring-data-solr</artifactId>
      </dependency>
    

       application.yml配置

    
    data:
        solr:
          host: http://192.168.168.224:8983/solr/searchList

       业务代码:

         solr工具类

    @Component
    public class SolrUtils {
        private SolrClient solrClient;
        
        private SolrQuery  solrQuery;
        @Autowired
        public SolrUtils(SolrClient solrClient) {
            this.solrClient = solrClient;
            solrQuery = new SolrQuery();
        }
    
        /**
         * 向solr文档中添加对象
         * @param data
         * @throws IOException
         * @throws SolrServerException
         */
        public void addSolrPO(SolrSearchPO data) throws IOException, SolrServerException {
            solrClient.addBean(data);
            solrClient.commit();
        }
    
        /**
         * solr查询
         * @param key  关键字
         * @param page  
         * @param row
         * @return
         * @throws IOException
         * @throws SolrServerException
         */
        public List<SolrSearchPO> queryList(String key,int page,int  row) throws IOException, SolrServerException {
            List<SolrSearchPO> list=new ArrayList<>();
            solrQuery.setQuery(key);
            solrQuery.setStart(page);
            solrQuery.setRows(row);
            //设置高亮字段
            solrQuery.setHighlight(true);
            solrQuery.addHighlightField("name,title");
            solrQuery.setHighlightSimplePre("<font color='red'>");
            solrQuery.setHighlightSimplePost("</font>");
            QueryResponse query = solrClient.query(solrQuery);
            // 文档结果集
            SolrDocumentList docs = query.getResults();
            SolrSearchPO solrSearchPO;
            for (SolrDocument s : docs) {
                solrSearchPO = new SolrSearchPO();
                solrSearchPO.setId(s.getFirstValue("id").toString());
                solrSearchPO.setName(s.getFirstValue("name").toString());
                solrSearchPO.setTitle(s.getFirstValue("title").toString());
                solrSearchPO.setContent(s.getFirstValue("content").toString());
                list.add(solrSearchPO);
            }
            return list;
        }
    
        /**
         * 删除
         * @throws IOException
         * @throws SolrServerException
         */
        public void delDoc() throws IOException, SolrServerException {
            solrClient.deleteByQuery("*:*");
            solrClient.commit();
        }
    }
    

    测试

     

    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class SolrTest {
    
        private Logger logger = LoggerFactory.getLogger(SolrTest.class);
    
        @Autowired
        private SolrUtils solrUtils;
    
        @Autowired
        private ITestService testService;
    
        @Test
        public void addSolr() {
            SolrSearchPO solrSearchPO;
            List<TestPO> allTestPo;
            try {
                allTestPo = testService.findAllTestPo(3);
                for (TestPO t : allTestPo) {
                    solrSearchPO = new SolrSearchPO();
                    solrSearchPO.setId(String.valueOf(t.getId()));
                    solrSearchPO.setName(t.getName());
                    solrSearchPO.setContent(t.getContent());
                    solrSearchPO.setTitle(t.getTitle());
                    solrUtils.addSolrPO(solrSearchPO);
                }
    
            } catch (Exception e) {
                e.printStackTrace();
                logger.error("添加错误--->"+e.toString());
            }
    
    
        }
    
        @Test
        public void queryList() {
            try {
                List<SolrSearchPO> solrSearchPOS = solrUtils.queryList("*:*", 0, 10);
                logger.info("搜索结果集长度---------->size=" + solrSearchPOS.size());
                for (SolrSearchPO s : solrSearchPOS) {
                    logger.info(s.toString());
                }
            } catch (IOException | SolrServerException e) {
                e.printStackTrace();
                logger.info("搜索失败------>e=" + e.toString());
            }
        }
    
        @Test
        public void del() {
            try {
                solrUtils.delDoc();
                logger.info("删除solr索引成功");
            } catch (IOException | SolrServerException e) {
                e.printStackTrace();
                logger.info("删除solr索引失败");
            }
        }
    }
    

     

    展开全文
  • Springboot 集成solr

    2018-04-04 17:38:26
    springboot框架,使用solr客户端solrj。步骤1:application.yml中写入solr连接hostdata: solr: host: http://localhost:8080/solr/collection1步骤2:pom文件引入如下配置&lt;dependency&gt; &lt;...

    springboot框架,使用solr客户端solrj。

    步骤1:application.yml中写入solr连接host

    data:
      solr:
        host: http://localhost:8080/solr/collection1

    步骤2:pom文件引入如下配置

    <dependency>
       <groupId>org.apache.solr</groupId>
       <artifactId>solr-solrj</artifactId>
       <version>5.3.1</version>
    </dependency>

    步骤3:新建solr配置类

    @Configuration
    public class SolrCacheConfiguration {
    
        Logger logger = LoggerFactory.getLogger(RedisCacheConfigurartion.class);
    
        @Value("${spring.data.solr.host}")
        private String host;
    
    
        @Bean
        public String getSolrUrl(){
            logger.info("solr地址:" + host);
            return host;
        }
    
    }

    步骤4:新建solr连接工具类,使用单例模式(静态内部类)

    @Component
    public class SolrUtil implements ApplicationContextAware {
    
        private static String URL = "";
        private static ApplicationContext applicationContext = null;
        private volatile static HttpSolrClient server = new HttpSolrClient(URL);
        private static class SingletonHolder {
            private static final SolrUtil INSTANCE = new SolrUtil();
        }
    
        static{
            server.setSoTimeout(100000);
            server.setConnectionTimeout(100000);
            server.setDefaultMaxConnectionsPerHost(100);
            server.setMaxTotalConnections(100);
            server.setFollowRedirects(false);
            server.setAllowCompression(true);
            server.setMaxRetries(1);
        }
    
        public static SolrUtil getInstance() {
            return SingletonHolder.INSTANCE;
        }
    
        private SolrUtil(){
    
        }
    
        /**
         * 获取solr连接
         * @return
         */
        public HttpSolrClient getServer(){
    
            if("".equals(URL)){
                SolrCacheConfiguration cacheConfiguration = applicationContext.getBean(SolrCacheConfiguration.class);
                URL = cacheConfiguration.getSolrUrl();
            }
            server.setBaseURL(URL);
    
            return server;
        }
    
        /**
         * Bean初始化调用setApplicationContext方法
         * @param applicationContext
         * @throws BeansException
         */
        @Override
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            if(SingletonHolder.INSTANCE.applicationContext == null){
                SingletonHolder.INSTANCE.applicationContext = applicationContext;
            }
        }
    
        /**
         * 关闭连接
         * @param solrClient
         */
        public void close(HttpSolrClient solrClient){
            if(solrClient != null){
                try {
                    solrClient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    
    }
    到这里,就可以用solrj操作solr了。
    展开全文
  • springboot集成solr 项目使用maven4.0构建,系统各个开源组件分别为springboot2.2.1,tomcat 9.0,solr 7.7.2。使用的版本都是比较新的,使用solr最新版出现一些问题没找到解决方法,换为了solr7.7 1.1集成solr...
  • springboot集成solr详解 此项目使用的是分布式,当然案例可以新建一个springboot项目进行测试 1.新建一个springboot项目,在项目中主要是作为一个搜索微服务 2.在搜索微服务learn_peace_search_service的配置文件...
  • springboot集成solr 基础应用实体类代码控制层代码前台页面(这里我用的是angularJs)效果展示 1.首先导入solr依赖 2.配置application.yml文件 实体类代码 @Entity @Table(name = "item") public class Item ...
  • <artifactId>SpringBoot_solr <version>0.0.1-SNAPSHOT <groupId>org.springframework.boot <artifactId>spring-boot-starter-parent <version>1.5.14.RELEASE <groupId>org.springframework....
  • springboot集成solr实现全局搜索系列

    千次阅读 2020-04-15 13:45:50
    1.2 Solr和lucene的区别2 Solr安装配置2.1 下载solr2.2 启动Solr2.3 Tomcat安装运行环境2.3.1 操作步骤2.4 solr界面介绍2.4.1 Dashboard2.4.2 Logging2.4.3 Core Admin2.4.4 java properties2.4.5 Tread Dump2.4.6 ...
  • 之前按照公司要求,为了提高搜索的准确性、广泛性以及用户体验,研究了一下Solr技术并添加到了自己的项目中。在网上看了好多博客的文章,根据前辈的经验得到了很多指点,但是也跳了不少坑。今天回顾老代码,决定做...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,244
精华内容 897
关键字:

springboot集成solr

spring 订阅