mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-10-22 12:05:29 +00:00
Merge branch 'chillu/pulls/dataobject-index'
This commit is contained in:
commit
e37c3a265b
@ -170,7 +170,7 @@ and tell Solr to use this folder with the `extraspath` configuration setting.
|
|||||||
'extraspath' => Director::baseFolder() . '/mysite/data/solr/',
|
'extraspath' => Director::baseFolder() . '/mysite/data/solr/',
|
||||||
));
|
));
|
||||||
|
|
||||||
Please run the `Solr_configure` task for the changes to take effect.
|
Please run the `Solr_Configure` task for the changes to take effect.
|
||||||
|
|
||||||
Note: You can also define those on an index-by-index basis by
|
Note: You can also define those on an index-by-index basis by
|
||||||
implementing `SolrIndex->getExtrasPath()`.
|
implementing `SolrIndex->getExtrasPath()`.
|
||||||
@ -468,15 +468,71 @@ Create a custom `solrconfig.xml` (see "File-based configuration").
|
|||||||
Add the following XML configuration.
|
Add the following XML configuration.
|
||||||
|
|
||||||
<lib dir="./contrib/extraction/lib/" />
|
<lib dir="./contrib/extraction/lib/" />
|
||||||
<lib dir="./dist" />
|
<lib dir="./dist" />
|
||||||
|
|
||||||
Now apply the configuration:
|
Now apply the configuration:
|
||||||
|
|
||||||
sake dev/tasks/Solr_configure
|
sake dev/tasks/Solr_Configure
|
||||||
|
|
||||||
Now you can use Solr text extraction either directly through the HTTP API,
|
Now you can use Solr text extraction either directly through the HTTP API,
|
||||||
or indirectly through the ["textextraction" module](https://github.com/silverstripe-labs/silverstripe-textextraction).
|
or indirectly through the ["textextraction" module](https://github.com/silverstripe-labs/silverstripe-textextraction).
|
||||||
|
|
||||||
|
## Adding DataObject classes to Solr search
|
||||||
|
|
||||||
|
If you create a class that extends `DataObject` (and not `Page`) then it won't be automatically added to the search
|
||||||
|
index. You'll have to make some changes to add it in.
|
||||||
|
|
||||||
|
So, let's take an example of `StaffMember`:
|
||||||
|
|
||||||
|
:::php
|
||||||
|
<?php
|
||||||
|
class StaffMember extends DataObject {
|
||||||
|
private static $db = array(
|
||||||
|
'Name' => 'Varchar(255)',
|
||||||
|
'Abstract' => 'Text',
|
||||||
|
'PhoneNumber' => 'Varchar(50)'
|
||||||
|
);
|
||||||
|
|
||||||
|
public function Link($action = 'show') {
|
||||||
|
return Controller::join_links('my-controller', $action, $this->ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getShowInSearch() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
This `DataObject` class has the minimum code necessary to allow it to be viewed in the site search.
|
||||||
|
|
||||||
|
`Link()` will return a URL for where a user goes to view the data in more detail in the search results.
|
||||||
|
`Name` will be used as the result title, and `Abstract` the summary of the staff member which will show under the
|
||||||
|
search result title.
|
||||||
|
`getShowInSearch` is required to get the record to show in search, since all results are filtered by `ShowInSearch`.
|
||||||
|
|
||||||
|
So with that, let's create a new class called `MySolrSearchIndex`:
|
||||||
|
|
||||||
|
:::php
|
||||||
|
<?php
|
||||||
|
class MySolrSearchIndex extends SolrIndex {
|
||||||
|
|
||||||
|
public function init() {
|
||||||
|
$this->addClass('SiteTree');
|
||||||
|
$this->addClass('StaffMember');
|
||||||
|
|
||||||
|
$this->addAllFulltextFields();
|
||||||
|
$this->addFilterField('ShowInSearch');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
This is a copy/paste of the existing configuration but with the addition of `StaffMember`.
|
||||||
|
|
||||||
|
Once you've created the above classes and run `flush=1`, access `dev/tasks/Solr_Configure` and `dev/tasks/Solr_Reindex`
|
||||||
|
to tell Solr about the new index you've just created. This will add `StaffMember` and the text fields it has to the
|
||||||
|
index. Now when you search on the site using `MySolrSearchIndex->search()`,
|
||||||
|
the `StaffMember` results will show alongside normal `Page` results.
|
||||||
|
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
### Using the web admin interface
|
### Using the web admin interface
|
||||||
|
Loading…
x
Reference in New Issue
Block a user