API Reference / API Parameters / naturalLanguages
Type: list of strings
Engine default: []
Parameter syntax
'naturalLanguages' => ['language ISO code', ...]

Can be used in these methods:

About this parameter

This parameter changes the default values of certain parameters and settings that work best for a natural language query, such as ignorePlurals, removeStopWords, removeWordsIfNoResults, analyticsTags and ruleContexts. These parameters and settings work well together when the query is formatted in natural language instead of keywords, for example when your user performs a voice search.

The naturalLanguages parameter changes the following parameters and setttings:

  • removeStopWords and ignorePlurals are set to the given list of languages.
  • removeWordsIfNoResults is set allOptional.
  • It adds the natural_language value to ruleContexts.
  • It adds the natural_language value to analyticsTags.

Usage notes

  • For optimal relevance, we recommend to only pass languages that occur in your data.

  • List of supported languages with their associated language ISO code:

    Afrikaans=af
    Arabic=ar
    Azerbaijani=az
    Bulgarian=bg
    Bengali=bn
    Catalan=ca
    Czech=cs
    Welsh=cy
    Danish=da
    German=de
    Greek=el
    English=en
    Esperanto=eo
    Spanish=es
    Estonian=et
    Basque=eu
    Persian (Farsi)=fa
    Finnish=fi
    Faroese=fo
    French=fr
    Irish=ga
    Galician=gl
    Hebrew=he
    Hindi=hi
    Hungarian=hu
    Armenian=hy
    Indonesian=id
    Icelandic=is
    Italian=it
    Japanese=ja
    Georgian=ka
    Kazakh=kk
    Korean=ko
    Kurdish=ku
    Kirghiz=ky
    Lithuanian=lt
    Latvian=lv
    Maori=mi
    Mongolian=mn
    Marathi=mr
    Malay=ms
    Maltese=mt
    Norwegian Bokmål=nb
    Dutch=nl
    Norwegian=no
    Northern Sotho=ns
    Polish=pl
    Pashto=ps
    Portuguese=pt
    Brazilian=pt-br
    Quechua=qu
    Romanian=ro
    Russian=ru
    Slovak=sk
    Albanian=sq
    Swedish=sv
    Swahili=sw
    Tamil=ta
    Telugu=te
    Thai=th
    Tagalog=tl
    Tswana=tn
    Turkish=tr
    Tatar=tt
    Ukranian=uk
    Urdu=ur
    Uzbek=uz
    Chinese=zh

Examples

Set Natural Languages

In this example, we set French (fr) as the natural language.

At query time, ignorePlurals and removeStopWords are set to fr, and removeWordsIfNoResults is set to allOptional.

1
2
3
$index->search('', [
  'naturalLanguages' => ['fr']
]);

Override naturalLanguages with query parameters

In this example, we set French (fr) as a natural language, and we override removeWordsIfNoResults to firstWords.

At query time, both ignorePlurals and removeStopWords are set to fr, and removeWordsIfNoResults is set to firstWords because we explicitly pass it as a query parameter.

1
2
3
4
$index->search('', [
  'naturalLanguages' => ['fr'],
  'removeWordsIfNoResults' =>'firstWords'
]);
Did you find this page helpful?