Recent Changes - Search:

Home Pages Pidgin   Azarennya (S|N) Mac Textanium Reference ToDo Food Local Edit

Local: Hide

Language: Hide

Fantasy: Hide

SciFi: Hide

Film: Hide

Music: Hide

REALbasic: Hide

ResourcesGarageUniversityWebRingForums:REALElfDataPlugins and Code:BKeeneyDeclareSubEinhugurJoeRestrepoTempelmannZAZ

Coding: Hide

Forums:PowWebPHPWebmasterCodingWalkersPerlIntroMonksPHPJavaScriptToolboxUnobtrusiveJavaScriptJavaScriptCompressorRegularExpressions (test)JSLintSQLCocoaCocoaBuilderCocoaDevCocoaLabAppleScriptBBSUserlandFaqintoshFileMakerFileMakerTipsFileMakerWorldFileMakerPlugins

Science: Hide

History: Hide

1421

News/Politics: Hide

Cults/Crime: Hide

ClambakeInfidels

Miscellaneous: Hide

DiscussionFileFormatForEntries

  • Entries per file. One file may contain just a single entry, or it may contain two or more.
    • Searching one large file is faster than searching many little files.
    • Saving one large file is slower than saving one little file. (But if only I can save entries, this shouldn't matter.)
  • Saving previous versions. Previous versions of an entry may be saved in the same file as the current version, saved in a different file, or simply discarded.
    • The files that get searched should contain only the latest entries; therefore old versions of entries should be saved in different files (if they aren't discarded).
    • If the editor is not publicly accessible, then there is less pressure to have a system that preserves old versions of entries.
  • Editable in a text editor? An entry file may be laid out like a text file, so that it can be read and edited with a plain text editor, or it may be stored in some other format.
    • Text should be readable in a text editor so that the text remains accessible if the new Wiki software doesn't work out for whatever reason.

Record-file format

Markup schemes tend to use four hyphens to mark a horizontal line. Let's take advantage of that, except that we look for lines with four hyphens AND extra data:

  • ----######### -- Four hyphens followed by one or more hash marks serves as the boundary line between records. (My Wiki is supposed to remove such lines before passing records to the markup translator.)
  • ----:key value -- Four hyphens and a colon mark a field. The first word in the field is the field name; subsequent text, to the end of the line, is the field value. (The point of a field is not only to allow exact searches for field values, but also searches for all values greater than or less than a given value.) (My Wiki is supposed to remove such lines before passing records to the markup translator.)
  • -------- -- Four hyphens followed by anything else is ignored (i.e., passed on to the markup translator unchanged). This is to make life easier for those who are in the habit of putting text on the same line as the four hyphens intended to produce a horizontal line. :)

Code to retrieve records

$records = array();
$record = array();
$record['text'] = '';
$record['meta'] = '';

while (!feof($handle)) {
    $line = getline($handle);
    if ($line == '') break;
    $head = substr($line, 0, 5);
    if ($head == '----#') {
        if (match($record, $criteria)) {
            $records[] = $record;
        }
        $record['text'] = '';
        $record['meta'] = '';
    } elseif ($head == '----:') {
        $record['meta'] .= "\n" . substr($line, 5);
    } else {
        $record['text'] .= $line;
    }
}
if ($record['text'] != '' or $record['meta'] != '') {
    if (match($record, $criteria)) {
        $records[] = $record;
    }
}

Code to compare records

A record's fields are stored as a single string (in $record['meta']). You search for a newline followed by a field name, then check the value after the name against the criteria.

Criteria also come as a multiline string, with each criterion (e.g., "name < John") separated from the next with a newline.

function match($record, $criteria) {
    // $criteria should be an array of arrays: field name, operator, field value.
    // To find phrase in text, field name is "" and operator is "^" (contains).
    // For each item in $criteria
        // If field name is blank, search $record['text'].
        // Else, search $record['meta'].
}

Operators and code:

$match = true;
$value = strtolower($value);   // Field value in the record.
$sought = strtolower($sought); // Value in the criterion.

switch ($operator) {
    case '^':
        if (strpos($value, $sought) === false) $match = false; break;
    case '=':
    case '==':
        if ($value != $sought) $match = false; break;
    case '!=':
    case '<>':
        if ($value == $sought) $match = false; break;
    case '<':
        if ($value >= $sought) $match = false; break;
    case '<=':
        if ($value > $sought) $match = false; break;
    case '>':
        if ($value <= $sought) $match = false; break;
    case '>=':
        if ($value < $sought) $match = false; break;
    case '!^':
        if (strpos($value, $sought) !== false) $match = false; break;
    default:
        $match = false;
}
Edit - History - Print - Recent Changes - Search
Page last modified on February 22, 2008, at 03:13 PM