Indexing your first site | laravel-site-search | Spatie

 SPATIE

  Laravel Site Search
======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-site-search](https://spatie.be/docs/laravel-site-search/v1)  Basic-usage  Indexing your first site

 Version   v3   v1

 Other versions for crawler [v3](https://spatie.be/docs/laravel-site-search/v3) [v1](https://spatie.be/docs/laravel-site-search/v1)

- [ Introduction ](https://spatie.be/docs/laravel-site-search/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-site-search/v1/support-us)
- [ Installation and setup ](https://spatie.be/docs/laravel-site-search/v1/installation-setup)
- [ About us ](https://spatie.be/docs/laravel-site-search/v1/about-us)
- [ Questions and issues ](https://spatie.be/docs/laravel-site-search/v1/questions-issues)
- [ Requirements ](https://spatie.be/docs/laravel-site-search/v1/requirements)
- [ Changelog ](https://spatie.be/docs/laravel-site-search/v1/changelog)

Basic usage
-----------

- [ High level overview ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/high-level-overview)
- [ Indexing your first site ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/indexing-your-first-site)
- [ Retrieving results ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/retrieving-results)
- [ Preventing content from being indexed ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/preventing-content-from-being-indexed)
- [ Using a search profile ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/using-a-search-profile)
- [ Authenticating requests ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/authenticating-requests)
- [ Listing indexes ](https://spatie.be/docs/laravel-site-search/v1/basic-usage/listing-indexes)

Advanced usage
--------------

- [ Creating multiple search indexes ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/creating-multiple-search-indexes)
- [ Using a custom indexer ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/using-a-custom-indexer)
- [ Indexing extra properties ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/indexing-extra-properties)
- [ Customizing Meilisearch settings ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/customizing-meilisearch-settings)
- [ Available events ](https://spatie.be/docs/laravel-site-search/v1/advanced-usage/available-events)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/laravel-site-search                                                                                                                                                                                                                                    `

Indexing your first site
========================

On this page, you'll learn how to create an index, populate it by crawling your site, and retrieving results. Let's do this!

First, you can run this command to define a site that needs to be indexed.

```
php artisan site-search:create-index
```

This command will ask for a name for your index, and the URL of your site that should be crawled.

After that you should run this command to start a queued job that crawls your site, and puts the content in a search index:

```
php artisan site-search:crawl
```

Finally, you can use the `Search` class to perform a query on your index.

```
use Spatie\SiteSearch\Search;

$searchResults = Search::onIndex($indexName)
    ->query('your query')
    ->get();
```

This is how you could render the results in a Blade view

```

    @foreach($searchResults->hits as $hit)

                {{ $hit->url }}
                {{ $hit->title() }}
                {!! $hit->highlightedSnippet() !!}

    @endforeach

```
