forked from front/redisearch
-
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.
- Loading branch information
1 parent
e509041
commit a26147d
Showing
13 changed files
with
617 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch; | ||
|
||
class Document { | ||
protected $id; | ||
protected $score = 1.0; | ||
protected $noSave = false; | ||
protected $replace = false; | ||
protected $fields = array(); | ||
protected $payload; | ||
protected $language; | ||
|
||
public function __construct( $id = null ) { | ||
$this->id = $id ?? uniqid(true); | ||
} | ||
|
||
public function getDefinition() { | ||
$properties = [ | ||
$this->getId(), | ||
$this->getScore(), | ||
]; | ||
|
||
if ( $this->isNoSave() ) { | ||
$properties[] = 'NOSAVE'; | ||
} | ||
|
||
if ( $this->isReplace() ) { | ||
$properties[] = 'REPLACE'; | ||
} | ||
|
||
if ( !is_null( $this->getLanguage() ) ) { | ||
$properties[] = 'LANGUAGE'; | ||
$properties[] = $this->getLanguage(); | ||
} | ||
|
||
if ( !is_null( $this->getPayload() ) ) { | ||
$properties[] = 'PAYLOAD'; | ||
$properties[] = $this->getPayload(); | ||
} | ||
|
||
$properties[] = 'FIELDS'; | ||
|
||
foreach ( $this->getFields() as $name => $value) { | ||
if ( isset( $value ) ) { | ||
$properties[] = $name; | ||
$properties[] = $value; | ||
} | ||
} | ||
|
||
return $properties; | ||
} | ||
|
||
public function setFields( $fields = array() ) { | ||
$this->fields = $fields; | ||
return $this; | ||
} | ||
|
||
public function getFields() { | ||
return $this->fields; | ||
} | ||
|
||
public function getId() { | ||
return $this->id; | ||
} | ||
|
||
public function setId( $id ) { | ||
$this->id = $id; | ||
return $this; | ||
} | ||
|
||
public function getScore() { | ||
return $this->score; | ||
} | ||
|
||
public function setScore( $score ) { | ||
if ($score < 0.0 || $score > 1.0) { | ||
$score = 1.0; | ||
} | ||
|
||
$this->score = $score; | ||
return $this; | ||
} | ||
|
||
public function isNoSave() { | ||
return $this->noSave; | ||
} | ||
|
||
public function setNoSave( $noSave ) { | ||
$this->noSave = $noSave; | ||
return $this; | ||
} | ||
|
||
public function isReplace() { | ||
return $this->replace; | ||
} | ||
|
||
public function setReplace( $replace ) { | ||
$this->replace = $replace; | ||
return $this; | ||
} | ||
|
||
public function getPayload() { | ||
return $this->payload; | ||
} | ||
|
||
public function setPayload( $payload ) { | ||
$this->payload = $payload; | ||
return $this; | ||
} | ||
|
||
public function getLanguage() { | ||
return $this->language; | ||
} | ||
|
||
public function setLanguage( $language ) { | ||
$this->language = $language; | ||
return $this; | ||
} | ||
|
||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
abstract class AbstractField implements FieldInterface { | ||
protected $name; | ||
protected $value; | ||
|
||
public function __construct( $name, $value = null ) { | ||
$this->name = $name; | ||
$this->value = $value; | ||
} | ||
|
||
public function getName() { | ||
return $this->name; | ||
} | ||
|
||
public function getValue() { | ||
return $this->value; | ||
} | ||
|
||
public function setValue( $value ) { | ||
$this->value = $value; | ||
return $this; | ||
} | ||
|
||
public function getDefinition() { | ||
return [ | ||
$this->getName(), | ||
$this->getType(), | ||
]; | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
interface FieldInterface { | ||
public function getDefinition(); | ||
public function getType(); | ||
public function getName(); | ||
public function getValue(); | ||
public function setValue($value); | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
class GeoField extends AbstractField { | ||
use Noindex; | ||
|
||
public function getType() { | ||
return 'GEO'; | ||
} | ||
|
||
public function getDefinition() { | ||
$properties = parent::getDefinition(); | ||
|
||
if ( $this->isNoindex() ) { | ||
$properties[] = 'NOINDEX'; | ||
} | ||
|
||
return $properties; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
class GeoLocation { | ||
protected $name; | ||
protected $longitude; | ||
protected $latitude; | ||
|
||
public function __construct( $longitude, $latitude ) { | ||
$this->longitude = $longitude; | ||
$this->latitude = $latitude; | ||
} | ||
|
||
public function __toString() { | ||
return "{$this->longitude} {$this->latitude}"; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
trait Noindex { | ||
protected $isNoindex = false; | ||
|
||
public function isNoindex() { | ||
return $this->isNoindex; | ||
} | ||
|
||
public function setNoindex( $noindex ) { | ||
$this->isNoindex = $noindex; | ||
return $this; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
class NumericField extends AbstractField { | ||
use Sortable; | ||
use Noindex; | ||
|
||
public function getType() { | ||
return 'NUMERIC'; | ||
} | ||
|
||
public function getDefinition() { | ||
$properties = parent::getDefinition(); | ||
|
||
if ( $this->isSortable() ) { | ||
$properties[] = 'SORTABLE'; | ||
} | ||
|
||
if ( $this->isNoindex() ) { | ||
$properties[] = 'NOINDEX'; | ||
} | ||
|
||
return $properties; | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
trait Sortable { | ||
protected $isSortable = false; | ||
|
||
public function isSortable() { | ||
return $this->isSortable; | ||
} | ||
|
||
public function setSortable( $sortable ) { | ||
$this->isSortable = $sortable; | ||
return $this; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
class TagField extends AbstractField { | ||
use Sortable; | ||
use Noindex; | ||
|
||
protected $separator = ','; | ||
|
||
public function getType() { | ||
return 'TAG'; | ||
} | ||
|
||
public function getSeparator() { | ||
return $this->separator; | ||
} | ||
|
||
public function setSeparator( $separator ) { | ||
$this->separator = $separator; | ||
return $this; | ||
} | ||
|
||
public function getDefinition() { | ||
$properties = parent::getDefinition(); | ||
|
||
$properties[] = 'SEPARATOR'; | ||
$properties[] = $this->getSeparator(); | ||
|
||
if ( $this->isSortable() ) { | ||
$properties[] = 'SORTABLE'; | ||
} | ||
|
||
if ( $this->isNoindex() ) { | ||
$properties[] = 'NOINDEX'; | ||
} | ||
|
||
return $properties; | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace FKRediSearch\RediSearch\Fields; | ||
|
||
class TextField extends AbstractField { | ||
use Sortable; | ||
use Noindex; | ||
|
||
protected $weight = 1.0; | ||
protected $noStem = false; | ||
|
||
public function getType() { | ||
return 'TEXT'; | ||
} | ||
|
||
public function getWeight() { | ||
return $this->weight; | ||
} | ||
|
||
public function setWeight( $weight ) { | ||
$this->weight = $weight; | ||
return $this; | ||
} | ||
|
||
public function isNoStem() { | ||
return $this->noStem; | ||
} | ||
|
||
public function setNoStem( $noStem ) { | ||
$this->noStem = $noStem; | ||
return $this; | ||
} | ||
|
||
public function getDefinition() { | ||
$properties = parent::getDefinition(); | ||
if ($this->isNoStem()) { | ||
$properties[] = 'NOSTEM'; | ||
} | ||
|
||
$properties[] = 'WEIGHT'; | ||
$properties[] = $this->getWeight(); | ||
|
||
if ( $this->isSortable() ) { | ||
$properties[] = 'SORTABLE'; | ||
} | ||
|
||
if ( $this->isNoindex() ) { | ||
$properties[] = 'NOINDEX'; | ||
} | ||
|
||
return $properties; | ||
} | ||
} |
Oops, something went wrong.