mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 12:05:29 +00:00
add quickstart script
enable FTS automatically in quickstart add a little idempotency to quickstart script find _config.php better configure and reindex as well add default index to quickstart add configure_server to quickstart
This commit is contained in:
parent
718b1d4e30
commit
fa6a412d72
88
bin/fts_quickstart
Normal file
88
bin/fts_quickstart
Normal file
@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "Installing Java SDK..."
|
||||
# Find our package manager
|
||||
if VERB="$( command -v apt-get )" 2> /dev/null; then
|
||||
echo "Debian-based OS detected"
|
||||
sudo apt-get install -y openjdk-8-jdk 2> /dev/null
|
||||
elif VERB="$( command -v yum )" 2> /dev/null; then
|
||||
echo "Modern Red Hat-based OS detected"
|
||||
sudo yum install -y java-1.8.0-openjdk.x86_64 2> /dev/null
|
||||
else
|
||||
echo "No valid package manager detected; try one of apt-get, yum."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "/opt/solr" ]; then
|
||||
printf "Installing Solr 4"
|
||||
# Acquire and unzip solr4
|
||||
wget http://archive.apache.org/dist/lucene/solr/4.10.4/solr-4.10.4.tgz 2> /dev/null && printf "."
|
||||
tar -xf solr-4.10.4.tgz 2> /dev/null && printf "."
|
||||
rm solr-4.10.4.tgz 2> /dev/null && printf "."
|
||||
|
||||
# Set the defaults in /opt/solr
|
||||
sudo mv solr-4.10.4 /opt/solr 2> /dev/null && printf "."
|
||||
mv /opt/solr/example /opt/solr/core 2> /dev/null && echo "."
|
||||
fi
|
||||
|
||||
if [ ! -f "/etc/init.d/solr" ]; then
|
||||
echo "Installing Solr daemon..."
|
||||
# Set up the daemon so that solr will run on startup
|
||||
sudo cp vendor/silverstripe/fulltextsearch/docs/examples/daemon_script /etc/init.d/solr 2> /dev/null
|
||||
sudo chmod +x /etc/init.d/solr 2> /dev/null
|
||||
sudo chkconfig --add solr 2> /dev/null
|
||||
fi
|
||||
|
||||
# Get solr running
|
||||
sudo /etc/init.d/solr start 2> /dev/null
|
||||
|
||||
# Determine application dir
|
||||
if [ -d app ]; then
|
||||
APPDIR="app"
|
||||
elif [ -d mysite ]; then
|
||||
APPDIR="mysite"
|
||||
else
|
||||
echo "Can't detect application dir - skipping default index creating"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check to see if it has been enabled in _config.php
|
||||
grep -i "FulltextSearchable::enable(" "$APPDIR/_config.php" 2> /dev/null
|
||||
if [ "$?" != 0 ]; then
|
||||
echo "Enabling FulltextSearchable in _config.php..."
|
||||
if [ ! -f "$APPDIR/_config.php" ]; then
|
||||
echo "<?php" > "$APPDIR/_config.php"
|
||||
echo "" >> "$APPDIR/_config.php"
|
||||
fi
|
||||
echo "" >> "$APPDIR/_config.php"
|
||||
echo "# Enable Fulltextsearch" >> "$APPDIR/_config.php"
|
||||
echo "\\SilverStripe\\ORM\\Search\\FulltextSearchable::enable();" >> "$APPDIR/_config.php" >> "$APPDIR/_config.php"
|
||||
echo "\\SilverStripe\\FullTextSearch\\Solr\\Solr::configure_server([" >> "$APPDIR/_config.php"
|
||||
echo " 'indexstore' => [" >> "$APPDIR/_config.php"
|
||||
echo " 'mode' => 'file'," >> "$APPDIR/_config.php"
|
||||
echo " 'path' => BASE_PATH . '/.solr'" >> "$APPDIR/_config.php"
|
||||
echo " ]" >> "$APPDIR/_config.php"
|
||||
echo "]);" >> "$APPDIR/_config.php"
|
||||
fi
|
||||
|
||||
# Determine code dir
|
||||
if [ -d "$APPDIR/src" ]; then
|
||||
CODEDIR="$APPDIR/src"
|
||||
elif [ -d "$APPDIR/code" ]; then
|
||||
CODEDIR="$APPDIR/code"
|
||||
else
|
||||
echo "Can't detect code dir - skipping default index creating"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a default index
|
||||
if [ ! -f "$CODEDIR/FulltextSearch/DefaultIndex.php" ]; then
|
||||
echo "Creating default index..."
|
||||
mkdir -p "$CODEDIR/FulltextSearch"
|
||||
cp vendor/silverstripe/fulltextsearch/docs/examples/default_index.php.example "$CODEDIR/FulltextSearch/DefaultIndex.php"
|
||||
fi
|
||||
|
||||
vendor/bin/sake dev/tasks/Solr_Configure
|
||||
vendor/bin/sake dev/tasks/Solr_Reindex
|
||||
|
||||
echo "Quickstart complete!"
|
@ -35,3 +35,19 @@ offers its own extensions, and there is some behaviour (such as getting the full
|
||||
and running) that each connector deals with itself, in a way best suited to that search engine's design.
|
||||
|
||||
## Quick start
|
||||
|
||||
If you are running on a Linux-based system, you can get up and running quickly with the quickstart script, like so:
|
||||
|
||||
```bash
|
||||
composer require silverstripe/fulltextsearch && vendor/bin/fts_quickstart
|
||||
```
|
||||
|
||||
This will:
|
||||
|
||||
- Install the required Java SDK (using `apt-get` or `yum`)
|
||||
- Install Solr 4
|
||||
- Set up a daemon to run Solr on startup
|
||||
- Start Solr
|
||||
- Enable `FulltextSearchable` in your `_config.php` (and create one if you don't have one)
|
||||
|
||||
The simply adding `$SearchForm` to a template and flushing the template cache should add a search text box to your site.
|
||||
|
Loading…
x
Reference in New Issue
Block a user