com presentations: update text search examples: slides/mongodb/text-create-index.xml slides/mongodb/text-index-options.xml slides/mongodb/text-query-options.xml slides/mongodb/text-query-syntax.xml slides/mongodb/text-run-command.xml
[email protected] (Derick Rethans)
| Newsgroups | php.pres |
|---|---|
| Message-ID | <[email protected]> |
Commit: 8cda93c2da4b57e0e64225a15d242d2dd7a7714e Author: Derick Rethans <[email protected]> Sat, 21 Mar 2015 11:45:15 +0100 Parents: e1ea2ddb59f169472df9359bf062e706be341860 Branches: master Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=8cda93c2da4b57e0e64225a15d242d2dd7a7714e Log: update text search examples Changed paths: M slides/mongodb/text-create-index.xml M slides/mongodb/text-index-options.xml M slides/mongodb/text-query-options.xml M slides/mongodb/text-query-syntax.xml M slides/mongodb/text-run-command.xml Diff: diff --git a/slides/mongodb/text-create-index.xml b/slides/mongodb/text-create-index.xml index ce0dc5f..9f988a0 100644 --- a/slides/mongodb/text-create-index.xml +++ b/slides/mongodb/text-create-index.xml @@ -2,8 +2,8 @@ <title>Create a Text Search Index</title> <example> -db.t.ensureIndex( - { title: "text", post: "text" }, - { weights: {title: 10, post: 5} } +db.articles.ensureIndex( + { subject: "text", post: "text" }, + { weights: {subject: 10, post: 5} } );</example> </slide> diff --git a/slides/mongodb/text-index-options.xml b/slides/mongodb/text-index-options.xml index 5b2b2ed..cfc9772 100644 --- a/slides/mongodb/text-index-options.xml +++ b/slides/mongodb/text-index-options.xml @@ -5,29 +5,29 @@ Basic, default weights: </blurb> <example> -tc.ensureIndex( { title: "text", post: "text" } ); +db.articles.ensureIndex( { subject: "text", post: "text" } ); </example> <blurb> Explicit weights: </blurb> <example> -tc.ensureIndex( { title: "text", post: "text" }, - { weights: { "title": 10 } } ); +db.articles.ensureIndex( { subject: "text", post: "text" }, + { weights: { "subject": 10 } } ); </example> <blurb> Wildcard field: text at any depth, default weights: </blurb> <example> -tc.ensureIndex( { "$**": "text" } ); +db.articles.ensureIndex( { "$**": "text" } ); </example> <blurb> Wildcard field: override default weights and explicit weights: </blurb> <example> -tc.ensureIndex( { "$**": "text" }, - { weights: {"$**": 10, post: 5 } } ); +db.articles.ensureIndex( { "$**": "text" }, + { weights: {"$**": 10, post: 5 } } ); </example> </slide> diff --git a/slides/mongodb/text-query-options.xml b/slides/mongodb/text-query-options.xml index f136003..a9a18cf 100644 --- a/slides/mongodb/text-query-options.xml +++ b/slides/mongodb/text-query-options.xml @@ -1,24 +1,24 @@ <slide> -<title>Text Search Query Options</title> +<title>Query Options and Sorting</title> -<example inline="3"> -db.collection.runCommand( "text", - { - // OR, AND, PHRASE, NEGATION - search: "coffee", - - // post-search ‘find’ filter - filter: { about: /desserts/ }, +<example result="1"><![CDATA[<?php +$m = new MongoClient; - // result limit - limit: 2, +$cursor = $m->demo->articles->find( + [ + '$text' => [ '$search' => '"advent" "xdebug"' ], + 'subject' => new MongoRegex( '/an/' ) + ], + [ + '_id' => 0, 'subject' => 1, + 'score' => [ '$meta' => 'textScore' ] + ] +)->limit( 4 )->sort( [ 'score' => [ '$meta' => 'textScore' ] ] ); - // result projection, 1/0 = include/exclude - project: { comments: 1, _id: 0 }, - - // default stemmer override - language: "english" - } -) +foreach ( $cursor as $record ) +{ + printf( "Score: %4.2f, Title: %s\n", $record['score'], $record['subject'] ); +} +?>]]> </example> </slide> diff --git a/slides/mongodb/text-query-syntax.xml b/slides/mongodb/text-query-syntax.xml index 92852f8..893efb2 100644 --- a/slides/mongodb/text-query-syntax.xml +++ b/slides/mongodb/text-query-syntax.xml @@ -3,26 +3,26 @@ <blurb>summer *OR* olympics (or strongly preferred: both)</blurb> <example> -t.runCommand( "text", "Summer Olympics" ) ); +db.articles.find( { '$text' : { '$search' : "Summer Olympics" } } ); </example> <blurb>*phrase* "Summer Olympics"</blurb> <example> -t.runCommand( "text", "\"Summer Olympics\"" ) ); +db.articles.find( { '$text' : { '$search' : "\"Summer Olympics\"" } } ); </example> <blurb>phrase "wild flowers" *OR* Sydney</blurb> <example> -t.runCommand( "text", "\"wild flowers\" Sydney" ) ); +db.articles.find( { '$text' : { '$search' : "\"wild flowers\" Sydney" } } ); </example> <blurb>wild *AND* flowers</blurb> <example> -t.runCommand( "text", "\"wild\" \"flowers\"" ) ); +db.articles.find( { '$text' : { '$search' : "\"wild\" \"flowers\"" } } ); </example> <blurb>industry *ANDNOT* Melbourne *ANDNOT* Physics</blurb> <example inline="3"> -t.runCommand( "text", "industry *-*Melbourne *-*Physics" ) ); +db.articles.find( { '$text' : { '$search' : "industry *-*Melbourne *-*Physics" } } ); </example> </slide> diff --git a/slides/mongodb/text-run-command.xml b/slides/mongodb/text-run-command.xml index 04eef91..c582c3a 100644 --- a/slides/mongodb/text-run-command.xml +++ b/slides/mongodb/text-run-command.xml @@ -1,6 +1,25 @@ <slide> -<title>Run a Text Search Command</title> +<title>Do a Text Search Query</title> +<div effect="fade-out"> <example> -db.t.runCommand( "text", { search: "MongoDB" } );</example> +db.articles.find( + { '$text' : { '$search' : '"advent" "xdebug"' } }, + { subject: 1, _id: 0 } +); +</example> +</div> + +<div effect="fade-in"> +<example result="1"><![CDATA[<?php +$m = new MongoClient; +$cursor = $m->demo->articles->find( + [ '$text' => [ '$search' => '"advent" "xdebug"' ] ], + [ 'subject' => 1, '_id' => 0 ] +); +foreach ( $cursor as $result ) { + echo $result['subject'], "\n"; +} +?>]]></example> +</div> </slide>