0

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"

ujjalcal
  • 125
  • 1
  • 1
  • 5

1 Answers1

1

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.

Sebastian Kreft
  • 7,819
  • 3
  • 24
  • 41
  • Actually I tried this in dev_appserver and it didnt work. But as you mentioned I am going to check this out once again in the appspot.com. Thanks for your input. Also curious to know why it wont work in the dev_appserver? – ujjalcal Sep 07 '12 at 17:02
  • Google haven't implemented Stemming on their development server. https://developers.google.com/appengine/docs/python/search/devserver – Carl Jul 30 '14 at 13:41