有一个文件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>