mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-09-29 12:49:23 +02:00
Improved docs
This commit is contained in:
parent
c464c826d0
commit
02e8f7338e
@ -52,38 +52,30 @@ Basic usage is a four step process:
|
|||||||
|
|
||||||
1). Define an index in SilverStripe (Note: The specific connector index instance - that's what defines which engine gets used)
|
1). Define an index in SilverStripe (Note: The specific connector index instance - that's what defines which engine gets used)
|
||||||
|
|
||||||
```php
|
// File: mysite/code/MyIndex.php:
|
||||||
mysite/code/MyIndex.php:
|
<?php
|
||||||
|
class MyIndex extends SolrIndex {
|
||||||
<?php
|
function init() {
|
||||||
|
$this->addClass('Page');
|
||||||
class MyIndex extends SolrIndex {
|
$this->addFulltextField('DocumentContents');
|
||||||
function init() {
|
}
|
||||||
$this->addClass('Page');
|
|
||||||
$this->addFulltextField('DocumentContents');
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
2). Add something to the index (Note: You can also just update an existing document in the CMS. but adding _existing_ objects to the index is connector specific)
|
2). Add something to the index (Note: You can also just update an existing document in the CMS. but adding _existing_ objects to the index is connector specific)
|
||||||
|
|
||||||
```php
|
$page = new Page(array('Contents' => 'Help me. My house is on fire. This is less than optimal.'));
|
||||||
$page = new Page(array('Contents' => 'Help me. My house is on fire. This is less than optimal.'));
|
$page->write();
|
||||||
$page->write();
|
|
||||||
```
|
Note: There's usually a connector-specific "reindex" task for this.
|
||||||
|
|
||||||
3). Build a query
|
3). Build a query
|
||||||
|
|
||||||
```php
|
$query = new SearchQuery();
|
||||||
$query = new SearchQuery();
|
$query->search('My house is on fire');
|
||||||
$query->search('My house is on fire');
|
|
||||||
```
|
|
||||||
|
|
||||||
4). Apply that query to an index
|
4). Apply that query to an index
|
||||||
|
|
||||||
```php
|
$results = singleton('MyIndex')->search($query);
|
||||||
$results = singleton($index)->search($query);
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that for most connectors, changes won't be searchable until _after_ the request that triggered the change.
|
Note that for most connectors, changes won't be searchable until _after_ the request that triggered the change.
|
||||||
|
|
||||||
|
94
docs/Solr.md
94
docs/Solr.md
@ -1,67 +1,83 @@
|
|||||||
# Solr connector for SilverStripe fulltextsearch module
|
# Solr connector for SilverStripe fulltextsearch module
|
||||||
|
|
||||||
This module provides a fulltextsearch module connector to Solr.
|
## Introduction
|
||||||
|
|
||||||
|
This module provides a fulltextsearch module connector to Solr.
|
||||||
It works with Solr in multi-core mode. It needs to be able to update Solr configuration files, and has modes for
|
It works with Solr in multi-core mode. It needs to be able to update Solr configuration files, and has modes for
|
||||||
doing this by direct file access (when Solr shares a server with SilverStripe) and by WebDAV (when it's on a different server).
|
doing this by direct file access (when Solr shares a server with SilverStripe) and by WebDAV (when it's on a different server).
|
||||||
|
|
||||||
Since Solr is Java based, this module requires a Java runtime to be present on the server Solr is running on (not necessarily
|
See the helpful [Solr Tutorial](http://lucene.apache.org/fulltextsearch/api/doc-files/tutorial.html), for more on cores and querying.
|
||||||
the same physical machine the SilverStripe server is on).
|
|
||||||
|
|
||||||
* See the helpful [Solr Tutorial](http://lucene.apache.org/solr/api/doc-files/tutorial.html), for more on cores and querying.
|
## Requirements
|
||||||
|
|
||||||
## Getting started quickly (dev mode)
|
Since Solr is Java based, it requires Java 1.5 or greater installed.
|
||||||
|
It also requires a servlet container such as Tomcat, Jetty, or Resin.
|
||||||
|
Jetty is already packaged with the module.
|
||||||
|
|
||||||
Configure Solr in file mode
|
See the official [Solr installation docs](http://wiki.apache.org/solr/SolrInstall)
|
||||||
|
for more information.
|
||||||
|
|
||||||
```php
|
Note that these requirements are for the Solr server environment,
|
||||||
mysite/_config.php:
|
which doesn't have to be the same physical machine as the SilverStripe webhost.
|
||||||
|
|
||||||
<?php
|
## Installation
|
||||||
|
|
||||||
Solr::configure_server(isset($solr_config) ? $solr_config : array(
|
Configure Solr in file mode. The 'path' directory has to be writeable
|
||||||
'host' => 'localhost',
|
by the user the Solr search server is started with (see below).
|
||||||
'indexstore' => array(
|
|
||||||
'mode' => 'file',
|
// File: mysite/_config.php:
|
||||||
'path' => BASE_PATH . '/fulltextsearch/thirdparty/solr/server/solr'
|
<?php
|
||||||
)
|
SearchUpdater::bind_manipulation_capture();
|
||||||
));
|
Solr::configure_server(isset($solr_config) ? $solr_config : array(
|
||||||
```
|
'host' => 'localhost',
|
||||||
|
'indexstore' => array(
|
||||||
|
'mode' => 'file',
|
||||||
|
'path' => BASE_PATH . '/fulltextsearch/thirdparty/fulltextsearch/server/solr'
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
Create an index
|
Create an index
|
||||||
|
|
||||||
```php
|
// File: mysite/code/MyIndex.php:
|
||||||
mysite/code/MyIndex.php:
|
<?php
|
||||||
|
class MyIndex extends SolrIndex {
|
||||||
<?php
|
function init() {
|
||||||
|
$this->addClass('Page');
|
||||||
class MyIndex extends SolrIndex {
|
$this->addAllFulltextFields();
|
||||||
function init() {
|
}
|
||||||
$this->addClass('Page');
|
|
||||||
$this->addAllFulltextFields();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
* Open a terminal, change to thirdparty/solr/server and start Solr by running `java -jar start.jar`
|
Start the search server (via CLI, in a separate terminal window or background process)
|
||||||
* In another terminal run the configure task `sake dev/tasks/Solr_configure`
|
|
||||||
* Then run the configure task `sake dev/tasks/Solr_reindex`
|
|
||||||
|
|
||||||
You can now visit http://localhost:8983/solr/MyIndex/admin/ to search the contents of the now created Solr index via the native SOLR UI
|
cd fulltextsearc/thirdparty/fulltextsearch/server/
|
||||||
|
java -jar start.jar
|
||||||
|
|
||||||
|
Initialize the configuration (via CLI)
|
||||||
|
|
||||||
|
sake dev/tasks/Solr_configure
|
||||||
|
|
||||||
|
Reindex
|
||||||
|
|
||||||
|
sake dev/tasks/Solr_reindex
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
It is possible to manually replicate the data automatically sent to Solr when saving/publishing in SilverStripe,
|
You can visit `http://localhost:8983/solr/MyIndex/admin/`
|
||||||
which is useful when debugging front-end queries, see: thirdparty/solr/server/silverstripe-solr-test.xml but roughly:
|
to search the contents of the now created Solr index via the native SOLR web interface.
|
||||||
|
Replace "MyIndex" with your own index definition as required.
|
||||||
|
|
||||||
```
|
It is possible to manually replicate the data automatically sent
|
||||||
#> java -Durl=http://localhost:8983/solr/MyIndex/update/ -Dtype=text/xml -jar post.jar silverstripe-solr-test.xml
|
to Solr when saving/publishing in SilverStripe,
|
||||||
```
|
which is useful when debugging front-end queries,
|
||||||
|
see `thirdparty/fulltextsearch/server/silverstripe-solr-test.xml`.
|
||||||
|
|
||||||
-----
|
java -Durl=http://localhost:8983/solr/MyIndex/update/ -Dtype=text/xml -jar post.jar silverstripe-solr-test.xml
|
||||||
|
|
||||||
These instructions will get you running quickly, but the Solr indexes will be stored as binary files inside your SilverStripe project. You can also
|
These instructions will get you running quickly, but the Solr indexes will be stored as binary files inside your SilverStripe project. You can also
|
||||||
copy the thirdparty/solr directory somewhere else. The instructions above will still apply - just set the path value
|
copy the thirdparty/solr directory somewhere else. The instructions above will still apply - just set the path value
|
||||||
in mysite/_config.php to point to this other location, and of course run `java -jar start.jar` from the new directory,
|
in mysite/_config.php to point to this other location, and of course run `java -jar start.jar` from the new directory,
|
||||||
not the thirdparty one.
|
not the thirdparty one.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user