solr怎么多表(文档)solr 多表联合查询询

3168人阅读
Solr搜索应用服务器(19)
目前我们有两个库,不在同一个服务器上,如:A服务器上库有个account表,B服务器上有个两个库:其实就是把一个大数据表拆分成两个库,比如 follow1有个表A B和C,follow2有个C D和E表,其实都是存放相同的数据,这六个表的数据差不多有1000W,现在建索引我这边需要一个多小时,data-config.xml配置如下
&dataConfig&&& &dataSource type=&JdbcDataSource& name=&ds-1& driver=&com.mysql.jdbc.Driver& url=&jdbc:mysql://ip1:5901/relationship_1& user=&****&
&& password=&*****& batchSize=&-1&/&
&& &dataSource type=&JdbcDataSource& name=&ds-2& driver=&com.mysql.jdbc.Driver& url=&jdbc:mysql://ip1:5902/relationship_2& user=&****&
&& password=&******& batchSize=&-1&/&
&& &dataSource type=&JdbcDataSource& name=&ds-3& driver=&com.mysql.jdbc.Driver& url=&jdbc:mysql://ip2:& user=&****&
&& password=&******& batchSize=&-1&/&&&document name=&follow_log&&
&& &entity dataSource=&ds-1& name=&following1& pk=&logId& query=&select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId, accountId,targetAccount,followFlag,friendF
lag,followTime,friendTime,friendly,blockFlag,blockReason,blockTime,joinFlag from ((select * from relationship_following_1 ) union all (select * from relationship_following_3 ) u
nion all (select * from relationship_following_5 )) as f& deltaImportQuery=&select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId, accountId,targetAccount,followF
lag,friendFlag,followTime,friendTime,friendly,blockFlag,blockReason,blockTime,joinFlag from ((select * from relationship_following_1 where cast(CONCAT(accountId,targetAccount) a
s SIGNED INTEGER) = '${dih.delta.logId}') union all (select * from relationship_following_3 where cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) = '${dih.delta.logId}')
&union all (select * from relationship_following_5 where cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) = '${dih.delta.logId}')) as f& deltaQuery=&select f.logId from (
(select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId from relationship_following_1 where followTime &= '${dih.last_index_time}' or friendTime &= '${dih.last_ind
ex_time}') union all (select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId from relationship_following_3 where followTime &= '${dih.last_index_time}' or friendTi
me &= '${dih.last_index_time}') union all (select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId from relationship_following_5 where followTime &= '${dih.last_ind
ex_time}' or friendTime &= '${dih.last_index_time}')) as f&&
&&&&& &field column=&logId& name=&logId&/&
&&&&& &field column=&accountId& name=&accountId&/&
&&&&& &field column=&targetAccount& name=&targetAccount&/&
&&&&& &field column=&followFlag& name=&followFlag&/&
&&&&& &field column=&friendFlag& name=&friendFlag&/&
&&&&& &field column=&followTime& name=&followTime&/&
&&&&& &field column=&friendTime& name=&friendTime&/&
&&&&& &field column=&friendly& name=&friendly&/&
&&&&& &field column=&blockFlag& name=&blockFlag&/&
&&&&& &field column=&blockReason& name=&blockReason&/&
&&&&& &field column=&blockTime& name=&blockTime&/&
&&&&& &field column=&joinFlag& name=&joinFlag&/&
&&&&&&&&& &entity dataSource=&ds-3& name=&account& query=&select name,photoPath,l99NO,accountType,online from account where accountId = '${following1.targetAccount}'&&
&&&&&&&&&&&&&&&&& &field column=&name& name=&name&/&
&&&&&&&&&&&&&&&&& &field column=&photoPath& name=&photoPath&/&
&&&&&&&&&&&&&&&&& &field column=&l99NO& name=&l99NO&/&
&&&&&&&&&&&&&&&&& &field column=&accountType& name=&accountType&/&
&&&&&&&&&&&&&&&&& &field column=&online& name=&online&/&
&&&&&&&&& &/entity&
&& &/entity&
&& &entity dataSource=&ds-2& name=&following2& pk=&logId& query=&select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId, accountId,targetAccount,followFlag,friendF
lag,followTime,friendTime,friendly,blockFlag,blockReason,blockTime,joinFlag from ((select * from relationship_following_2 ) union all (select * from relationship_following_4 ) u
nion all (select * from relationship_following_6 )) as f& deltaImportQuery=&select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId, accountId,targetAccount,followF
lag,friendFlag,followTime,friendTime,friendly,blockFlag,blockReason,blockTime,joinFlag from ((select * from relationship_following_2 where cast(CONCAT(accountId,targetAccount) a
s SIGNED INTEGER) = '${dih.delta.logId}') union all (select * from relationship_following_4 where cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) = '${dih.delta.logId}')
&union all (select * from relationship_following_6 where cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) = '${dih.delta.logId}')) as f& deltaQuery=&select f.logId from (
(select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId from relationship_following_2 where followTime &= '${dih.last_index_time}' or friendTime &= '${dih.last_ind
ex_time}') union all (select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId from relationship_following_4 where followTime &= '${dih.last_index_time}' or friendTi
me &= '${dih.last_index_time}') union all (select cast(CONCAT(accountId,targetAccount) as SIGNED INTEGER) logId from relationship_following_6 where followTime &= '${dih.last_ind
ex_time}' or friendTime &= '${dih.last_index_time}')) as f&&
&&&&& &field column=&logId& name=&logId&/&
&&&&& &field column=&accountId& name=&accountId&/&
&&&&& &field column=&targetAccount& name=&targetAccount&/&
&&&&& &field column=&followFlag& name=&followFlag&/&
&&&&& &field column=&friendFlag& name=&friendFlag&/&
&&&&& &field column=&followTime& name=&followTime&/&
&field column=&friendTime& name=&friendTime&/&
&&&&& &field column=&friendly& name=&friendly&/&
&&&&& &field column=&blockFlag& name=&blockFlag&/&
&&&&& &field column=&blockReason& name=&blockReason&/&
&&&&& &field column=&blockTime& name=&blockTime&/&
&&&&& &field column=&joinFlag& name=&joinFlag&/&
&&&&&&&&& &entity dataSource=&ds-3& name=&account& query=&select name,photoPath,l99NO,accountType,online from account where accountId = '${following2.targetAccount}'&&
&&&&&&&&&&&&&&&&& &field column=&name& name=&name&/&
&&&&&&&&&&&&&&&&& &field column=&photoPath& name=&photoPath&/&
&&&&&&&&&&&&&&&&& &field column=&l99NO& name=&l99NO&/&
&&&&&&&&&&&&&&&&& &field column=&accountType& name=&accountType&/&
&&&&&&&&&&&&&&&&& &field column=&online& name=&online&/&
&&&&&&&&& &/entity&
&&& &/entity&
&& &/document&
&/dataConfig&
学习这个没多久,不知道有没有更好的办法来实现
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:612772次
积分:4565
积分:4565
排名:第4883名
原创:74篇
转载:42篇
评论:81条
(3)(1)(3)(3)(4)(2)(7)(3)(10)(9)(16)(6)(5)(6)(1)(6)(4)(1)(1)(1)(3)(1)(2)(2)(4)(2)(4)(1)(3)(2)solr查询给指定的文档加权重
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。solr 对多张表 建立 索引,查询 时 全部要查
来源:csdn
关联的表 (注意是没有关联) ,
我要在查询的 时候 对这些表都查,得到查询结果。
比如 用户 输入了
一串 字符,
我无法判断 他是
信托,保险,银行理财等(这些都对应数据库的表,表之间无关联,字段也不相同) 那方面的。
所以我要 对些表
都建立 索引, 怎么处理 。。注意是 使用solr】
yanghongjy:
一串 字符,
我无法判断 他是
信托,保险,银行理财等
这个字符可能是流水号,可能是名称,备注,日期等等
这些字段需要吗?
你们具体需求是什么?要这些所有这些东西不?
只查自己还是其他服务?
awl910213:
不明白你的意思啊,你建立索引后就直接查solr就可以查啊
还管你什么表啊
关键 点 在 :要对多张表 进行 搜索。 这些表的 id 都是自动生成的 。生成索引时 为 发生 覆盖。
有人说可以使用 多个core 解决, 那查询的时候 如何查询多个core呢 。。
顺便问下 : 有做过 solr 拼音 suggest 吗 ? 不知道如何下手
问题不是要哪些 字段, 是一次性要 检索 多张表 。。
要对多张表 进行 搜索。 这些表的 id 都是自动生成的 。生成索引时 为 发生 覆盖。
有人说可以使用 多个core 解决, 那查询的时候 如何查询多个core呢 。。
顺便问下 : 有做过 solr 拼音 suggest 吗 ? 不知道如何下手
qust_2011:
还是一个索引库(core)简单,只不过需要修改这几个表的主键生成策略,例如uuid
生成之后怎么办啊,还是不知道查询的是哪张表的数据啊
如果是在rails下的话,那需要为各个相关表配置solr的参数,然后在查询时,进行多表级联查询
在solr里建立多个core,然后搜索的时候加上一个参数,分别是每个core的基地址,就可以了。
参数好像是shard=http://localhost:8983/solr,http://localhost:8984/solr这种,但我刚刚试了,又不行了,不知道为什么,我以前就是这样做的。
欧,可以了。是shards=http://localhost:8983/solr/core1,http://localhost:8984/solr/core2,......
caolei616:
用单核的话
把id改为guid
要不就用多核 查询时加地址就可以
taodengwen:
比如说 “信托” 表要搜索的词对应数据库字段 name
"保险" 表要 搜索的词对应数据库字段 description
"银行理财"表要 搜索的词对应数据库字段 title
那么在将这些数据查询出来统一封装成一个java dto(不同的数据来源可以用应字段标识,比如说dataType,=1 代表“信托”的数据 =2代表“保险的数据”) 在将这个dto存储到solr中(doc),查询的时候直接查询solr中的name字段
比如 “信托” 中的name 存储在dto的name
“保险” 中的description
也存储在dto的name
"银行理财"中的title也存储在dto的name
更多表都可以这样
最后将这些dto转换存储到solr中,
查询的时候直接查询name 就可以了
(name: 输入的关键字)
taodengwen:
这样处理就跟表有没有关联没有关系了,这个图片demo实际上没有表关联关系,都是独立的表,,
问题回答了!
我也想请问一下大家,solr 中放什么样的数据更合适,一般什么情况下用solr???
我觉得也是, 一般情况下 表关联还是很复杂的
shiguangjiqi8888:
我遇到了,父表跟子表得情况,一对多得关系,怎么处理呢?
一个core怎么查询多个表啊,先谢谢你了
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动solr进行多表索引,全文检索过滤查询,求解答 - 开源中国社区
当前访客身份:游客 [
当前位置:
新学习solr,盼指导
在solrconfig.xml定义了data-config.xml并添加内容: &document& &entity name=&myuser& query=&select userid,username from user&& &/entity& &/document& 并在schema.xml定义了user的各个字段 solr实现了对user的全文检索 但是我要实现用户过滤,要跟role表进行关联 那么是不是增加 &entity name=&myrole& query=&select roleid,rolename from role&& &/entity& 在schema.xml定义了role的各个字段来对role表进行索引,这样来实现2个表的关联查询? 是不是这样实现的? 所有字段都在schema.xml?万一2个表有相同字段呢?
共有1个答案
<span class="a_vote_num" id="a_vote_num_
帖子比较老了,回复一下,供其他人参考吧
field1, field2, field3, field4
userid1, username1, roleid1, rolename1 & &&-- document
userid1,&username1, roleid2, rolename2 & &&-- document
userid2,&username2, roleid2, rolename2 & &&-- document
userid2,&username2, roleid3, rolename3 & &&-- document
index1, index2, index3, index4
不知道这样能否看懂?
--- 共有 2 条评论 ---
1、关联查询,数据放在同一个entity里
2、用户或者角色表作为子entity
3、权限放在外面做,不放到solr里
(3个月前)&nbsp&
能否详细的说一下,我也遇到了这样的问题,谢谢
(3个月前)&nbsp&
更多开发者职位上
有什么技术问题吗?
Robinso...的其它问题
类似的话题基于solr或者elasticsearch提供的多核,多索引,多shard等查询能力,一般都是由lucene提供的多索引查询的功能演化而来的,这个功能在单机版的lucene里面确实没有发挥多大的威力,但是确是solrclourd,elasticsearch分布式集群查询数据的基础,正是因为lucene提供了多索引归并查询已经合并排序功能,所以在给它加上http的能力,就能把lucene也做成一个分布式的查询框架,当然一个分布式,需要考虑的内容非常多,容错,副本,高可靠,等都是主要功能。
本篇介绍洗下如何在solr中实现多core查询,其实也叫多shard查询,多core查询的要求是,两份索引里面的主键字段,和查询数据字段必须一致,就是说都必须有一样的字段名,否则查询的时候或者归并merge的时候会报错,其实这正是分布式搜索的基础条件,只不过现在我们不用solrcloud也能查询多个core,需要注意前提条件:
主键字段+查询字段的名称必须一致,下面看solrj里面如何实现:
* 多核查询测试
* @throws Exception
public static void queryMultiCore()throws Exception{
//查询a和b下面的数据,
HttpSolrClient sc=new HttpSolrClient("http://192.168.1.215:8983/solr/a");
String shards = "192.168.1.215:8983/solr/a,192.168.1.214:8983/solr/b";
ModifiableSolrParams solrParams = new ModifiableSolrParams();
solrParams.set("q", "sname:北京奇虎有限公司");
solrParams.set("q.op", "AND");//设置查询关系
solrParams.set("fl", "*,score");//设置过滤
solrParams.set("shards", shards);//设置shard
QueryResponse rsp = sc.query(solrParams);
.out.println("命中数量:"+rsp.getResults().getNumFound());
for(SolrDocument sd:rsp.getResults()){
System.out.println(sd);
sc.close();
参考:
/questions/9665688/distributed-search-using-solrj
http://wiki.apache.org/solr/DistributedSearch

我要回帖

更多关于 solr api 中文文档 的文章

 

随机推荐