Command Spotlight – Text Index

If you have ever tried searching for maps in the Community Atlas, you might have noticed that there is an option for searching for text in the map. This option searches for text in the visible labels on the map itself, but also for text in the attached map notes. Since map notes are included in the search, it means that you can search for something like “Symbol Set 6” and get a list of all maps in the atlas that uses resources from SS6 (If you have looked at atlas maps, you may have noticed they all have a map note listing which products are required, which is why you can then search for this).

So, the interesting question here is how is this possible in the first place? FCW files are binary files after all, and not easily parsed by web server software, and the search would also be slow if it had to look through 1300+ files every time someone tried to search.

The solution here lies in a feature in CC3+ that can create a search index for a whole folder of maps. This feature was originally intended to use with the built in search feature in Campaign Cartographer, but as I’ve already reveled here, it can also be utilized by other tools, in this case my web server software to allow map searches despite the fact that the maps on the web server are just plain non-searchable images.

Making a Search Index

Creating a search index in CC3+ is quite simple, but it does require you to use the CC3+ command line, as it is not exposed through the menus. But the command is quite straight forward. First, open up one of the maps in the folder you wish to index. Note that the index will include sub-directories, so if you have a complete directory structure, open up a map at the top of the hierarchy.

Now, with the map open, simply type INDEX $\*.fcw on the command line and hit enter. This will create a file called index.idx in the same folder as your open map. If you have lots of maps in the folder (and subfolders) the indexing can take a little bit of time. For the atlas, with it’s 1300+ maps, this takes a couple of minutes. You’ll notice that the process is running, because the status bar at the top should turn red, and it will be displaying the map names as it process them. The process might appear hung at times, but just have some patience, it will finish. Also note, you cannot work in CC3+ while this commands is running, so just let it finish before doing anything else. There is no confirmation message when it is done, but you should see the status bar returning to it’s regular white color.

Searching Using the Index

I’ve talked about using the search in CC3+ earlier, but in that article, I just had the search look through all the maps for every search, something that can be slow if you have lots of maps. However, in the search dialog (Tools -> Search Files for Text…), instead of putting in the path to the fcw files in the folder, we can put in the path to the index file we created above instead. CC3+ will then use the index file for the search operation, instead of searching through each map. This is much faster.

To give a concrete example with screenshots. I have my working copy of the Community Atlas stored in M:\Community Atlas Project\Atlas. So, if I want to search without an index file, I can simply put in M:\Community Atlas Project\Atlas\*.fcw in the path, and the search will look at all fcw files in that location, including subdirectories if that option is checked. For the atlas, this search will actually take a couple of minutes, simply because it needs to look through all those files.

However, since I have an index file (index.idx) already created for that folder, if I instead input my path as M:\Community Atlas Project\Atlas\index.idx then CC3+ can instead use the index file instead of having to look through all those files, and you’ll find that the search goes MUCH faster (less than a second for the community atlas collection), because we have already pre-processed all those maps and put the results into the index file. For atlas users, this file is already there in the download, but for your own worlds, you will have to make it yourself as described above. (Note of course that the index file only contains the maps that were present when the file was made, if you add new maps to the folder, or update existing maps, the index needs to be re-created)

Using the Index File in Other Apps

So, what I am doing to make the search feature in the atlas works is simply to put this index file on my webserver, and wrote a small function in the web application that runs the atlas that can read and parse this file. You see, the index file is really just a plain text file, you can open it up in any text editor (like notepad) and read it, or even edit it.If you wish to have a look at the index file from the atlas, just download the atlas zip file, you’ll find the index.idx file in the root of the zip file.

I’ll not do a deep dive of the technical format here, but if you open it, you’ll notice the first line is “$Alarius\Aak Hills.FCW”. A line starting with a dollar sign means that the following (until the next line starting with a dollar sign) lines are all text from that map, this is how it knows what map file matches. then each text entry from that map is preceded with a line with an asterisk (*N, *T, etc). This says something about the type of text (Map Note, Text entity in map, etc). And that is more or less all there is to it.

Of course, when I say using the index file in other apps, I am mostly referring to writing your own tools/scripts like i did for the atlas. While you can read/edit it in notepad, no other software will really understand this file except as lines of plain text with no particular meaning. But as I have shown with the community atlas example here, this allows you to make your maps accessible in ways not possible with most other mapping solutions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.