Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@craftercms/search
Advanced tools
This package contains tools for integrating your application with Crafter Search.
All of Crafter CMS packages can be used either via npm or in plain html/javascript via regular script imports.
yarn
or npm
yarn add @craftercms/search
ornpm install @craftercms/search
craftercms
. You can access all craftercms' packages and functions under this root.search
package depends on rxjs
, @craftercms/utils
, @craftercms/classes
; make sure to import those too before the search
script.Tip: Once you've imported the scripts, type craftercms
on your browser's dev tools console to inspect the package(s)
<script src="https://unpkg.com/rxjs"></script>
<script src="https://unpkg.com/@craftercms/utils"></script>
<script src="https://unpkg.com/@craftercms/classes"></script>
<script src="https://unpkg.com/@craftercms/content"></script>
<script src="https://unpkg.com/@craftercms/search"></script>
<script>
(function ({ search, content }, { operators }) {
const { map } = operators;
const { search, createQuery } = search;
const { parseDescriptor, preParseSearchResults } = content;
search(
createQuery({
query: {
bool: {
filter: [/*...*/]
}
}
}),
{ baseUrl: 'http://localhost:8080', site: 'editorial' }
).pipe(
map(({ hits, ...rest }) => ({
...rest,
hits: hits.map(({ _source }) => parseDescriptor(
preParseSearchResults(_source)
))
}))
).subscribe((results) => {
// Do stuff with results...
});
})(craftercms, rxjs);
</script>
The examples below assume usage in the style of using via npm. If you're using the bundles,
directly importing as a script in the browser, these functions will be under the global variable
named craftercms.search
(i.e. window.craftercms.search
).
Returns the result for a given query.
search(query: Query)
Parameters | |
---|---|
query | The query object |
config | Crafter configuration. Optional. Default value in here. |
Map model
import { crafterConf } from '@craftercms/classes';
import { search, createQuery } from '@craftercms/search';
import { map } from 'rxjs/operators';
import { parseDescriptor, preParseSearchResults } from '@craftercms/content';
// First, set the Crafter configuration to cache your config.
// All subsequent calls to `getConfig` will use that configuration.
crafterConf.configure({
baseUrl: 'http://localhost:8080',
site: 'wordify'
});
const query = 'lorem';
const fields = ['headline_s', 'blurb_t'];
const contentTypes = ['/page/post', '/component/post'];
search(
createQuery({
query: {
'bool': {
'filter': [
{ 'bool': { 'should': contentTypes.map(id => ({ 'match': { 'content-type': id } })) } },
{ 'multi_match': { 'query': query, 'fields': fields } }
]
}
}
}),
// If you didn't pre-configure, you may send config values as second param here
// { baseUrl: 'http://localhost:8080', site: 'wordify' }
).pipe(
map(({ hits, ...rest }) => {
return {
...rest,
hits: hits.map(({ _source }) => parseDescriptor(
preParseSearchResults(_source)
))
};
})
).subscribe((results) => {
console.log(results);
});
You may use a different config by supplying the config object at the service call invoking time.
import { search, createQuery } from '@craftercms/search';
//Create query
const query = createQuery({
"query" : {
"match_all" : {}
}
});
search(query, { baseUrl: 'http://localhost:8080', site: 'editorial' }).subscribe((results) => {
// ...
});
FAQs
Crafter CMS search service and associated tools
We found that @craftercms/search demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.