Wiki‎ > ‎Tweaking Philologic‎ > ‎

This script written by Mark creates an index file called artid2pg.idx which links DIV ids to page numbers and allows you to generate links to pages from DIV-level search results. comes in the goodies directory of Philologic.

If you would also like to include page numbers next to KWIC results, please see KwicPageNumbers.


A brief description of how to get page numbers to display after headwords or other DIV-level object searches.


Copy from the goodies directory of your Philologic install into the $SYSDIR (the install directory) for the database you are working on. For example:

cp /var/lib/philologic/goodies/ /var/lib/philologic/databases/mydictionary/


Execute the script from within the $SYSDIR of your database like so:

cd /var/lib/philologic/databases/mydictionary/
ls TEXTS/ | perl > artid2pg.idx

Modify DivDisplayLine in

Change DivDisplayLine in to look something like this:

sub DivDisplayLine {
local ($thedivline, $results, $rtn, $subresults);
$thedivline = $_[0];
@results=split(/\t/, $thedivline);
$rtn .= "<br><a href=\"";
$rtn .= $PHILOGETOBJECT . "?c." . $results[0];
$rtn .= "." . $dbname . "\">";
$rtn .= "$results[1]</a>";
@subresults = split(":", $results[0]);
#$rtn .= &getbiblioLine($subresults[0], "link");

$pagelink = DivPageLink($results[0]);
return ($rtn . " " . $pagelink);

Add DivPageLink to

Add a new subroutine to that looks like this:

# -----------------------------------------------------------------------
# DivPageLink: Using to create artid2pg.idx, then
# using this subroutine enables you to get a page link from
# your div search results
# -----------------------------------------------------------------------

sub DivPageLink {
local ($objectid, $rtn, $IMGSVR, $art2pgfil, $linin, $ress, $imgfilname);
$IMGSVR = "";
$objectid = $_[0];

$objectid =~ s/^(\d+:)\d+:/\1/;

#print "<br><br>objectid: $objectid<br><br>";

if (!$readartid2pg) {
$art2pgfil = $SYSTEM_DIR . "artid2pg.idx";
open (ART2PG, "$art2pgfil");
while ($linin = <ART2PG>) {
@ress = split("\t", $linin);
$obj2internalpage{$ress[1]} = $ress[2];
$obj2realpage{$ress[1]} = $ress[4];
close (ART2PG);

$internalpage = $obj2internalpage{$objectid};

$realpage = $obj2realpage{$objectid};

$realpage =~ s/^0*//;
#print "real: $realpage<br>";

return "(page <a href='/cgi-bin/philologic/" . $internalpage . ".$dbname'>" . $realpage . "</a>)";


Variant or Possible Bugfix

A new version of was generated for use a project where it was noticed that the first two objects on each page were incorrectly being linked to the previous page. Here's a diff of the old script on the left and new script on the right:

<     $div = 0;
> $div = -1;
< if (/<div/) {
> if (/<div2/) {

These differences between this script and the stock one that comes with Philologic 3 are simple. First, we only increment $div when we see <div2, not just <div, because only <div2 signifies a new entry in DSAL dicos. Secondly, we start $div at -1 instead of 1, because the first object is index 0 and we incremement before writing out the index.

Do all databases need that? We're not sure right now.

Subpages (1): Artid2pg.idx