Official Content

To our last example, Full Text Search example 2, let's add the possibility of working with a dictionary in order to refine the search query.

If the user query is not available in the index, another word or expression will be suggested to the user in order to make the query. The function used for that purpose will be TextSearch.CheckSpell. The suggested word is looked up in the dictionary; that is, for each word in the search query, CheckSpell returns the most similar one found in the dictionary.

The dictionary can be built up from the index, using the function TextSearch.BuildDictionary:

Event 'ReindexAll'
    &er = TextSearch.ReindexAll()
    &BooleanVar = TextSearch.BuildDictionary()

So, the code in the "Search" Web Panel object will be like the one below. Remember that:

  • &SearchResult is of SearchResult DataType
  • &SearchResultItem is of SearchResultItem DataType
&SearchResult = TextSearch.Find(&searchpattern,&items,&pagenumber)
&maxItems     = &SearchResult.MaxItems 
&elapsedTime  = &SearchResult.ElapsedTime
if &maxItems = 0 //There are no results
   &suggestword = TextSearch.CheckSpell(&searchpattern)
   if  &suggestword = ' '
       &tpage = 0
       msg(format("Your search - <b>%1</b> - did not match any documents.", &searchpattern))
       msg('Did you mean .. ' + &suggestword + ' ?')
       &searchpattern = &suggestword


If you have a dictionary (which you can download in HTML format), you can index it and call BuildDictionary afterwards.

See also

Full-Text Search in Applications
Full Text Search Examples - Indexing
Full Text Search Data Types

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant