Query by a field

Define searchable fields

You can define which fields should be saved to the index by marking them in the related content type at the chosen field's definition.

It is also possible to switch off indexing for certain content types. In that case nobody will be able to find the instances made with those content types using queries, and the index will be smaller.

About the possible indexing configurations and field definition see the schema and the content type concepts.

Basically query by a field works by adding the chosen field name to the query with a value that you are looking for:

query=[FieldName]:[value]

Field names are always case sensitive but values are not. The following queries return the same result:

query=Name:saturn   query=Name:SaTUrn

In the following examples you will see how you can query by the most common fields.

Query by a text field

The following query returns the content that's Name is BusinessPlan.docx

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT?query=Name%3ABusinessPlan.docx

// the special characters should be url encoded
// the actual query here is ?query=Name:BusinessPlan.docx

Following query returns the content that's Description field contains the word 'company' (notice that it is actually a wildcard search)

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT?query=Description%3A*company*

// the special characters should be url encoded
// the actual query here is ?query=Description:*company*

Query by a number field

Following example shows how to get the list of tasks that's completion rate is lower than 50% (their Completion field's value is less than 50):

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT?query=TaskCompletion%3A%3C50

// the special characters should be url encoded
// the actual query here is ?query=TaskCompletion:<50

Query by a boolean field

You can also query by a boolean field as it is shown in the following example. The query returns the list of critical workspaces (e.g. content that's IsCritical field's value is true).

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=IsCritical%3Atrue

// the special characters should be url encoded
// the actual query here is ?query=IsCritical:true

Query by choice field (localized value)

It is also possible to query by a choice field. Since choice options could have a value and the (localized) title you have to format your query according to which one you want to search for. See the following choice field's options

<Field name="MemoType" type="Choice">
<DisplayName>Memo</DisplayName>
<Configuration>
<Options>
<Option value="generic" selected="true">Generic</Option>
<Option value="iso">ISO</Option>
<Option value="iaudit">Internal audit</Option>
</Options>
</Configuration>
</Field>

In the following example you can see that if you simply use a verb as a possible value of a choice field it will search for it as a choice option's text, in this case for 'British shorthair' cats.

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT?query=MemoType%3A%22Internal+audit%22

// the special characters should be url encoded
// the actual query here is ?query=MemoType:"Internal audit"

Query by choice field (value)

If you use localized titles for the choice options you may need to query by value that is common even if the title could be used and displayed in various languages. In this case you have to use the '$' sign with the value.

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT?query=MemoType%3A$iaudit

// the special characters should be url encoded
// the actual query here is ?query=MemoType:$iaudit