mnoGoSearch 3.2.26 reference manual: Full-featured search engine software | ||
---|---|---|
Prev | Chapter 3. Indexing | Next |
When indexer tries to insert a new URL into database or is trying to index an existing one, it first of all checks whether this URL has corresponding Server, Realm or Subnet command given in indexer.conf. URLs without corresponding Server, Realm or Subnet command are not indexed. By default those URLs which are already in database and have no Server/Realm/Subnet commands will be deleted from database. It may happen for example after removing some Server/Realm/Subnet commands from indexer.conf.
These commands have following format:
Server [Method] [SubSection] <pattern> [alias] Realm [Method] [CaseType] [MatchType] [CmpType] <pattern> [alias] Subnet [Method] [MatchType] <pattern>
Mandatory parameter pattern specify an URL, or it's part, or pattern to compare.
Optional parameter method specify an document action for this command. May take values: Allow, Disallow, HrefOnly, CheckOnly, Skip, CheckMP3, CheckMP3Only. By default, the value Allow is used.
Value Allow specify that all corresponding documents will be indexed and scanned for new links. Depends on Content-Type appropriate external parser is executed if need.
Value Disallow specify that all corresponding documents will be ignored and deleted from database, if its was placed into before.
Value HrefOnly specify that all corresponding documents will be only scanned for new links (not indexed). This is useful, for example, for mail archives indexing, when index pages is only scanned to detect new messages for indexing.
Server HrefOnly Page http://www.mail-archive.com/general%40mnogosearch.org/ Server Allow Path http://www.mail-archive.com/general%40mnogosearch.org/
Value CheckOnly specify that all corresponding documents will be requested by HTTP HEAD request, not HTTP GET, i.e. only brief info about documents (size, last modified, content type) will be fetched. This allow, for example, check links on your site:
Server HrefOnly http://www.mnogosearch.org/ Realm CheckOnly *
These commands instruct indexer to scan all documents on www.mnogosearch.org site and collect all links. Brief info about every document outside www.mnogosearch.org will be requested by HEAD method. After indexing done, indexer -S command will show status for all documents from this site.
Value Skip specify that all corresponding documents will be skipped while indexing. This is useful when need temporarily disable reindexing several sites, but able search on. These documents will marked as expired.
Value CheckMP3 specify that corresponding documents will be checked for MP3 tags along if its Content-Type is equal to audio/mpeg. This is useful, for example, if remote server supply application/octet-stream as Content-Type for MP3 files. If this tag is present, these files will indexed as MP3 file, otherwise its will be processed according to Content-Type.
This value is equal to CheckMP3, but if MP3 tag is not present, processing on Content-Type will not be taken.
Use optional SubSection parameter to specify server's checking behavior. Values of SubSection are the same with "Follow" command arguments. SubSection value must be one of the following: page, path, site, world and has "path" value by default. If SubSection is not specified, current "Follow" value will be used. So, the only Server site http://localhost/ command and combination of Follow site and Server http://localhost/ have the same effect.
path subsection
When indexer seeks for a "Server" command corresponding to an URL it checks that the discovered URL starts with URL given in Server command argument but without trailing file name. For example, if Server path http://localhost/path/to/index.html is given, all URLs which have http://localhost/path/to/ at the beginning correspond to this Server command.
The following commands have the same effect except that they insert different URLs into database:
Server path http://localhost/path/to/index.html Server path http://localhost/path/to/index Server path http://localhost/path/to/index.cgi?q=bla Server path http://localhost/path/to/index?q=bla
site subsection
indexer checks that the discovered URL have the same hostname with URL given in Server command. For example, Server site http://localhost/path/to/a.html will allow to index whole http://localhost/ server.
world subsection
If world subsection is specified in Server command, it has the same effect that URL is considered to match this Server command. See explanation below.
page subsection
This subsection describes the only one URL given in Server argument.
subsection in news:// schema
Subsection is always considered as "site" for news:// URL schema. This is because news:// schema has no nested paths like ftp:// or http:// Use Server news://news.server.com/ to index whole news server or for example Server news://news.server.com/udm to index all messages from "udm" hierarchy.
Optional parameter CaseType is specify the case sensitivity for string comparison, it can take one of follow value: case - case insensitive comparison, or nocase - case sensitive comparison.
Optional parameter CmpType is specify the type of comparison and can take two value: Regex and String. String wildcards is default match type. You can use ? and * signs in URLMask parameters, they means "one character" and "any number of characters" respectively. For example, if you want to index all HTTP sites in .ru domain, use this command:
Realm http://*.ru/*
Regex comparison type takes a regular expression as it's argument. Activate regex comparison type using Regex keyword. For example, you can describe everything in .ru domain using regex comparison type:
Realm Regex ^http://.*\.ru/
Optional parameter MatchType means match type. There are Match and NoMatch possible values with Match as default. Realm NoMatch has reverse effect. It means that URL that does not match given pattern will correspond to this Realm command. For example, use this command to index everything without .com domain:
Realm NoMatch http://*.com/*
Optional alias argument allows providing very complicated URL rewrite more powerful than other aliasing mechanism. Take a look the Section called Aliases for alias argument usage explanation. Alias works only with Regex comparison type and has no effect with String type.
This is the main command of the indexer.conf file. It is used to add servers or their parts to be indexed. This command also says indexer to insert given URL into database at startup.
E.g. command Server http://localhost/ allows to index whole http://localhost/ server. You can also specify some path to index server subsection: Server http://localhost/subsection/.
Note: You can suppress indexer behavior to add URL given in Server command by using -q indexer command line argument. It is useful when you have hundreds or thousands Server commands and their URLs are already in database. This allows having more quick indexer startup.
Realm command is a more powerful means of describing web area to be indexed. It works almost like Server command but takes a regular expression or string wildcards as it's pattern parameter and do not insert any URL into database for indexing.
Subnet command is another way to describe web area to be indexed. It works almost like Server command but takes a string wildcards as it's pattern argument which is compared against IP address instead of URL. Argument may have * and ? signs, they means "one character" and "any number of characters" respectively. For example, if you want to index all HTTP sites in your local subnet, use this command:
Subnet 192.168.*.*
You may use "NoMatch" optional argument. For example, if you want to index everything without 195.x.x.x subnet, use:
Subnet NoMatch 195.*.*.*
Indexer seeks for "Server" and "Realm" commands in order of their appearance. Thus if you want to give different parameters to e.g. whole server and its subsection you should add subsection line before whole server's. Imagine that you have server subdirectory which contains news articles. Surely those articles are to be reindexed more often than the rest of the server. The following combination may be useful in such cases:
# Add subsection Period 200000 Server http://servername/news/ # Add server Period 600000 Server http://servername/
These commands give different reindexing period for /news/ subdirectory comparing with the period of server as a whole. indexer will choose the first "Server" record for the http://servername/news/page1.html as far as it matches and was given first.
The default behavior of indexer is to follow through links having correspondent Server/Realm command in the indexer.conf file. It also jumps between servers if both of them are present in indexer.conf either directly in Server command or indirectly in Realm command. For example, there are two Server commands:
Server http://www/ Server http://web/
When indexing http://www/page1.html indexer WILL follow the link http://web/page2.html if the last one has been found. Note that these pages are on different servers, but BOTH of them have correspondent Server record.
If one of the Server command is deleted, indexer will remove all expired URLs from this server during next reindexing.
The third scheme is very useful for indexer -i -f url.txt running. You may maintain required servers in the url.txt. When new URL is added into url.txt indexer will index the server of this URL during next startup.
mnoGoSearch has an alias support making it possible to index sites taking information from another location. For example, if you index local web server, it is possible to take pages directly from disk without involving your web server in indexing process. Another example is building of search engine for primary site and using its mirror while indexing. There are several ways of using aliases.
Format of "Alias" indexer.conf command:
Alias <masterURL> <mirrorURL>
E.g. you wish to index http://search.mnogo.ru/ using nearest German mirror http://www.gstammw.de/mirrors/mnoGoSearch/. Add these lines in your indexer.conf:
Server http://search.mnogo.ru/ Alias http://search.mnogo.ru/ http://www.gstammw.de/mirrors/mnoGoSearch/
search.cgi will display URLs from master site http://search.mnogo.ru/ but indexer will take corresponding page from mirror site http://www.gstammw.de/mirrors/mnoGoSearch/.
Another example. If you want to index everything in udm.net domain and one of servers, for example http://home.udm.net/ is stored on local machine in /home/httpd/htdocs/ directory. These commands will be useful:
Realm http://*.udm.net/ Alias http://home.udm.net/ file:/home/httpd/htdocs/
Indexer will take home.udm.net from local disk and index other sites using HTTP.
Aliases are searched in the order of their appearance in indexer.conf. So, you can create different aliases for server and its parts:
# First, create alias for example for /stat/ directory which # is not under common location: Alias http://home.udm.net/stat/ file:/usr/local/stat/htdocs/ # Then create alias for the rest of the server: Alias http://home.udm.net/ file:/usr/local/apache/htdocs/
Note: if you change the order of these commands, alias for /stat/ directory will never be found.
You may specify location used by indexer as an optional argument for Server command:
Server http://home.udm.net/ file:/home/httpd/htdocs/
Aliases in Realm command is a very powerful feature based on regular expressions. The idea of aliases in Realm command implementation is similar to how PHP preg_replace() function works. Aliases in Realm command work only if "regex" match type is used and does not work with "string" match type.
Use this syntax for Realm aliases:
Realm regex <URL_pattern> <alias_pattern>
Indexer searches URL for matches to URL_pattern and builds an URL alias using alias_pattern. alias_pattern may contain references of the form $n. Where n is a number in the range of 0-9. Every such reference will be replaced by text captured by the n'th parenthesized pattern. $0 refers to text matched by the whole pattern. Opening parentheses are counted from left to right (starting from 1) to obtain the number of the capturing subpattern.
Example: your company hosts several hundreds users with their domains in the form of www.username.yourname.com. Every user's site is stored on disk in "htdocs" under user's home directory: /home/username/htdocs/.
You may write this command into indexer.conf (note that dot '.' character has a special meaning in regular expressions and must be escaped with '\' sign when dot is used in usual meaning):
Realm regex (http://www\.)(.*)(\.yourname\.com/)(.*) file:/home/$2/htdocs/$4
Imagine indexer process http://www.john.yourname.com/news/index.html page. It will build patterns from $0 to $4:
$0 = 'http://www.john.yourname.com/news/index.htm' (whole patter match)
$1 = 'http://www.' subpattern matches '(http://www\.)'
$2 = 'john' subpattern matches '(.*)'
$3 = '.yourname.com/' subpattern matches '(\.yourname\.com/)'
$4 = '/news/index.html' subpattern matches '(.*)'
Then indexer will compose alias using $2 and $4 patterns:
file:/home/john/htdocs/news/index.html
and will use the result as document location to fetch it.
You may also specify "AliasProg" command for aliasing purposes. AliasProg is useful for major web hosting companies which want to index their web space taking documents directly from a disk without having to involve web server in indexing process. Documents layout may be very complex to describe it using alias in Realm command. AliasProg is an external program that can be called, that takes a URL and returns one string with the appropriate alias to stdout. Use $1 to pass URL to command line.
For example this AliasProg command uses 'replace' command from MySQL distribution and replaces URL substring http://www.apache.org/ to file:/usr/local/apache/htdocs/:
AliasProg "echo $1 | /usr/local/mysql/bin/mysql/replace http://www.apache.org/ file:/usr/local/apache/htdocs/"
You may also write your own very complex program to process URLs.
The ReverseAlias indexer.conf command allows URL mapping before URL is inserted into database. Unlike Alias command, that triggers mapping right before a document is downloaded, ReverseAlias command triggers mapping after the link is found.
ReverseAlias http://name2/ http://name2.yourname.com/ Server http://name2.yourname.com/
All links with short server name will be mapped to links with full server name before they are inserted into database.
One of the possible use is cutting various unnecessary strings like PHPSESSION=XXXX
E.g. cutting from URL like http://www/a.php?PHPSESSION=XXX, when PHPSESSION is the only parameter. The question sign is deleted as well:
ReverseAlias regex (http://[^?]*)[?]PHPSESSION=[^&]*$ $1$2
Cutting from URL like w/a.php?PHPSESSION=xxx&.., i.e. when PHPSESSION is the first parameter, but there are other parameters following it. The '&' sign after PHPSESSION is deleted as well. Question mark is not deleted:
ReverseAlias regex (http://[^?]*[?])PHPSESSION=[^&]*&(.*) $1$2
Cutting from URL like http://www/a.php?a=b&PHPSESSION=xxx or http://www/a.php?a=b&PHPSESSION=xxx&c=d, where PHPSESSION is not the first parameter. The '&' sign before PHPSESSION is deleted:
ReverseAlias regex (http://.*)&PHPSESSION=[^&]*(.*) $1$2
It is also possible to define aliases in search template (search.htm). The Alias command in search.htm is identical to the one in indexer.conf, however it is active during searching and not indexation.
The syntax of the search.htm Alias command is the same as in indexer.conf:
Alias <find-prefix> <replace-prefix>
For example, there is the following command in search.htm:
Alias http://localhost/ http://www.mnogo.ru/
Search returned a page with the following URL:
http://localhost/news/article10.html
As a result, the $(DU) variable will be replace NOT with this URL:
http://localhost/news/article10.html
but with the following URL (that results in processing with Alias):
http://www.mnogo.ru/news/article10.html
Since version 3.2.7 mnoGoSearch has "ServerTable" indexer.conf command.
When ServerTable mysql://user:pass@host/dbname/tablename[?srvinfo=infotablename] is specified, indexer will load servers information from given tablename SQL table, and will load servers parameters from given infotablename SQL table. If srvinfo parameter is not specified, parameters will be loaded from srvinfo table. Check the structure for server and srvinfo tables in create/mysql/create.txt file. If there is no structure example for your database, take it as an example. Please send us structure for your database at <devel@mnogosearch.org>!
You may use several ServerTable command to load servers information from different tables.
Servers table consists of all necessary fields which describe servers parameters. Field names have correspondent indexer.conf commands. For example, "period" field corresponds "Period" indexer.conf command. Default field values are the same with default indexer.conf parameters.
"gindex" field corresponds "Index" command. Name is slightly changed to avoid SQL reserved word usage.
Description for several fields see in the Section called Database schema in Chapter 9.
Note: Only those servers are read from the table where "active" field has 1 value and "parent" field has 0 value. This is useful to allow users to submit new URLs into servers table and give administrator a possibility to approve added URLs.
Flush server.active to inactive for all server table records. Use this command to deactivate all command in ServerTable before load new from indexer.conf or from other ServerTable.
mnoGoSearch indexer can use external parsers to index various file types (mime types).
Parser is an executable program which converts one of the mime types to text/plain or text/html. For example, if you have postscript files, you can use ps2ascii parser (filter), which reads postscript file from stdin and produces ascii to stdout.
Indexer supports four types of parsers that can:
read data from stdin and send result to stdout
read data from file and send result to stdout
read data from file and send result to file
read data from stdin and send result to file
Configure mime types
Configure your web server to send appropriate "Content-Type" header. For apache, have a look at mime.types file, most mime types are already defined there.
If you want to index local files or via ftp use "AddType" command in indexer.conf to associate file name extensions with their mime types. For example:
AddType text/html *.html
Add lines with parsers definitions. Lines have the following format with three arguments:
Mime <from_mime> <to_mime> <command line>
For example, the following line defines parser for man pages:
# Use deroff for parsing man pages ( *.man ) Mime application/x-troff-man text/plain deroff
This parser will take data from stdin and output result to stdout.
Many parsers can not operate on stdin and require a file to read from. In this case indexer creates a temporary file in /tmp and will remove it when parser exits. Use $1 macro in parser command line to substitute file name. For example, Mime command for "catdoc" MS Word to ASCII converters may look like this:
Mime application/msword text/plain "/usr/bin/catdoc -a $1"
If your parser writes result into output file, use $2 macro. indexer will replace $2 by temporary file name, start parser, read result from this temporary file then remove it. For example:
Mime application/msword text/plain "/usr/bin/catdoc -a $1 >$2"
The parser above will read data from first temporary file and write result to second one. Both temporary files will be removed when parser exits. Note that result of usage of this parser will be absolutely the same with the previous one, but they use different execution mode: file->stdout and file->file correspondingly.
To avoid a indexer hang on parser execution you may specify in your indexer.conf amount of time in seconds for parser execution by ParserTimeOut command. For example:
ParserTimeOut 600
Default value is 300 seconds, i.e. 5 minutes.
You can use pipes in parser's command line. For example, these lines will be useful to index gzipped man pages from local disk:
AddType application/x-gzipped-man *.1.gz *.2.gz *.3.gz *.4.gz Mime application/x-gzipped-man text/plain "zcat | deroff"
Some parsers can produce output in other charset than given in LocalCharset command. Specify charset to make indexer convert parser's output to proper one. For example, if your catdoc is configured to produce output in windows-1251 charset but LocalCharset is koi8-r, use this command for parsing MS Word documents:
Mime application/msword "text/plain; charset=windows-1251" "catdoc -a $1"
When executing a parser indexer creates UDM_URL environment variable with an URL being processed as a value. You can use this variable in parser scripts.
RPM parser by Mario Lang <lang@zid.tu-graz.ac.at>
/usr/local/bin/rpminfo:
#!/bin/bash /usr/bin/rpm -q --queryformat="<html><head><title>RPM: %{NAME} %{VERSION}-%{RELEASE} (%{GROUP})</title><meta name=\"description\" content=\"%{SUMMARY}\"></head><body> %{DESCRIPTION}\n</body></html>" -p $1
indexer.conf:
Mime application/x-rpm text/html "/usr/local/bin/rpminfo $1"
It renders to such nice RPM information:
3. RPM: mysql 3.20.32a-3 (Applications/Databases) [4] Mysql is a SQL (Structured Query Language) database server. Mysql was written by Michael (Monty) Widenius. See the CREDITS file in the distribution for more credits for mysql and related things.... (application/x-rpm) 2088855 bytes
catdoc MS Word to text converter
Home page, also listed on Freshmeat
indexer.conf: Mime application/msword text/plain "catdoc $1"
xls2csv MS Excel to text converter
It is supplied with catdoc.
indexer.conf: Mime application/vnd.ms-excel text/plain "xls2csv $1"
pdftotext Adobe PDF converter
Supplied with xpdf project.
Homepage, also listed on Freshmeat
indexer.conf: Mime application/pdf text/plain "pdftotext $1 -"
unrtf RTF to html converter
indexer.conf: Mime text/rtf* text/html "/usr/local/mnogosearch/sbin/unrtf --html $1 Mime application/rtf text/html "/usr/local/mnogosearch/sbin/unrtf --html $1
Please feel free to contribute your scripts and parsers configuration to <general@mnogosearch.org>.