SummerOfCode/2013/AutosuggestDocs

From MozillaWiki
Jump to: navigation, search

Overview

Autosuggest Search Engine module tracks an form submission made by the user, and tries to infer from the user's activity whether the user has been trying to submit a form that is possibly a search form.

To use it use the following module into your code:

Components.utils.import("resource://gre/modules/AutosuggestSearchEngine.jsm");

It tracks different fields in the forms, and its contents, frecency score of the website hosting the form and decides which is the most likely field to be a search field. Once it gets a postive hit, it fires a notification that can be tracked by an observer that can consume useful information from the notification, such as the form website, the most likely field.

It stores the temporary data collected from the forms in the autosuggestsearch-history.json file in the user profile directory.

Using Autosuggest Search Engine

Method Overview

  • init

init

Initialize the Autosuggest Search Engine module.

void init();

Storage Handler

Storage Handler handles the storage part of the module and save the data in the storage section in the profile directory in a flat JSON file autosuggestsearch-history.json.

It can be accessed via:

AutosuggestSearchEngine.storageHandler

It provides the following methods:

  • createNew
  • getForm
  • updateForm
  • saveData

createNew

Creates a new entry in case the URI is not present in storage already.

void createNew(actionURL);
  • actionURL: The URL whose entry is to be created.

getForm

Helper method to get the submissions data for an URI. The returned data looks like:

{ submissionCount: Number of submissions,
  mostLikelyField: most likely field in the form,
  formScore: the score of the form
}
Object getForm(actionURL)
  • actionURL: The URL whose form data is to be returned.

updateForm

Helper method to update the stored details about a form

void updateForm(actionURL, submissionCount, mostLikelyField, formScore)
  • actionURL: The URL whose form data is to be set.
  • submissionCount: The number of times the form was submitted.
  • mostLikelyField: The most likely field guessed by the module.
  • formScore: The score of the form.

saveData

Helper method to save the in-memory data to disk.

void saveData()

Preferences

The Autosuggest Search Engine has two preferences:

  • browser.autosuggestSearch.debug: A true value to toggle the debug mode for AutosuggestSearchEngine.jsm.
  • browser.autosuggestSearch.enabled: A boolean value to turn the Autosuggest feature on or off.