Saturday, May 16, 2009

Advanced Search - An in-depth look

I'd like to take a behind-the-scenes look at the new Advanced Search options, both to explain how to best use the tools, and to explain just how such a complicated search filter works.


First of all, the Advanced Search query is generated 100% on the fly. Previously, only three predefined search queries were used. This was simple and effective, because the search filter was almost always the same. Just the key words sent through the search filter changed.
For example, the filter by name would look like this:
WHERE CardName LIKE [something]

Changing the text sent in the [something] placeholder yielded different results. The catch was, not every field is necessary for every search. Suppose you didn't care what the card's name was. The program still had to send the search filter something. In this example the [something] would be a dummy value, just to trick the database into including everything.

Combine this process with up to 50 values, and now problems arise. The database is often making far more comparisons than necessary, slowing performance.



The new search options bypass this problem by generating the search filter when it is needed. If text is entered in the CardName filter, the database filters based on the text entered. More importantly, if no text is entered, that step is skipped!



So, with that explination out of the way, here is the first in a series of screenshots. The first step is to determine what set(s) of cards to display.
Filtering by format will show all printings (records) of all cards legal in that format. These format lists are another series of tables in the database.
Filtering by Set, on the other hand, will only show cards from the sets enabled through the checkboxes. The sets are grouped the same way the 'volumes' are grouped, which should make everything easy to understand.

Also worth noting is the interactive title text for each group of sets, which can be clicked to toggle every set in that group on or off, and the clear button int the top right of many filter groups. This can be clicked to reset that filter (or to toggle everything on or off in the case of check box collections).



The second tab brings back many familiar controls, but now features some extra options.

Skipping the Color options for now, the only changes to the Card Type filters are the addition of a "Planeswalker" checkbox. This rarely-used option is bundled with "Enchantments" and "Creatures" for the simple search, to preserve the layout. Similarly, the "Token" and "Land" as well as the "Product" and "Special" rarities have also been split.

The CMC options now allow for up to three ranges of numbers, which is probably quite excessive.

Back to the Color options.
Each row of checkboxes represents one group of filter options. Clicking the "Multicolor" and/or "Hybrid" tabs will set that row's filter to only hybrid or multicolor style cards, rather than monocolor cards. Clicking "Match All" means that only multicolor/hybrid cards that match all the selected colors will be included.

Additionally, the filtering process will be skipped for rows with each box checked, or no boxes checked. The same is true for the Type and Rarity checkboxes.


Here are some examples:
White, Blue = Only white and blue monocolor cards.
White, Blue, Multicolor = Multicolor cards that are blue or white, and are not colors that are not checked.
White, Blue, Green, Multicolor = Multicolor cards that are blue or white or green, and are not colors that are not checked.
Black, Red, Green, Multicolor, Match All = Multicolor cards that are exactly Black, Red, and Green




The third tab allows for text-based filtering.

The Subtype, Rules Text, and Flavor Text fields each allow a pair of AND fields, and a single NOT field.
When completed, the filter will exclude anything from the NOT field, and include anything that matches either of the two three-condition OR clauses.

The Artist field simply filters by artist name.

The Card Name box is actually intended to copy/past long lists of card names, such as from a decklist psted online. Unlike the other fields, this list requires an exact match.


Perhaps least impressive is the fourth tab, which filters results by the inventory records in the currently-opened save file. Unilke all the other options listed here, this filter is performed after the search, because these records are not part of the master database.

The filters are paired up, allowing up to two ranges of inventory.
The first dropdown determines what versions to check. Total, the default, finds the sum of all versions each printing of each card.
The other options for this list are "All," which checks all versions for a match among any of them, "Regular" which is the normal printing, "Foil" which is the foil (shiny/premium) printing, and two "other" entries, for oddball cases such as foreign versions, or signed copies.


Last but not least, the sort order tab allows a wide variety of sorting conditions, including several compound conditions. This step formats the data as effectively as possible for further processing (control break processing) later on, when the resulting list is broken up into managable pieces.

No comments: