forked from markguinn/silverstripe-shop-search
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A few small fixes + better documentation + sample solr config
- Loading branch information
Mark Guinn
committed
May 23, 2014
1 parent
b35e6cb
commit 81cd688
Showing
13 changed files
with
5,986 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
/** | ||
* Adds some methods to the Product class to list out all categories | ||
* a product is in. This is generally useful, but also really helps | ||
* with building search indexes. | ||
* | ||
* @author Mark Guinn <[email protected]> | ||
* @date 05.23.2014 | ||
* @package shop_search | ||
* @subpackage helpers | ||
*/ | ||
class ProductCategoryHelperMethods extends DataExtension | ||
{ | ||
/** | ||
* Includes Parent() and ProductCategories() and all the parent categories of each. | ||
* @param bool $recursive [optional] - include the parents of the categories as well? - default: true | ||
* @return array - array of productCategory records | ||
*/ | ||
protected function buildParentCategoriesArray($recursive=true) { | ||
$out = array(); | ||
|
||
// add the main parent | ||
$parent = $this->owner->Parent(); | ||
if (!$parent || !$parent->exists()) return $out; | ||
if ($parent->ClassName == 'ProductCategory') $out[$parent->ID] = $parent; | ||
|
||
if ($recursive) { | ||
foreach ($parent->getAncestors() as $rec) { | ||
if ($rec->ClassName == 'ProductCategory') $out[$rec->ID] = $rec; | ||
} | ||
} | ||
|
||
// add any secondary categories | ||
foreach ($this->owner->ProductCategories() as $cat) { | ||
$out[$cat->ID] = $cat; | ||
if ($recursive) { | ||
foreach ($cat->getAncestors() as $rec) { | ||
if ($rec->ClassName == 'ProductCategory') $out[$rec->ID] = $rec; | ||
} | ||
} | ||
} | ||
|
||
return $out; | ||
} | ||
|
||
|
||
/** | ||
* Includes Parent() and ProductCategories() and all the parent categories of each. | ||
* @return ArrayList - array of productCategory records | ||
*/ | ||
public function getAllCategories() { | ||
return new ArrayList( $this->buildParentCategoriesArray(false) ); | ||
} | ||
|
||
|
||
/** | ||
* Includes Parent() and ProductCategories() and all the parent categories of each. | ||
* @return ArrayList - array of productCategory records | ||
*/ | ||
public function getAllCategoriesRecursive() { | ||
return new ArrayList( $this->buildParentCategoriesArray(true) ); | ||
} | ||
|
||
|
||
/** | ||
* Includes Parent() and ProductCategories() | ||
* @return array - array of ID's | ||
*/ | ||
public function getAllCategoryIDs() { | ||
return array_keys( $this->buildParentCategoriesArray(false) ); | ||
} | ||
|
||
|
||
/** | ||
* Includes Parent() and ProductCategories() and all the parent categories of each. | ||
* @return array - array of ID's | ||
*/ | ||
public function getAllCategoryIDsRecursive() { | ||
return array_keys( $this->buildParentCategoriesArray(true) ); | ||
} | ||
|
||
|
||
/** | ||
* Returns an array of the titles of all the categories. | ||
* @return array - (strings) | ||
*/ | ||
public function getAllCategoryTitles() { | ||
$cats = $this->buildParentCategoriesArray(false); | ||
$out = array(); | ||
foreach ($cats as $cat) $out[] = $cat->Title; | ||
return $out; | ||
} | ||
|
||
|
||
/** | ||
* Returns an array of the titles of all the categories, including grandparents, etc | ||
* @return array - (strings) | ||
*/ | ||
public function getAllCategoryTitlesRecursive() { | ||
$cats = $this->buildParentCategoriesArray(true); | ||
$out = array(); | ||
foreach ($cats as $cat) $out[] = $cat->Title; | ||
return $out; | ||
} | ||
|
||
|
||
/** | ||
* Returns a string of the titles of all the categories. | ||
* @param string $sep | ||
* @return string | ||
*/ | ||
public function getJoinedCategoryTitles($sep = ', ') { | ||
return implode($sep, $this->getAllCategoryTitles()); | ||
} | ||
|
||
|
||
/** | ||
* Returns a string of the titles of all the categories. | ||
* @param string $sep | ||
* @return string | ||
*/ | ||
public function getJoinedCategoryTitlesRecursive($sep = ', ') { | ||
return implode($sep, $this->getAllCategoryTitlesRecursive()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The files in this folder are examples of how you might configure solr. | ||
They are largely copied verbatim from fulltextsearch-localsolr with | ||
some changes added for search suggestions and search-as-you-type. | ||
|
||
If you want to customise them just copy them to another folder or | ||
ditch them entirely and change your extrasPath under Solr::configure_server. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<!-- If this file is found in the config directory, it will only be | ||
loaded once at startup. If it is found in Solr's data | ||
directory, it will be re-loaded every commit. | ||
--> | ||
|
||
<elevate> | ||
<query text="foo bar"> | ||
<doc id="1" /> | ||
<doc id="2" /> | ||
<doc id="3" /> | ||
</query> | ||
|
||
<query text="ipod"> | ||
<doc id="MA147LL/A" /> <!-- put the actual ipod at the top --> | ||
<doc id="IW-02" exclude="true" /> <!-- exclude this cable --> | ||
</query> | ||
|
||
</elevate> |
Oops, something went wrong.