API Reference / API Parameters / removeStopWords
Feb. 26, 2019

removeStopWords

Type: boolean | list of strings
Engine default: false
Parameter syntax
'removeStopWords' => true|false|['language ISO code', ...]

Can be used in these methods:

About this parameter

Removes stop (common) words from the query before executing it.

Stop word removal is useful when you have a query in natural language, e.g. “what is a record?”. In that case, the engine will remove “what”, “is”, and “a” before executing the query, and therefore just search for “record”. This will remove false positives caused by stop words, especially when combined with optional words (see optionalWords and removeWordsIfNoResults).

Usage notes:

  • removeStopWords is used in conjunction with the queryLanguages setting.

  • You can send removeStopWords one of 3 values:

    • true, which enables the stop word functionality, ensuring that stop words are removed from consideration in a search. The languages supported here are either every language (this is the default, see list of languages below), or those set by queryLanguages. See queryLanguages example below.

    • false, which disables stop word functionality, allowing stop words to be taken into account in a search.

    • a list of language ISO codes for which stop words should be enabled. This list will override any values that you may have set in ‘queryLanguages`.

  • For most use cases, however, it is better not to use this feature, as people tend to search by keywords on search engines (that is, they naturally omit stop words).

  • Prefix logic: Stop words only apply on query words that are not interpreted as prefixes. To control how prefixes are interpreted, check out queryType.

  • List of supported languages with their associated ISO code:

    Arabic=ar
    Bulgarian=bg
    Bengali=bn
    Catalan=ca
    Czech=cs
    Danish=da
    German=de
    Greek=el
    English=en
    Spanish=es
    Basque=eu
    Persian (Farsi)=fa
    Finnish=fi
    French=fr
    Irish=ga
    Galician=gl
    Hindi=hi
    Hungarian=hu
    Armenian=hy
    Indonesian=id
    Italian=it
    Japanese=ja
    Korean=ko
    Kurdish=ku
    Lithuanian=lt
    Latvian=lv
    Marathi=mr
    Dutch=nl
    Norwegian=no
    Polish=pl
    Portuguese=pt
    Brazilian=pt-br
    Romanian=ro
    Russian=ru
    Slovak=sk
    Swedish=sv
    Thai=th
    Turkish=tr
    Ukranian=uk
    Urdu=ur
    Chinese=zh

Examples

Set the default Query Languages

In this example, we set Spanish (‘es’) as the default language for removeStopWords

1
2
3
4
$index->setSettings([
  'queryLanguages' => ['es'],
  'removeStopWords' => true
]);

Override Query Languages

In this example, we override the Spanish default for removeStopWords by adding Catalan (‘ca’) to its list of languages.

1
2
3
$results = $index->search('query', [
  'removeStopWords' => ['ca', 'es']
]);

Did you find this page helpful?