Search code examples
searchmarklogicstemming

MarkLogic - Enabling stemming will also search for American / British spelling


MarkLogic 9.0.8.2

We have business requirements to support American/British words in search queries like

  • fiber or fibre
  • color or colour

SO if we enable stemming at database level will solve this problem or we need to configure more to make it work?

Stemming https://docs.marklogic.com/guide/search-dev/stemming


Solution

  • Yes, enabling stemming on the database would be the easiest way to achieve what you are looking to do.

    Below is some code that you can use to quickly experiment and verify that it will work for you:

    xquery version "1.0-ml";
    (: enable stemmed searches :)
    import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy";
    
    let $config := admin:get-configuration()
    return
      (: experiment with various settings: off, basic, advanced, decompounding :) 
      admin:database-set-stemmed-searches($config, xdmp:database("Documents"), "basic") 
      ! admin:save-configuration(.)
    ;
    
    (: insert two test documents with different spelling for color :)
    ("color","colour") ! xdmp:document-insert("/"||.||".xml", <doc>{.}</doc>)
    ;
    
    (: search and see what is returned :)
    cts:search(doc(), cts:word-query("colour"))