Help:Search operators

Semantic MediaWiki provides different search operators to enable a user to refine search conditions and criteria.

Wildcards
Wildcards are written as " " and allow any value for a given condition. For example,  returns all pages that have any value for the property "Born in". Please note that " " can only be used by itself. See the section Like, not like for the wildcards " " and " ".

Comparators
Comparators are special symbols like  or. They are placed after  in property conditions.
 *   and  : "greater than" and "less than"
 *   and  : "greater than or equal" and "less than or equal" by default, but "greater than" and "less than" if is set to.
 *   and  : "greater than or equal" and "less than or equal"
 *  : "not" ("unequal")
 *  : «like» comparison for strings
 *  : «not like» comparison for strings

For example, Area code::>>415

Comparators work only for property values and not for conditions on categories. A wiki installation can limit which comparators are available, which is done by the administrator by modifying the setting to as explained.

Depending on the value set to, interpretation of  and   can differ; the different behaviours are documented on the page about strict comparators.

When applying comparators to pages, then the title of the page (without namespace prefix) is used. However, this can be changed by setting another MediaWiki sortkey for that page, e.g. . Please mark that this applies to all comparators, including ! and ~. It is not possible to have multiple sortkeys for one page. In particular, redirect pages are not taken into account when applying comparators.

Not equal
You can select pages that have a property value which is unequal to a given value. For example, Area code::!415 will select pages that have an area code which is not "415". Note that this query description does not look for pages which do not have an area code 415. Rather, it looks for all pages that (also) have a code unequal to 415. In particular, pages that have no area code at all cannot be the result of the above query.

As with the (default) equality comparator, the use of custom units may require rounding in numeric conversions that can lead to unexpected results. For example,  may still select someone whose height displays as «6.00 feet» simply because the exact numeric value is not really 6. In such situations, it might be more useful to query for pages that have a property value outside a certain range, expressed by taking a disjunction (see below) of conditions with.

Like, not like
The comparators  and   work only for properties of  and  (SMW ≤ 1.7.x) or  and  (SMW ≥ 1.8.x) and since  also for CiteRef::gh:smw:1129, CiteRef::gh:smw:1129 and CiteRef::gh:smw:1178. In a like condition, one uses " " wildcards to match any sequence of characters and " " to match any single character. For example, one could ask  to select addresses containing the string "Park Place", or   to select both "Mr." and "Ms.".

Note that in case of (SMW ≤ 1.7.x) all 255 storable characters are searchable, in case of  (SMW ≥ 1.8.x) only the first 40 characters (if more than 72 characters were stored as property value) or all 72 characters (if a maximum of 72 characters were stored as property value) are searchable as explained. . For all 255 characters are searchable (all SMW versions).

Also note that some special characters need masking when used in combination with comparator " ".

Property "Path" of holds something like "n:\path\morepath" as data value. To query for all pages that contain "n:\path\..." in property "Path" you need to mask the backslashes " " to your query like this:
 * Example

and later supports another notation:  and , which relies on the standard LIKE / NOT LIKE SQL syntax for a pattern match.CiteRef::gh:smw:2558

Greater than or equal, less than or equal
With numeric values, you often want to select pages with property values within a certain range. For example

height::>6 ft height::<7 ft

asks for all actors that are between 6 feet and and 7 feet tall. Note that this takes advantage of the automatic unit conversion: even if the height of the actor was set with  it would be recognized as a correct answer (provided that the datatype for height understands both units, see Help:Custom units). Note that the comparator means greater/less than or equal – the equality symbol " " is not needed.

It is also possible to describe this with  conditions:CiteRef::gh:smw:1043:106536707

|<7 ft

Such range conditions on property values are mostly relevant if values can be ordered in a natural way. For example, it makes sense to ask  but it is not really helpful to say.

If a datatype has no natural linear ordering, Semantic MediaWiki will just apply the alphabetical order to the normalised datavalues as they are used in the RDF export. You can thus use greater than and less than to select alphabetic ranges of a property of. For example, you could ask  to select surnames between "Do" and up to "G". For wiki pages, the comparator refers to the name of the given page (without the namespace prefix).

Here and in all other uses of comparators, it might happen that a searched for value really starts with a symbol like. In this case, SMW can be prevented from interpreting the symbol as a comparator if a space is inserted after. For example,  really searches for pages with the value "&lt;br>" for the given property.

Greater than, less than
At times you might want to exclude the precise value from the result itself, e.g. to find an actor taller than Hugh Laurie (1.89m), you can query using a combination of the " " comparator and the " " comparator:

height::>1.89m height::!1.89m

Strict comparators
The default behaviour of SMW, where comparators  and   mean "less than or equal" and "greater than or equal", can be somewhat confusing for people that are familiar with the mathematical meaning of. Thus you can choose to have SMW interpret "strict", as explained here.

Values containing operator symbols
Cases may occur where the value of a given property starts with one of the following symbols: <, ≤, >, ≥, =, ! and ~. To assure that Semantic MediaWiki can handle those cases, value notations are white-space sensitive. To avoid confusion a space is inserted after. For example,  really searches for pages with the value "   " for the given property.

Case insensitivity
Starting with CiteRef::gh:smw:1912CiteRef::gh:smw:2499 it is possible to enable case insensitive matching for properties of e.g., , and  (blob types, i.e. strings or text) using the   option to.

The following four examples will provide an overview of the general differences between having this feature enabled or not:

Property "Has text" of datatype "Text" holds "CAseInSensitiveSearch" as data value on page "Example". If enabled queries No. 1 to 3 and if not (default) queries No. 1 to 3 will also select page "Example":
 * Example 1

Property "Has page" of datatype "Page" holds "CAseInSensitiveSearch" as data value on page "Example". If enabled queries No. 1 and 2 and if not (default) query No. 3 will select page "Example":
 * Example 2

Property "Has text" of datatype "Text" holds "CAseIn" as data value on page "Example". If enabled queries No. 1 to 3 and if not (default) query No. 3 will select page "Example":
 * Example 3

Property "Has page" of datatype "Page" holds "CAseIn" as data value on page "Example". If enabled query No. 3 and if not (default) query No. 3 will select page "Example":
 * Example 4