GalaxyHelpers.staticSearch()

All Galaxy websites includes a javascript library accessible under the namespace window.GalaxyHelpers

To work with static data in json, we advise window.GalaxyHelpers.staticSearch()

.staticSearch() takes an object as a parameter and returns a promise

Getting data from a static JSON

Use the property url in the param object

GalaxyHelpers.staticSearch({
    url: 'jsonURL', // URL of the static json file
}).then((data) => {
    console.log(data);
    const results = data.results;
});

Filtering data from a static JSON

We include a basic filtering to limit, paginate and have a key: value filtering

Use the property filters in the param object

GalaxyHelpers.staticSearch({
    url: 'jsonURL', // URL of the static json file
    filters: {
        limit: 18, // optional
        page: 2, // optional
        has_photo: 1, // to get only items with has_photo: 1 for example
    }
}).then(data => {
    console.log(data);
    const results = data.results;
});

If you need custom filters, you can do them once you received the content. See below "Filters"

Parameters

GalaxyHelpers.staticSearch(options)

Data source

You have 2 different types of sources for the data:

  • providing the URL of a static JSON

  • providing an array with your data.

options.url

string

URL of the JSON with the source data

options.data

array

alternative way to send data, provide an array of objects to be filtered

options.filters

object

Filtering options

Filters

What can you use inside filters?

  • limit (number)

  • page (number)

  • key_inside_JSON : value_inside_json : for example has_photo:1 or offers_id: 4

  • special for OGH: latitude, longitude, radius

Each filter is linked with AND. For example has_photo: 1 AND is_featured: 1

GalaxyHelpers.staticSearch({
    url: 'myJSON',
    filters: {
        is_featured: 1,
        has_photo: 1
    }
})

If you provide an array as a value, by default the filtering is using OR for the options:

GalaxyHelpers.staticSearch({
    url: 'myJSON',
    filters: {
        is_featured: 0, // only NON featured items
        offers_id: [22, 55] // If "offers_id" has the value 22 OR 55
    }
})

If you need to filter on an array (for example an array of categories, an array of locations, etc.. you can use the feature __ids_ for your field (link to section)

New in the release 2022-03-21: ability to blacklist

Blacklisting a category

By adding the prefix blacklist: , instead of filtering on items that have something, you can blacklist items that have this category

GalaxyHelpers.staticSearch({
    url: 'myJSON',
    filters: {
        'is_featured': 0,
        'offers_id': [22, 55] // If "offers_id" has the value 22 or 55
        'blacklist:offers_id': 33 // If "offers_id" does NOT have the value 33 
    }
})

Response

GalaxyHelpers.staticSearch(options).then(data => console.log(data))

property

type

description

count

number

Number of items matching your search

results

array

Results matching your search + limit + pagination

resultsFullList

array

All results matching your search, regardless of limit and pagination

hasMore

boolean

Indicates if there is another page of result after. Only present if you do a request with a limit

Examples

Here are some examples to copy/paste if you want to play with it

/* Create some fake data */
const hotels = [
    {
        id: 1,
        name: "Hotel ABC",
        is_featured: 1,
        offers_id: [22,33,44,55]
    },
    {
        id: 2,
        name: "Hotel ZYX",
        is_featured: 1,
        offers_id: [22,55]
    },
    {
        id: 3,
        name: "Hotel AZERTY",
        is_featured: 0,
        offers_id: [55]
    },
    {
        id: 4,
        name: "Hotel QWERTY",
        is_featured: 1,
        offers_id: [33]
    }
];

/* Example 1*/

GalaxyHelpers.staticSearch({
    data: hotels, // array with your data. use "url" to provide the URL of a static JSON
    filters: {
        is_featured: 1,
        offers_id: 55
    }
}).then(data => {
    console.log("Research 1", data.results);
    /* Will return "Hotel ABC" and "Hotel ZYX",
      because both have "is_featured:1" AND includes "55" in offers_id */
});

/* Exemple 2 */

GalaxyHelpers.staticSearch({
    data: hotels, // array with your data. use "url" to provide the URL of a static JSON
    filters: {
        offers_id: [22, 55]
    }
}).then(data => {
    console.log("Research 2", data.results);
    /* Will return "Hotel ABC", "Hotel ZYX" and "Hotel AZERTY" 
    because each have 22 OR 55 in the offers_id */
});

Last updated