Skip to navigation
List and example of the lucene queries
23.06.16
https://dotcms.com/docs/latest/content-search-syntax perators The following are some of the most common operators used in Lucene query strings; you can use these operators to build most Lucene queries. If you need to create more complex queries, consider using the full Elasticsearch syntax. For more information on Lucene query syntax, please see the official Lucene documentation. Name Operator Required + Prohibit - Boolean AND && or AND Boolean OR || or OR Boolean NOT ! or NOT Search All Fields _all Date Range [... TO ...] Single Character Wildcard ? Multiple Character Wildcard * Field Grouping (, ) Fuzzy Search ~ Boost Terms ^ Escape Character \ Required (+) The required operator (+) only returns items which have the term after the “+” in the specified content field. If the required operator is not included, then results may be returned which do not include the term, as long as they meet the other requirements of the query string (such as matching other specified fields or search terms); by using the required operator, you can ensure that search results will exclude any results which do not include specific search terms. For example, the following query will only return blog articles whose body includes the term “investment”. The search results may also have the term “JetBlue”. This means that search results which include both “investment” and “JetBlue” will receive higher scores (and thus may be sorted near the top of the results); but items which include “investment” but do not include “JetBlue” will still be returned, while items which include “JetBlue” but do not include “investment” will not be returned. +contentType:Blog +Blog.body:(+"investment" "JetBlue") Prohibit (-) The Prohibit (-) operator excludes documents that contain the term after the - symbol. For example, the following query returns all the employees whos first name begins with the letter “R”, but whose last name does NOT begin with the letter “A”: +contentType:Employee +(Employee.firstName:R*) -(Employee.lastName:A*) Note: For a description of the asterisk character (*), please see Multiple Character Wildcard, below. Boolean Operators [AND (&&), OR (||), and NOT (!)] You may specify the boolean operators AND, OR, and NOT either as keywords (AND, OR, and NOT) or as special character terms (&&, ||, and !). When using the AND, OR, and NOT keywords, make sure to use all caps. AND (&&) The AND operator (&& or AND) matches content where both terms exist in the content field(s) being queried. For example, the following query returns only the blogs where the word “business” and “Apple” BOTH appear in the blog body field: +contentType:Blog +Blog.body:("business" && "Apple") Note: The order the fields appear in the results do not matter for the AND operator. The example would return both results where the word “business” appears before the word “Apple” and results where the word “business” appears after the word “Apple”. OR (||) The OR operator (|| or OR) links two terms and finds a matching document if either of the terms exist in the content field(s) being queried. The OR operator is the equivalent of a union between sets. For example, the following query returns all items which include either the word “analysts” or the word “investment” in the body: +contentType:Blog +Blog.body:("analysts" || "investment") NOT (!) The NOT (!) operator excludes documents that contain the term after the ! symbol. For example, the following query returns all blog artices with the word “investment” in the body, but do NOT have the term “JetBlue” in the body: +contentType:Blog +Blog.body:("investment" !"JetBlue") Search All Fields To search all fields in the content (rather than a specific field), use _all in the same way you would specify an individual field name. For example, the following query returns all items which have the word “fund” in any searchable field in the content: +contentType:Products +_all:*fund* For more information on using the _all search term, please see the Search within All Content Fields documentation. Date Range Use square brackets around a beginning and end date with the word “TO” between them to search for content dates that fall within the range. For example, the following query returns all News items with publish dates between January 1, 2011 and January 1, 2015: +contentType:News +News.sysPublishDate:[01/01/2011 TO 01/01/2015] Note: Searching date ranges via the Content API requires slightly different date formatting. Wildcards You may include wildcard characters to allow your query to return results which match some common portion of the search term, but which vary in other portions of the field. Single Character Wildcard (?) The question mark character (?) will match any single character, so any result which includes any character in the respective position of the question mark will be returned as long as the rest of the query string matches. For example, the following query returns all Employees whose first name includes “Mari”, followed by any character. Search results will include employees with the first name “Maria” or “Marie” (or any other 5 letter first name which begins with “Mari”). +contentType:Employee +Employee.firstName:Mari?
https://dotcms.com/docs/latest/content-search-syntax
Reply
Anonymous
Information Epoch 1740079041
Save trees.
Home
Notebook
Contact us