0
votes

I have created Document, added it to Index and used the GAE Search API to search for a text successfully. Please find the sample code below.

search.Document(
    fields=[search.TextField(name='id', value=id),
            search.TextField(name='search', value=searchT)])

options = search.QueryOptions(returned_fields=['id'])
results = search.Index(name=_D_INDEX_NAME).search(search.Query(searchTxt, options=options))

Now I am unable to understand to to achieve these mentioned below: Some sample code would be really appreciated.

To search for plural variants of an exact query, use the ~ operator:
~"car" # searches for "car" and "cars"
To build queries that reference specific fields, use both field and value in your query, separated by a colon:
field:value
field:"value as a string"

1
what exactly do you not understand? - aschmid00
I was looking for some sample code, as whatever I tried didnt work. Finally came to know from @Sebastian that it wont work in the dev_appserver (see answer below) - ujjalcal

1 Answers

1
votes

When you add a document, you specify its schema by defining the fields of the document. In your case id and search.

To search for a term that only appears in a specific field you use the notation field:term

search.Index(name=_D_INDEX_NAME).search('search:programming')

For searching plural variants of a term you use the operator ~

search.Index(name=_D_INDEX_NAME).search('~car')

Note however that this won't work in the dev_appserver.