[DOCS-1627] Text search "search for text" tutorial unclear on phrase query semantics Created: 14/Jun/13  Updated: 30/Oct/23  Resolved: 09/Sep/13

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Major - P3
Reporter: Ara T. Howard Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 10 years, 21 weeks, 1 day ago

 Description   

The "Match Phrases" section in tutorial/search-for-text.txt could use clarification, specifically to indicate that the compound OR query includes individual terms from phrases (i.e. to clarify that "foo bar \"baz\"" is not a search for ((foo OR bar) AND ("baz")).

Original description below (see linked mailing list discussion in comments):

according to the docs at http://docs.mongodb.org/manual/single/index.html#document-tutorial/enable-text-search

searching for

"corto largo \"and tomorrow\""

should perform something like

(corto OR largo OR tomorrow) AND ("and tomorrow")

but it does not. for example, my corpus has ONE document with the word 'dog' in it

> db.search_indices.runCommand( 'text', { search: 'dog', limit: 42} )
{
        "queryDebugString" : "dog||||||",
        "language" : "english",
        "results" : [
                {
                        "score" : 0.75,
                        "obj" : {
                                "_id" : ObjectId("51bb42dfaf481c7aa4001b3d"),
                                "context_type" : "B",
                                "context_id" : ObjectId("51bb42dfaf481c7aa4001b3c"),
                                "title" : "search_model_b",
                                "keywords" : [
                                        null
                                ],
                                "fulltext" : "dog search_model_b"
                        }
                }
        ],
        "stats" : {
                "nscanned" : 1,
                "nscannedObjects" : 0,
                "n" : 1,
                "nfound" : 1,
                "timeMicros" : 73
        },
        "ok" : 1
}

however, if i expand the search by including another term, and keep the phrase, we can see that a logical OR occurs - not and AND

> db.search_indices.runCommand( 'text', { search: 'dog "search_model_a"', limit: 1} )
{
        "queryDebugString" : "dog|search_model_a||||search_model_a||",
        "language" : "english",
        "results" : [
                {
                        "score" : 110.75000000000001,
                        "obj" : {
                                "_id" : ObjectId("51bb42dfaf481c7aa4001b3b"),
                                "context_type" : "A",
                                "context_id" : ObjectId("51bb42dfaf481c7aa4001b3a"),
                                "title" : "search_model_a",
                                "keywords" : [
                                        null
                                ],
                                "fulltext" : "cat search_model_a"
                        }
                }
        ],
        "stats" : {
                "nscanned" : 12,
                "nscannedObjects" : 0,
                "n" : 1,
                "nfound" : 1,
                "timeMicros" : 104
        },
        "ok" : 1
}

notice the result was returned not because

'dog AND search_model_a'

but because

'dog OR search_model_a'

using ONLY phrases has the expected results

> db.search_indices.runCommand( 'text', { search: '"dog" "search_model_a"', limit: 1} )
{
        "queryDebugString" : "dog|search_model_a||||dog|search_model_a||",
        "language" : "english",
        "results" : [ ],
        "stats" : {
                "nscanned" : 12,
                "nscannedObjects" : 0,
                "n" : 0,
                "nfound" : 0,
                "timeMicros" : 133
        },
        "ok" : 1
}
 
> db.search_indices.runCommand( 'text', { search: '"dog" "search_model_b"', limit: 1} )
{
        "queryDebugString" : "dog|search_model_b||||dog|search_model_b||",
        "language" : "english",
        "results" : [
                {
                        "score" : 112.50000000000003,
                        "obj" : {
                                "_id" : ObjectId("51bb42dfaf481c7aa4001b3d"),
                                "context_type" : "B",
                                "context_id" : ObjectId("51bb42dfaf481c7aa4001b3c"),
                                "title" : "search_model_b",
                                "keywords" : [
                                        null
                                ],
                                "fulltext" : "dog search_model_b"
                        }
                }
        ],
        "stats" : {
                "nscanned" : 12,
                "nscannedObjects" : 0,
                "n" : 1,
                "nfound" : 1,
                "timeMicros" : 109
        },
        "ok" : 1
}

BUG in the docs? or in the code?



 Comments   
Comment by auto [ 24/Sep/13 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-1627 clarify text search that includes phrases
Branch: master
https://github.com/mongodb/docs/commit/06fdcfc49973b0b97e0a34c83ac6cf4828d167d5

Comment by J Rassi [ 20/Jun/13 ]

Updated title/description, moved to DOCS.

Comment by Ara T. Howard [ 15/Jun/13 ]

see more discussion here -> https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/2hUgOAN4KKk

Comment by Ara T. Howard [ 14/Jun/13 ]

let me know if you need more info. sorry about the shell/js formatting... does this system support code/syntax highlighting?

Comment by Ara T. Howard [ 14/Jun/13 ]

ref: https://groups.google.com/forum/?fromgroups#!topic/mongodb-user/2hUgOAN4KKk

Generated at Thu Feb 08 07:41:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.