1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-06-07 23:34:00 +00:00

Minor code formatting

This commit is contained in:
Starbeamrainbowlabs 2019-08-17 01:19:04 +01:00
parent 5609506def
commit 7088990027
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -545,8 +545,7 @@ class search
$index = []; $index = [];
$terms = self::tokenize($source, true); $terms = self::tokenize($source, true);
foreach($terms as $term) foreach($terms as $term) {
{
// Skip over stop words (see https://en.wikipedia.org/wiki/Stop_words) // Skip over stop words (see https://en.wikipedia.org/wiki/Stop_words)
if(in_array($term[0], self::$stop_words)) continue; if(in_array($term[0], self::$stop_words)) continue;
@ -566,8 +565,7 @@ class search
* @param bool $capture_offsets Whether to capture & return the character offsets of the tokens detected. If true, then each token returned will be an array in the form [ token, char_offset ]. * @param bool $capture_offsets Whether to capture & return the character offsets of the tokens detected. If true, then each token returned will be an array in the form [ token, char_offset ].
* @return array An array of raw tokens extracted from the specified source string. * @return array An array of raw tokens extracted from the specified source string.
*/ */
public static function tokenize($source, $capture_offsets = false) public static function tokenize($source, $capture_offsets = false) {
{
/** Normalises input characters for searching & indexing */ /** Normalises input characters for searching & indexing */
static $literator; if($literator == null) $literator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD); static $literator; if($literator == null) $literator = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD);
@ -664,15 +662,12 @@ class search
* @param array $changed An array to be filled with the nterms of all the changed entries. * @param array $changed An array to be filled with the nterms of all the changed entries.
* @param array $removed An array to be filled with the nterms of all the removed entries. * @param array $removed An array to be filled with the nterms of all the removed entries.
*/ */
public static function compare_indexes($oldindex, $newindex, &$changed, &$removed) public static function compare_indexes($oldindex, $newindex, &$changed, &$removed) {
{ foreach($oldindex as $nterm => $entry) {
foreach($oldindex as $nterm => $entry)
{
if(!isset($newindex[$nterm])) if(!isset($newindex[$nterm]))
$removed[] = $nterm; $removed[] = $nterm;
} }
foreach($newindex as $nterm => $entry) foreach($newindex as $nterm => $entry) {
{
if(!isset($oldindex[$nterm]) or // If this word is new if(!isset($oldindex[$nterm]) or // If this word is new
$newindex[$nterm] !== $oldindex[$nterm]) // If this word has changed $newindex[$nterm] !== $oldindex[$nterm]) // If this word has changed
$changed[$nterm] = $newindex[$nterm]; $changed[$nterm] = $newindex[$nterm];
@ -690,8 +685,8 @@ class search
} }
/** /**
* Reads in and parses an inverted index, measuring the time it takes to do so. * Reads in and parses an inverted index, measuring the time it takes to do so.
* @param string $invindex_filename The path to the file inverted index to parse. * @param string $invindex_filename The path to the file inverted index to parse.
* @return boolean Whether the measurement was actually able to take place. Usually this will be true, but it will return false if it can't find the specified index. * @return bool Whether the measurement was actually able to take place. Usually this will be true, but it will return false if it can't find the specified index.
*/ */
public static function measure_invindex_load_time($invindex_filename) { public static function measure_invindex_load_time($invindex_filename) {
global $env; global $env;