zoukankan      html  css  js  c++  java
  • solr之高级查询--联表 join查询

    例如有两个业务表:文章表,评论表 。

       场景: 一个文章可以由多个人评论。

       创建两个core,一个core叫article,一个叫comment。
    article实例的schema.xml文件中定义几个简单的属性:id、title、content、createtime,relationId

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

    <field name="title" type="text_general_rev" indexed="true" stored="true"/>

    <field name="content" type="text_general_rev" indexed="true" stored="true"/>

    <field name="create" type="long" indexed="true" stored="true"/>

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

    comment实例的schmea.xml文件中定义几个简单的属性:id,articleId,userName,createtime,commentContent

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

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

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

    <field name="createtime" type="long" indexed="true" stored="true"/>

    <field name="commentContent" type="text_general_rev" indexed="true" stored="true"/>

    ok,从上面可以看出文章的relationId在评论里面articleId属性相关联

    查询张三评论过的文章

    http://localhost:8088/solr/article/select?q={!join fromIndex=article toIndex=comment from=relationId to=articleId} userName:"张三"

    写了这么多,{!join fromIndex=article toIndex=comment from=relationId to=articleId}这个里面才是最主要的东西。类似sql :select  * from tableA a left join tableB b on a.id = b.realtionId 对应过去应该就了解了对应位置是什么东西了。

  • 相关阅读:
    未来开发构想:
    3种方式遍历repeater中的CheckBox全选
    [常见面试题]一条Sql语句:取出表A中第31到第40记录,ID可能不是连续的
    mpc源代码下载,编译,调试
    哈希表(Hashtable)使用
    ASP.NET常用代码
    [转]Erwin4.1.4与PowerDesign9.5
    Three things everyone should know to improve object retrieval
    Learning the parts of objects by nonnegative matrix factorization (Letters to Nature)
    js 钟表
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/9335230.html
Copyright © 2011-2022 走看看