Excluding Types from a Search
You can omit certain types from a FlexibleSearch query run.
If you want to make sure that certain types are omitted from a FlexibleSearch query run, there are two approaches at your disposal:
-
Using the itemtype operator and a parameter.
This approach is feasible if you can prepare and pass a Map with references to the types you want to exclude as a FlexibleSearch parameters, such as:
final Set<ComposedTypeModel> excludedTypes = new HashSet<ComposedTypeModel>(); excludedTypes.add(getComposedType("mySuborderType")); StringBuilder queryString = new StringBuilder("SELECT {").append(OrderModel.PK).append("} "); queryString.append("FROM {").append(OrderModel._TYPECODE).append("} "); queryString.append("WHERE {").append(OrderModel.ITEMTYPE).append("} NOT IN (?excluded)"); final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString.toString(), Collections.singletonMap("excluded", excludedTypes));
-
Using a JOIN clause
This approach is feasible if you cannot pass parameters, for example, because you need to enter a FlexibleSearch statement directly:
SELECT {o.PK} FROM {Order AS o JOIN ComposedType AS t ON {o.itemtype}={t.PK} } WHERE {t.code} NOT IN ( 'Foo', 'Bar' )