• sedna进行xquery查询


    有一个文件book.xml:

    <books>
    	<book>
    		<name>The Call Of Wild</name>
    		<author>Jack London</author>
    		<price>32.5$</price>
    		<date>2015-7-6</date>
    	</book>
    	<book>
    		<name>Wuthering Heights</name>
    		<author>Emily Bronte</author>
    		<price>40$</price>
    		<date>2015-7-5</date>
    	</book>
    </books>


    创建books数据库:

    [root@localhost xuzhina]#se_cdb books
    Creating a database (this can take a few minutes)...
    The database 'books' has been created successfully

    启动它:

    [root@localhost xuzhina]#se_sm books
    Starting database recovery or hot-backup restoration...
    Database is in consistent state. Starting...
    SM has been started in the background mode

    创建一个collection叫novel:

    [root@localhost xuzhina]#se_term -query "CREATE COLLECTION 'novel'" books
    UPDATE is executed successfully

    载入进去:

    [root@localhost xuzhina]#se_term -query "LOAD 'book.xml' 'book' 'novel'" books
    Bulk load succeeded

    查询整个文件:

    [root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books return $p" book
    s
    <books>
      <book>
        <name>The Call Of Wild</name>
        <author>Jack London</author>
        <price>32.5$</price>
        <date>2015-7-6</date>
      </book>
      <book>
        <name>Wuthering Heights</name>
        <author>Emily Bronte</author>
        <price>40$</price>
        <date>2015-7-5</date>
      </book>
    </books>


    查询book:

    [root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books/book return $p"
     books
    <book>
      <name>The Call Of Wild</name>
      <author>Jack London</author>
      <price>32.5$</price>
      <date>2015-7-6</date>
    </book>
    <book>
      <name>Wuthering Heights</name>
      <author>Emily Bronte</author>
      <price>40$</price>
      <date>2015-7-5</date>
    </book>

    查询某个书名的book:

    [root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books/book[name='The
    Call Of Wild'] return $p" books
    <book>
      <name>The Call Of Wild</name>
      <author>Jack London</author>
      <price>32.5$</price>
      <date>2015-7-6</date>
    </book>

    查询第2本书(记住它的索引是从1開始的):

    [root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books/book[2] return
    $p" books
    <book>
      <name>Wuthering Heights</name>
      <author>Emily Bronte</author>
      <price>40$</price>
      <date>2015-7-5</date>
    </book>

    查询某个书的书名包含某个词语,比方Call:

    [root@localhost xuzhina]#se_term -query "for $p in collection('novel')/books/book[contains(n
    ame, 'Call')] return $p" books
    <book>
      <name>The Call Of Wild</name>
      <author>Jack London</author>
      <price>32.5$</price>
      <date>2015-7-6</date>
    </book>


  • 相关阅读:
    20.11.16 leetcode406 leetcode中的排序写法
    20.11.15 leetcode402
    20.11.14 leetcode1122(自定义排序)
    polyline NOIP模拟 数论 规律
    alien NOIP模拟 位运算 数论
    跳石头 vijos1981 NOIP2015 D2T1 二分答案 模拟 贪心
    寻找道路 vijos1909 NOIP2014 D2T2 SPFA
    不死的LYM NOIP模拟 二分+状压DP
    死亡的颂唱者 NOIP模拟 贪心 DFS
    无线网络发射器选址 vijos 1908 NOIP2014 D2T1 模拟
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/6755860.html
Copyright © 2020-2023  润新知