![]() |
| Frontier Tutorials / Indexing a Website / Build The Keyword Index |
Now that we've added keywords to our pages, we need to build the keyword index of the pages. To do that, we'll use Indexer.BuildPageIndex.
Indexer.BuildPageIndex constructs a keyword index of all pages in a specified website table or subtable.
Only entries in the source table (and its subtables) that the website framework will render into HTML pages will be indexed. All other entries are ignored, and will not appear in the index/indices.
Any page entry that contains the keywords directive (in our case, #topics) will be included in the index. Any table that does not contain the keywords directive is ignored (i.e., will not appear in the generated index).
BuildPageIndex( inSourceAdr, inDestTbl, inReplaceIndices=true, inKeywordDirective="metakeywords", inSortBy=nil, doExpandNestedKeywords=false )
- inSourceAdr
- The location from which pages should be indexed. To index your entire site, this would be the address of the website table (e.g., @websites.mysite). To index only a portion of a site, pass the address of the subsite table. To index just a single page (as from the #filters.finalFilter script), pass the address of the individual page.
- inDestTbl
- The address of the table in which the index information should be stored (e.g., @websites.mysite.["#indices"].["topic"]).
- inKeywordDirective
- Specifies the name of the directive from which to extract keywords. For our tutorial, this is "topics".
- inSortBy
- Specifies the name of the directive that the index information tables should sort by. If not specified, the index sorts by the addresses of the indexed pages. For websites, the title often works well, so for our tutorial, we will pass "title" for inSortBy.
- doExpandNestedKeywords
- Specifies whether nested keywords should also be entered individually. If true, expanded keywords will be entered in the index as specified, and will also be split into individual keywords, and those keywords will be entered in the index.
For example, if doExpandNestedKeywords is true, "frontier:community" is equivalent to "frontier:community, frontier, community".
The key function call we need to make is
| Indexer.BuildPageIndex( @websites.mysite, @websites.mysite.["#indices"].["topic"], true, "topics", "title" ) |
|
|---|
(Replace "websites.mysite" with your own site table, of course.)
Create a new, empty subtable in your website named "#indices".
Don't worry that we haven't created the ["#indices"].topic subtable yet; BuildTableIndex will create it automatically.
Type this command into the Quick Script window and execute it, then examine the ["#indices"].topic subtable. It should contain a subtable for each keyword you used.
But it's a pain to have to type in something like this whenever you want to rebuild the index, so we'll put it in a script, and call it BuildTopicsIndex:
|
on BuildTopicsIndex( sourceAdr=@websites.mysite, destTbl=@websites.mysite.["#indices"].["topic"], inReplaceIndices=true )
|
This seems almost trivial. However, it does several things for us:
Now you can type this simpler command into the Quick Script window to rebuild the index:
| websites.mysite.["#tools"].BuildTopicsIndex() |
Of course, it would still be a pain to have to type even this shorter command into the Quick Script window every time you wanted to rebuild your indices. Instead, let's make it a menu command.
In your website table, create a new menuBar object named "#menu". Set the menu name (the first line of the menu outline) to the name of your site, or to some shortened version of it.
If you have installed the TableMenu agent (as instructed earlier), this new website menu will immediately appear on the menubar. If not, install it now. Click on a different window to inactivate your website window; notice that your website menu disappears from the menubar. Click back in your website window, and you'll get the website menu back.
Set the name of the first menu command in your website menu to "Rebuild Indices". Double-click on the arrow beside the menu command name to open the menu item script window, and copy the above BuildTopicsIndex command from the Quick Script window and paste it into the menu item script. Then close the menu item script window.
Now delete the ["#indices"].topic subtable entirely. Select the Rebuild Indices command from your website menu. It should recreate and repopulate the ["#indices"].topic subtable.
Of course, you don't have to actually delete the ["#indices"].topic subtable in order to rebuild it. Because we let inReplaceIndices default to true, ["#indices"].topic will be cleared by indexer.BuildPageIndex, then rebuilt.
Now you can completely rebuild your keyword index at any time, by a simple menu command!