Module: background script - searchTermGeneration

Members

(inner, constant) maxRuns

Defines the maximum number of iterations when searching for a suggestion. This number should (hopefully) not get reached, but we use it to make 100% sure that we can never land in an endless loop.
Source:

(inner, constant) suggestionAPI

Holds the link to the Google suggestion API for completing search terms.
Source:

Methods

(inner) chooseTerm(suggestions, alreadyChosen)

Returns a suggestion from a list of suggestions which was not considered before.
Parameters:
Name Type Description
suggestions Array.<string> Array of suggestions.
alreadyChosen Array.<string> Array of words we already looked at.
Source:

(inner) getAllWords(term)

Returns all possible combinations of words for a search term (with the only condition that the words do not change their order).
Parameters:
Name Type Description
term string The term for which we want to get all combinations of words.
Source:

(inner) getSuggestion(term, callback)

Tries to find a Google search completion suggestion for a given term.
Parameters:
Name Type Description
term string The search term for which we want to find a suggestion.
callback function Mandatory callback function with suggestion as parameter.
Source:

(inner) getSuggestionRecursive(original, wordQueue, runs, alreadyDone, callback)

Tries to find a Google search completion suggestion for a given term.
Parameters:
Name Type Description
original string The original term for which we want to find a suggestion.
wordQueue Array.<string> The terms to look at next.
runs number The number of iterations done so far.
alreadyDone Array.<string> Terms which have already been looked at.
callback function Mandatory callback function with suggestion as parameter.
Source:

(inner) isValid(originalTerm, suggestionTerm)

Checks if a suggestion is valid, i.e., it contains the same number of words as the original term and it contains not a single word of the original term.
Parameters:
Name Type Description
originalTerm string The original term.
suggestionTerm string The suggestion to be checked.
Source:

(inner) processResponse(text)

Brings the response from the API into the correct format.
Parameters:
Name Type Description
text string Response text from the API request.
Source:

(inner) requestAPI(api, term, callback)

Requests the Google suggestion API for a given term.
Parameters:
Name Type Description
api string The Google suggestion API.
term string The term which should get completed.
callback function Mandatory callback function with the suggestions as parameter.
Source: