
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@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
The npm package @craftercms/search receives a total of 224 weekly downloads. As such, @craftercms/search popularity was classified as not popular.
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 2 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.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.