MongoEngine / MongoEngine/mongoengine

Example of text search for embedded doc

Open
#1,797 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
4.3k
Forks
1.2k
Avg merge
4h 41m
Merged PRs (30d)
11

Description

The text search manual for this is a little spars.

I want to set up the meta for text searches on an embedded doc. but the instructions don't mention how, specifically. Do you set the meta for the Embedded Doc class or do you set the meta in the Document class pointing to the EmbeddedDocumentListField property?

My confusions is due to the use of the '$' in the 'fields' list because '$' in MongoDB is a positional for arrays.

Then after setting the meta, if it was set for the embedded doc class, do you just filter to the embedded document and do a objects.text_search()?

Example of the Modal to show what I mean:

class Line(EmbeddedDocument):
    line_num = IntField(required=True, null=False)
    line = StringField(max_length=255, required=True, null=True)
    severity = StringField(max_length=7, required=False, null=True)
    definitions = ListField(ObjectIdField(required=False, null=True), required=False, null=True)
    
    meta = {
        'indexes': [
            {
                'fields': ['$line'],
                'default_language': 'english',
            }
        ]
    }
   
    def __unicode__(self):
        return self.line


class Section(Document):
    section_title = StringField(max_length=255, required=True)
    lines = EmbeddedDocumentListField(Line, required=False, null=True)

    def __unicode__(self):
        return self.section_title

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the text-search manual and the EmbeddedDocument/Document example in the issue first. Clarify where text-search metadata belongs for embedded documents, how the '$' field notation applies, and how a completed example should query embedded text.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.