Prefix and Regex queries are not working

query
#1

I have been using beer-sample bucket and created fts index on it. But I do not seem to query it with Prefix or Regex queries. Fts is only giving me results for completely matching terms. Below is my fts index definirion
{
“type”: “fulltext-index”,
“name”: “beer_fts”,
“uuid”: “375d139c7c3155cc”,
“sourceType”: “couchbase”,
“sourceName”: “beer-sample”,
“sourceUUID”: “ccfc5b6f86033ee7c1d01bd8e72f771e”,
“planParams”: {
“maxPartitionsPerPIndex”: 171
},
“params”: {
“doc_config”: {
“mode”: “type_field”,
“type_field”: “type”
},
“mapping”: {
“default_analyzer”: “standard”,
“default_datetime_parser”: “dateTimeOptional”,
“default_field”: “_all”,
“default_mapping”: {
“dynamic”: true,
“enabled”: false
},
“default_type”: “_default”,
“index_dynamic”: true,
“store_dynamic”: false,
“types”: {
“beer”: {
“dynamic”: true,
“enabled”: true,
“properties”: {
“description”: {
“dynamic”: false,
“enabled”: true,
“fields”: [
{
“analyzer”: “”,
“include_in_all”: true,
“include_term_vectors”: true,
“index”: true,
“name”: “description”,
“store”: false,
“type”: “text”
}
]
},
“style”: {
“dynamic”: false,
“enabled”: true,
“fields”: [
{
“analyzer”: “”,
“include_in_all”: true,
“include_term_vectors”: true,
“index”: true,
“name”: “style”,
“store”: false,
“type”: “text”
}
]
}
}
}
}
},
“store”: {
“kvStoreName”: “mossStore”
}
},
“sourceParams”: {}
}

Any idea what is going on?

I also tried python to query fts"

In [2]: from couchbase import fulltext as ft

In [3]: from couchbase.cluster import Cluster

In [4]: from couchbase.bucket import Bucket

In [5]: cluster = Cluster(‘couchbase://xxx’)

In [6]: authenticator = PasswordAuthenticator(‘xxx’, ‘xxx’)

In [7]: cluster.authenticate(authenticator)

In [8]: bs = cluster.open_bucket(‘beer-sample’)

In [9]: query = ft.PrefixQuery(‘Ameri’)

In [10]: res = fb.search(‘beer_fts’, query=query)

In [11]: for i in res:
…: print i
…:

In [12]: query = ft.MatchQuery(‘America’)

In [13]: res = fb.search(‘beer_fts’, query=query)

In [14]: for i in res:
…: print i
…:
{u’sort’: [u’_score’], u’index’: u’beer_fts_375d139c7c3155cc_f4e0a48a’, u’score’: 0.8033196920587414, u’id’: u’pabst_brewing_company-old_milwaukee’}
{u’sort’: [u’_score’], u’index’: u’beer_fts_375d139c7c3155cc_aa574717’, u’score’: 0.7063992746318444, u’id’: u’penn_brewery-penn_gold’}

#2

Prefix and Regexp queries work on the terms in the index, and it looks like in your mapping all fields are using the default analyzer, which is ‘standard’. The standard analyzer converts all terms to lowercase, so when using Prefix and Regexp queries (which do not use the anlayzer) you must pass in lowercase input.

I didn’t try it, but I’d expect the prefix query for ‘ameri’ to work, even though the prefix query for ‘Ameri’ did not.

This similarly affects regular expression queries as well.

#3

Oh that does work. Thank you. I didn’t think of that. So ‘amer’ matches both ‘America’ and ‘america’ but ‘Amer’ matches nothing.