<commit_before>Algolia Search API Client for Javascript
==================

This Javascript client let you easily use the Algolia Search API in a browser, it is compatible with most browsers:

 * Internet Explorer &ge; 8
 * Firefox &ge; 3.5
 * Google Chrome &ge; 3
 * Safari &ge; 4
 * Opera &ge; 12
 * Opera mobile &ge; 12
 * etc.

See [this wikipedia page](http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing#Browser_support) to have more details on supported browser (this library supports XDomainRequest extension and so supports IE8 and IE9).

Setup
-------------
To setup your project, follow these steps:

 1. Add a script include of `algoliasearch-min.js`
 2. Initialize the client with your ApplicationID, API-Key and list of hostnames (you can find all of them on your Algolia account)
 3. When you use this API client for search on a website, we strongly recommand to use a key with an ACL restricted "search" that you can retrieve with `client.addUserKey(["search"])`.

```javascript
  &lt;script src="algoliasearch-min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    client = new AlgoliaSearch('ApplicationID', 'API-Key', 
                              ['http://api-u1-1.algolia.io', 'http://api-u1-2.algolia.io', 'api-u1-3.algolia.io']),
```

Quick Start
-------------

You can replace your ApplicationID and API-Key in `simple-ui.html` to test the Javascript client on your account.

General Principle
-------------

All API calls will return the result in a callback that takes two arguments:

 1. **sucess**: a boolean that is set to false when an error was found.
 2. **content**: the object containing answer (if an error was found, you can retrieve the error message in `content.message`)

Search 
-------------
To perform a search, you have just to initialize the index and perform a call to search.<br/>
You can optionally use the following arguments :

 * **attributes**: a string that contains attribute names to retrieve separated by a comma.<br/>By default all attributes are retrieved.
 * **attributesToHighlight**: a string that contains attribute names to highlight separated by a comma.<br/>By default all textual attributes are highlighted.
 * **minWordSizeForApprox1**: the minimum number of characters in a query word to accept one typo in this word.<br/>Defaults to 3.
 * **minWordSizeForApprox2**: the minimum number of characters in a query word to accept two typos in this word.<br/>Defaults to 7.
 * **getRankingInfo**: if set to 1, the result hits will contain ranking information in _rankingInfo attribute.
 * **page**: *(pagination parameter)* page to retrieve (zero base).<br/>Defaults to 0.
 * **hitsPerPage**: *(pagination parameter)* number of hits per page.<br/>Defaults to 10.
 * **aroundLatLng**: search for entries around a given latitude/longitude (specified as two floats separated by a comma).<br/>For example `aroundLatLng=47.316669,5.016670`).<br/>You can specify the maximum distance in meters with **aroundRadius parameter** (in meters).<br/>At indexing, you should specify geoloc of an object with _geoloc attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
 * **insideBoundingBox**: search entries inside a given area defined by the two extreme points of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat, p2Lng).<br/>For example `insideBoundingBox=47.3165,4.9665,47.3424,5.0201`).<br/>At indexing, you should specify geoloc of an object with _geoloc attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
 * **tags**: filter the query by a set of tags (contains a list of tags separated by a comma).<br/>At indexing, tags should be added in _tags attribute of objects (for example `{"_tags":["tag1","tag2"]}` )

````javascript
index = client.initIndex('MyIndexName');
index.search('query string', function(success, content) {
    for (var h in content.hits) {
        console.log('Hit(' + content.hits[h].objectID + '): ' + content.hits[h].toString());
    }
});

index.search('query string', function(success, content) {
    for (var h in content.hits) {
        console.log('Hit(' + content.hits[h].objectID + '): ' + content.hits[h].toString());
    }
}, {'attributes': 'population,name', 'hitsPerPage': 50});
```

The search answer will be of the form:

```javascript
{
    "hasError": false,
    "errorMsg": null,
    "answer":
            { "hits":[
                        { "name": "<NAME>",
                          "company": "Vita Foods Inc.",
                          "email": "<EMAIL>",
                          "objectID": "6891Y2usk0",
                          "_highlightResult": {"name": {"value": "Betty <em>Jan</em><NAME>", "matchLevel": "full"}, 
                                               "company": {"value": "Vita Foods Inc.", "matchLevel": "none"},
                                               "email": {"value": "<EMAIL>", "matchLevel": "none"} }
                        },
                        { "name": "<NAME>", 
                          "company": "Ortman Mccain Co", 
                          "email": "<EMAIL>", 
                          "objectID": "ap78784310" 
                          "_highlightResult": {"name": {"value": "<NAME> <em>Dan</em>", "matchLevel": "full" },
                                               "company": {"value": "Ortman Mccain Co", "matchLevel": "none" },
                                               "email": {"highlighted": "<EMAIL>", "matchLevel": "none" } }
                        }],
                "page":0,
                "nbHits":2,
                "nbPages":1,
                "hitsPerPage:":20,
                "processingTimeMS":1,
                "query":"jan"
            }
}
``

Add a new object in the Index
-------------

Each entry in an index has a unique identifier called `objectID`. You have two way to add en entry in the index:

 1. Using automatic `objectID` assignement, you will be able to retrieve it in the answer.<commit_msg>Fixed formatting error<commit_after>Algolia Search API Client for Javascript
==================

