自行搭建solr6.2版本一直到net core调用(二)

 

上一章讲了部署solr,这一章讲如何在asp.net core中实现

 

1. 用到正式数据,这边直接用正式的数据库和表了.

首先创建一下新的目录 newsInfo

拷贝一下之前core0里面的conf到 newsInfo里面

 

2. data-config更改一下查询连接及对应列

<?xml version="1.0" encoding="UTF-8"?>

<dataConfig>

<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1/kevis_etc" user="root"

password="123456" batchSize="-1"/>

<document name="News">

<entity name="NewsInfo" pk="id" query="SELECT id,Guid,CreateTime,NewsTitle,SubTitle,NewsContent,ClassId FROM tbl_NewsInfo ">

<field column="id" name="id" />

<field column="Guid" name="Guid" />

<field column="NewsTitle" name="NewsTitle" />

<field column="SubTitle" name="SubTitle" />

<field column="NewsContent" name="NewsContent" />

<field column="CreateTime" name="CreateTime" />

<field column="ClassId" name="ClassId" />

</entity>

</document>

</dataConfig>

 

3. managed-schema 加入NewsInfo需要的列

<field name="id" type="tlongs" indexed="true" stored="true" required="true" multiValued="false" />

<field name="Guid" type="text_general" indexed="true" stored="true" multiValued="false"/>

<field name="NewsTitle" type="text_general" indexed="true" stored="true" multiValued="false"/>

<field name="SubTitle" type="string" indexed="true" stored="true"/>

<field name="NewsContent" type="string" indexed="true" stored="true"/>

<field name="ClassId" type="int" indexed="true" stored="true"/>

<field name="CreateTime" type="tdate" indexed="true" stored="true"/>

 

4. 回到页面,创建一下 newsInfo

 

5. 生成一下数据

 

 

6. 程序中 先导入一下包

搜索 SolrNet ,导入到 application层

 

KevisEtcWebModule.cs ----> PreInitialize() 加入

清除上次请求(不清除会导致重复请求报错)我这边不加也没发现错误

//SolrNet.Startup.Container.Clear();

//SolrNet.Startup.InitContainer();

SolrNet.Startup.Init<NewsInfo_Solr>("http://127.0.0.1:8080/solr/newsInfo/");

 

7. 实现查询方法 ,按如下创建类

SolrBaseAppService.cs

ISolrBaseAppService.cs

 

NewsInfo_Solr.cs

 

 

News_SolrAppService.cs

 

INews_SolrAppService.cs

 

8. 前端调用

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值