Google App Engine - Using Search API Python with list fields

前端 未结 2 719
日久生厌
日久生厌 2021-02-15 23:45

I\'m using ndb.Model. The Search API has the following field classes:

    TextField : plain text
    HtmlField : HTML formatted text
    AtomField : a string wh         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-02-16 00:31

    Use unique identifiers for each "tag". Then you can create a document like:

    doc = search.Document(fields=[
        search.TextField(name='tags', value='tag1 tag2 tag3'),
    ])
    search.Index(name='tags').put(doc)
    

    You can even use numbers (ids) as strings:

    doc = search.Document(fields=[
        search.TextField(name='tags', value='123 456 789'),
    ])
    

    And query using operators as you wish:

    index = search.Index(name='tags')
    results = index.search('tags:(("tag1" AND "tag2") OR ("tag3" AND "tag4"))')
    

提交回复
热议问题