@JLernDesign, Iâm sorry for not being clear enough! In my code sample, I showed you how it would work with useSiteSearch and the REST API, one right after the other, and it made it look like they were related when theyâre actually two separate things. Sorry about that 
No, thatâs only applicable to the CMA JS client (the REST API). client in this case being the DatoCMS CMA JS client (NOT the CDA one! Site Search has nothing to do with GraphQL).
If youâre using useSiteSearch(), then to initialize the search, you have to do one of two things (neither related to the CMA client at all):
Option 1: Properly set the initial query
const { state, error, data } = useSiteSearch({ client,
initialState: {
query: 'benefits' // Inside initialState
}
});
(In your original code, the problem was that query: 'benefits' wasnât inside the initialState object)
Option 2: Set the state somewhere else
In my example, that would be this section:
onMounted(async () => {
// Perform the site search lookup
state.query = "benefits";
});
In real-world usage, youâd probably tie that state to a text box where the user types in their query.
Yes, in the vue-datocms readme: https://github.com/datocms/vue-datocms/tree/master/src/composables/useSiteSearch
In particular, look at the complete example to see a real-world implementation with a textbox: https://github.com/datocms/vue-datocms/blob/master/examples/src/SiteSearch/index.vue
No, because site searches are the result of crawling your frontend with our web spider, NOT the results from the CMS (CDA or CMA).
To test site searches, you would just make a HTTP call against the site search endpoint: Search result â Content Management API â DatoCMS
You can use the JS client for that (a simple node or browser script), or you can use a HTTP client like Postman or the open-source Bruno.
Separately, if site search isnât what you wanted and you actually wanted to query and look things up from the CDA directly, you would use our GraphQL filters for that.
Site search is for crawling and indexing the built HTML of your frontend. This means, for example:
- The crawled results are completely detached from your DatoCMS schema and records.
- The spider only sees what your visitors see (and sometimes even less, because it canât execute fancy clientside JS)
- Itâs good enough for simple blog posts, etc., but itâs not a replacement for more featureful search engines like Google or Algolia, etc. Thereâs also the open-source TypeSense if you need something more powerful and customizable
Overall, it depends on your use case. If you want a simple text box search where your user can type in a basic string and you return a list of matching pages, our basic site search might be good enough.
If you need something more complex, like the ability to break down results by category (blog posts vs product pages, for example), youâd either have to use another search engine, or at least work around the limitations of our search engine and try to categorize the results yourself by URL path or such.
Our own docs site uses this latter, âfakeâ categorization technique:
Those sections are not inherently part of the search results. We classify them based on URL path matching. Example code (sorry, this is React and not Vue): https://github.com/datocms/astro-website/blob/main/src/layouts/docs/BaseLayout/Search/index.tsx (the Areas[] array and related functions).
Sorry for the long post!
TLDR takeaways:
- Site search crawls your built frontend and returns uncategorized keyword matches by relevance
- Site search has nothing to do with the CDA
- To test site search, you have to make an API call, using either the JS CMA client or a HTTP testing app (Postman, Bruno, cURL, your IDE, etc.)
useSiteSearch requires you to provide the query either inside an initialState{} object in init, or by altering the destructured state property of its hook elsewhere (like in a textbox). See the readme and example there for details.