Search
Contents
Description
Uses an explorer interface to search and returns scored results.
Parameters
Name | Type | Attributes | Default | Details | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
clearCache |
boolean |
<optional> |
false |
Clear all server-side caches |
|||||||||||||||
count |
number |
<optional> |
10 |
How many results to return. |
|||||||||||||||
facets |
object |
<optional> |
Which facets in facet categories to filter on.
|
||||||||||||||||
interface |
string |
<required> |
undefined |
Which explorer interface to use. |
|||||||||||||||
locale |
string |
<optional> |
from HTTP request or server default |
Which locale to return search results in (may require translated localization files). |
|||||||||||||||
name |
string |
<optional> |
q |
Which request parameter contains the searchString. |
|||||||||||||||
page |
number |
<optional> |
1 |
Which page of search results to return. Takes count into account. |
|||||||||||||||
searchString |
string |
<required> |
'' |
The actual terms you want to find. Typically what a user types into a text input. |
Returns
Name | Type | Details |
---|---|---|
count |
number |
How many results was returned. |
expand |
boolean |
Whether or not synonym expansion was used. When false only searches the from field and adds from the to field. When true searches both from and to fields and adds from both to and from fields. |
facetCategories |
object |
Information needed to render facets on a webpage. |
hits |
Array.<object> |
The search results based on explorer interface configuration. |
pages |
number |
How many pages there are (for the current search). |
pagination |
Array.<object> |
Information needed to render a paginator on a webpage. |
params |
object |
Which parameters the search function was passed or defaulted to. |
removedStopWords |
Array.<string> |
Which stop-words was removed before querying. |
synonymsObj |
object |
What synonyms where found and added based on the initial search string. |
total |
number |
How many search results are there in total. |
Example
import {search} from '/lib/explorer'; (1)
export const get = ({ (2)
params: { (3)
count = 10, (4)
q: searchString = '' (5)
} = {} (6)
}) => ({ (7)
body: search({ (8)
count, (9)
interface: 'default', (10)
//name: 'q', (11)
searchString (12)
}),
contentType: 'application/json;charset=utf-8' (13)
});
1 | Import search function from explorer library. |
2 | Export a function to handle HTTP get requests. |
3 | Use ECMAScript deconstruction to pluck the request parameters we want. |
4 | Pluck the count parameter and default to 10 if it’s not passed. |
5 | Pluck the q parameter and default to 10 if it’s not passed and store in a variable called searchString. |
6 | If no parameters are passed default to an empty object so deconstruction to default values still work. |
7 | Let the exported get function return a response object. |
8 | Store the result of the search function in the response object body property. |
9 | Pass on the count variable as a parameter to the search function. |
10 | Hardcode that the search function is executed using the interface named default. |
11 | Here we could change which request parameter contains the searchString. |
12 | Pass on the searchString variable as a parameter to the search function. |
13 | Since the response body property is a pure Javascript object just return it as UTF-8 encoded json. |
Sample response
{
"params": { (1)
"count": 1,
"facets": {},
"interface": "default",
"locale": "en",
"name": "q",
"searchString": "test or not",
"start": 0
},
"count": 1, (2)
"expand": false, (3)
"pages": 19, (4)
"total": 19, (5)
"removedStopWords": [ (6)
"or",
"not"
],
"synonymsObj": { (7)
"Example synonyms": { (8)
"test": { (9)
"score": 3.862200975418091,
"to": [ (10)
"expression",
"term"
]
}
}
},
"hits": [ (11)
{
"title": "Request a demo of Enonic XP - Enonic",
"text": "… TimelineCareersContact us Enonic MarketEnonic DiscussEnonic SupportDemo requestSubmit your details below to get a 5 days <b>test</b> drive in the cloud.
Email (to send you trial links) Name I consent to receive communications in digital channels about…",
"href": "https://www.enonic.com/try-now"
}
],
"facetCategories": [ (12)
{
"activeCount": 0, (13)
"clearHref": "?", (14)
"href": "?language=English&language=Norsk", (15)
"inactiveCount": 2, (16)
"name": "Language", (17)
"facets": [ (18)
{
"href": "?language=English", (19)
"name": "English", (20)
"removeHref": "?", (21)
"count": 0 (22)
},
{
"href": "?language=Norsk",
"name": "Norsk",
"removeHref": "?",
"count": 0
}
]
}
],
"pagination": [ (23)
{
"text": "1" (24)
},
{
"href": "?q=test&page=2", (25)
"text": "2"
},
{
"href": "?q=test&page=3",
"text": "3"
},
{
"href": "?q=test&page=4",
"text": "4"
},
{
"href": "?q=test&page=5",
"text": "5"
},
{
"href": "?q=test&page=6",
"text": "6"
},
{
"href": "?q=test&page=7",
"text": "7"
},
{
"href": "?q=test&page=8",
"text": "8"
},
{
"href": "?q=test&page=9",
"text": "9"
},
{
"href": "?q=test&page=10",
"text": "10"
},
{
"href": "?q=test&page=2",
"text": "Next" (26)
},
{
"href": "?q=test&page=19",
"text": "Last"
}
]
}
1 | Which parameters the search function was passed or defaulted to. |
2 | How many results was returned. |
3 | Whether or not synonym expansion was used. When false only searches the from field and adds from the to field. When true searches both from and to fields and adds from both to and from fields. |
4 | How many pages there are. |
5 | How many results there are in total. |
6 | Which stop-words was removed before querying the interface. |
7 | What synonyms where found and added based on the initial search string. |
8 | Thesaurus name (in which thesaurus was the synonyms found). |
9 | Synonym name (which synonym was found based on the search string). |
10 | List of synonyms added when querying the interface. |
11 | The actual search results in this page. |
12 | How many results would there be with various facets. Based on advanced aggregated filter queries. |
13 | How many facets are activated in this category. |
14 | Url query to use to clear all filters in current category. |
15 | Url query to use to activate all filters in current category. |
16 | How many facets are NOT activated in this category. |
17 | The name of the current facet category. |
18 | List of facets in this category. |
19 | Url query to use to activate this facet filter. |
20 | Name of the current facet. |
21 | Url query to use to inactivate this facet filter. |
22 | How many results there would be if this facet filter was activated. |
23 | Information needed to render a paginator on a webpage. |
24 | A good text to use when rendering a paginator on a webpage. |
25 | Url query to use to go to that page. |
26 | This text can be localized. |