This Javascript client let you easily use the Algolia Search API in a browser, it is compatible with most browsers:

 * Internet Explorer &ge; 8
 * Firefox &ge; 3.5
 * Google Chrome &ge; 3
 * Safari &ge; 4
 * Opera &ge; 12
 * Opera mobile &ge; 12
 * etc.

See [this wikipedia page](http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing#Browser_support) to have more details on supported browser (this library supports XDomainRequest extension and so supports IE8 and IE9).

Setup
-------------
To setup your project, follow these steps:

 1. Add a script include of `algoliasearch-min.js`
 2. Initialize the client with your ApplicationID, API-Key and list of hostnames (you can find all of them on your Algolia account)
 3. When you use this API client for search on a website, we strongly recommand to use a key with an ACL restricted "search" that you can retrieve with `client.addUserKey(["search"])`.

```javascript
  &lt;script src="algoliasearch-min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
    client = new AlgoliaSearch('ApplicationID', 'API-Key', 
                              ['http://api-u1-1.algolia.io', 'http://api-u1-2.algolia.io', 'api-u1-3.algolia.io']),
```

Quick Start
-------------

You can replace your ApplicationID and API-Key in `simple-ui.html` to test the Javascript client on your account.

General Principle
-------------

All API calls will return the result in a callback that takes two arguments:

 1. **sucess**: a boolean that is set to false when an error was found.
 2. **content**: the object containing answer (if an error was found, you can retrieve the error message in `content.message`)

Search 
-------------
To perform a search, you have just to initialize the index and perform a call to search.<br/>
You can optionally use the following arguments :

 * **attributes**: a string that contains attribute names to retrieve separated by a comma.<br/>By default all attributes are retrieved.
 * **attributesToHighlight**: a string that contains attribute names to highlight separated by a comma.<br/>By default all textual attributes are highlighted.
 * **minWordSizeForApprox1**: the minimum number of characters in a query word to accept one typo in this word.<br/>Defaults to 3.
 * **minWordSizeForApprox2**: the minimum number of characters in a query word to accept two typos in this word.<br/>Defaults to 7.
 * **getRankingInfo**: if set to 1, the result hits will contain ranking information in _rankingInfo attribute.
 * **page**: *(pagination parameter)* page to retrieve (zero base).<br/>Defaults to 0.
 * **hitsPerPage**: *(pagination parameter)* number of hits per page.<br/>Defaults to 10.
 * **aroundLatLng**: search for entries around a given latitude/longitude (specified as two floats separated by a comma).<br/>For example `aroundLatLng=47.316669,5.016670`).<br/>You can specify the maximum distance in meters with **aroundRadius parameter** (in meters).<br/>At indexing, you should specify geoloc of an object with _geoloc attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
 * **insideBoundingBox**: search entries inside a given area defined by the two extreme points of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat, p2Lng).<br/>For example `insideBoundingBox=47.3165,4.9665,47.3424,5.0201`).<br/>At indexing, you should specify geoloc of an object with _geoloc attribute (in the form `{"_geoloc":{"lat":48.853409, "lng":2.348800}}`)
 * **tags**: filter the query by a set of tags (contains a list of tags separated by a comma).<br/>At indexing, tags should be added in _tags attribute of objects (for example `{"_tags":["tag1","tag2"]}` )

````javascript
index = client.initIndex('MyIndexName');
index.search('query string', function(success, content) {
    for (var h in content.hits) {
        console.log('Hit(' + content.hits[h].objectID + '): ' + content.hits[h].toString());
    }
});

index.search('query string', function(success, content) {
    for (var h in content.hits) {
        console.log('Hit(' + content.hits[h].objectID + '): ' + content.hits[h].toString());
    }
}, {'attributes': 'population,name', 'hitsPerPage': 50});
```

The search answer will be of the form:

```javascript
{
    "hasError": false,
    "errorMsg": null,
    "answer":
            { "hits":[
                        { "name": "<NAME>",
                          "company": "Vita Foods Inc.",
                          "email": "<EMAIL>",
                          "objectID": "6891Y2usk0",
                          "_highlightResult": {"name": {"value": "Betty <em>Jan</em><NAME>", "matchLevel": "full"}, 
                                               "company": {"value": "Vita Foods Inc.", "matchLevel": "none"},
                                               "email": {"value": "<EMAIL>", "matchLevel": "none"} }
                        },
                        { "name": "<NAME>", 
                          "company": "Ortman Mccain Co", 
                          "email": "<EMAIL>", 
                          "objectID": "ap78784310" 
                          "_highlightResult": {"name": {"value": "<NAME> <em>Dan</em>", "matchLevel": "full" },
                                               "company": {"value": "Ortman Mccain Co", "matchLevel": "none" },
                                               "email": {"highlighted": "<EMAIL>", "matchLevel": "none" } }
                        }],
                "page":0,
                "nbHits":2,
                "nbPages":1,
                "hitsPerPage:":20,
                "processingTimeMS":1,
                "query":"jan"
            }
}
```

Add a new object in the Index
-------------

Each entry in an index has a unique identifier called `objectID`. You have two way to add en entry in the index:

 1. Using automatic `objectID` assignement, you will be able to retrieve it in the answer.
{'fraction_non_alphanumeric': 0.1392394413595827, 'fraction_numerical': 0.02136967861349487, 'mean_word_length': 2.7042692427547523, 'pattern_counts': {'":': 90, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '845008', 'n_tokens_mistral': 3478, 'n_tokens_neox': 3211, 'n_words': 1245}