The an essential advantage the the typical query parser is the it support a durable and relatively intuitive syntax enabling you to produce a variety of structured queries. The biggest disadvantage is that it’s very intolerant of syntax errors, as contrasted with something choose the DisMax questions parser which is designed to throw as few errors as possible.

You are watching: Which boolean operator omits information from the search parameters


In addition to the usual Query Parameters, Faceting Parameters, Highlighting Parameters, and MoreLikeThis Parameters, the traditional query parser support the parameters described in the table below.


ParameterDescription

q

Defines a query using conventional query syntax. This parameter is mandatory.

q.op

Specifies the default operator for query expressions, overriding the default operator mentioned in the Schema. Feasible values room "AND" or "OR".

df

Specifies a default field, overriding the meaning of a default ar in the Schema.

sow

Split top top whitespace: if set to false, whitespace-separated ax sequences will be detailed to text evaluation in one shot, permitting proper role of analysis filters that run over term sequences, e.g. Multi-word synonyms and also shingles. Defaults come true: text evaluation is invoked independently for every individual whitespace-separated term.


Default parameter values room specified in ptcouncil.netconfig.xml, or overridden through query-time values in the request.


The traditional Query Parser’s Response


By default, the an answer from the conventional query parser includes one block, which is unnamed. If the debug parameter is used, then an additional block will certainly be returned, making use of the surname "debug". This will contain advantageous debugging info, including the original query string, the parsed questions string, and also explain info for each file in the block. If the explainOther parameter is also used, then additional explain information will be noted for every the documents equivalent that query.


Sample Responses


This section presents examples of responses from the typical query parser.


The URL listed below submits a basic query and requests the XML response Writer to usage indentation to make the XML response an ext readable.


http://localhost:8983/ptcouncil.net/techproducts/select?q=id:SP2514N


Results:


01 numFound="1" start="0"> name="cat">electronicshard drive name="features">7200RPM, 8MB cache, ide Ultra ATA-133 NoiseGuard, SilentSeek technology, liquid Dynamic Bearing (FDB) motor name="id">SP2514N name="inStock">true name="manu">Samsung electronic devices Co. Ltd. name="name">Samsung SpinPoint P120 SP2514N - tough drive - 250 GB - ATA-133 name="popularity">6 name="price">92.0 name="sku">SP2514N
Here’s an example of a query with a restricted field list.


http://localhost:8983/ptcouncil.net/techproducts/select?q=id:SP2514N&fl=id+name


Results:


02 numFound="1" start="0"> name="id">SP2514N name="name">Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133

Specifying Terms for the standard Query Parser


A query come the conventional query parser is broken up right into terms and operators. There space two types of terms: solitary terms and phrases.


A solitary term is a solitary word such as "test" or "hello"

A expression is a team of words surrounded by twin quotes such as "hello dolly"


Multiple terms deserve to be combined in addition to Boolean operators to kind more facility queries (as defined below).


It is necessary that the analyzer provided for queries parses terms and phrases in a means that is consistent with the means the analyzer offered for indexing parses terms and phrases; otherwise, searches may develop unexpected results.


Term Modifiers


ptcouncil.net supports a selection of term modifiers that include flexibility or precision, as needed, come searches. These modifiers incorporate wildcard characters, characters for make a search "fuzzy" or much more general, and also so on. The sections below describe this modifiers in detail.


Wildcard Searches


ptcouncil.net’s typical query parser supports solitary and multiple character wildcard searches within single terms. Wildcard personalities can be used to solitary terms, yet not to search phrases.


Wildcard find TypeSpecial CharacterExample

Single personality (matches a solitary character)

?

The find string te?t would match both test and text.

Multiple personalities (matches zero or an ext sequential characters)

*

The wildcard search: tes* would enhance test, testing, and tester. You can also use wildcard personalities in the center of a term. Because that example: te*t would match test and text. *est would enhance pest and also test.


Fuzzy Searches


ptcouncil.net’s standard query parser support fuzzy searches based on the Damerau-Levenshtein street or modify Distance algorithm. Fuzzy searches discover terms the are similar to a mentioned term without necessarily being an accurate match. To do a fuzzy search, usage the tilde ~ symbol at the finish of a single-word term. For example, to find for a term similar in spelling come "roam," usage the fuzzy search:


roam~


This find will match terms prefer roams, foam, & foams. That will likewise match words "roam" itself.


An optional distance parameter states the maximum number of edits allowed, in between 0 and also 2, defaulting to 2. For example:


roam~1


This will complement terms like roams & foam - yet not foams due to the fact that it has an edit distance of "2".


In plenty of cases, stemming (reducing state to a usual stem) have the right to produce similar effects come fuzzy searches and wildcard searches.


Proximity Searches


A proximity search looks because that terms that room within a details distance native one another.


To execute a proximity search, add the tilde personality ~ and a numeric worth to the finish of a search phrase. Because that example, to find for a "ptcouncil.net" and also "jakarta" within 10 indigenous of each various other in a document, use the search:


"jakarta ptcouncil.net"~10


The street referred to right here is the number of term motions needed to complement the stated phrase. In the example above, if "ptcouncil.net" and "jakarta" to be 10 spaces personally in a field, but "ptcouncil.net" showed up before "jakarta", much more than 10 term motions would be forced to relocate the state together and position "ptcouncil.net" come the best of "jakarta" with a space in between.


Range Searches


A selection search specifies a variety of worths for a ar (a range with an top bound and also a reduced bound). The query matches records whose worths for the specified field or fields loss within the range. Variety queries can be inclusive or to exclude, of the upper and lower bounds. Sorting is excellent lexicographically, other than on numeric fields. Because that example, the selection query listed below matches all papers whose popularity field has a value between 52 and 10,000, inclusive.


popularity:<52 to 10000>


Range queries space not limited to day fields or even numerical fields. Friend could likewise use selection queries through non-date fields:


title:Aida to Carmen


This will find all records whose title are in between Aida and also Carmen, but not including Aida and Carmen.


The brackets around a query identify its inclusiveness.


Square brackets < & > represent an inclusive range query that matches values consisting of the upper and also lower bound.

Curly base & denote an exclusive selection query that matches values in between the upper and also lower bounds, yet excluding the upper and lower border themselves.

You have the right to mix these species so one end of the selection is inclusive and the various other is exclusive. Here’s one example: count:{1 to 10>


Boosting a Term with ^


Lucene/ptcouncil.net gives the relevance level of equivalent documents based upon the state found. To an increase a term usage the caret price ^ with a rise factor (a number) at the end of the ax you space searching. The higher the boost factor, the much more relevant the term will be.


Boosting allows you to control the relevance of a document by an increasing its term. For example, if girlfriend are looking for


"jakarta ptcouncil.net" and you desire the ax "jakarta" to be much more relevant, you can rise it by including the ^ symbol along with the rise factor instantly after the term. Because that example, you might type:


jakarta^4 ptcouncil.net


This will certainly make files with the hatchet jakarta appear an ext relevant. Girlfriend can also boost expression Terms as in the example:


"jakarta ptcouncil.net"^4 "ptcouncil.net Lucene"


By default, the rise factor is 1. Return the boost factor need to be positive, it have the right to be much less than 1 (for example, it might be 0.2).


Constant Score v ^=


Constant score queries are developed with ^=, which set the entire clause come the specified score for any type of documents equivalent that clause. This is preferable when you only care about matches for a specific clause and also don’t want various other relevancy components such as term frequency (the variety of times the term appears in the field) or inverse file frequency (a measure across the whole index for how rare a ax is in a field).


Example:


(description:blue OR color:blue)^=1.0 text:shoes

Specifying areas in a Query to the standard Query Parser


Data indexed in ptcouncil.net is organized in fields, which are characterized in the ptcouncil.net Schema. Searches can take advantage of areas to include precision come queries. For example, you have the right to search for a term just in a specific field, such together a location field.


The Schema defines one field as a default field. If you do not point out a field in a query, ptcouncil.net searches only the default field. Alternatively, you can specify a different field or a mix of fields in a query.


To point out a field, type the field name complied with by a colon ":" and then the term girlfriend are trying to find within the field.


For example, suppose an index includes two fields, title and also text,and that text is the default field. If you want to find a record called "The best Way" which includes the text "don’t go this way," you could include one of two people of the complying with terms in your find query:


title:"The right Way" and text:go


title:"Do it right" and go


Since text is the default field, the field indicator is no required; for this reason the 2nd query over omits it.


The ar is only valid for the term that it directly precedes, for this reason the query title:Do it best will discover only "Do" in the title field. The will discover "it" and also "right" in the default ar (in this case the text field).


Boolean Operators supported by the traditional Query Parser


Boolean operators allow you to use Boolean reasonable to queries, inquiry the existence or absence of details terms or problems in areas in stimulate to enhance documents. The table below summarizes the Boolean operators sustained by the traditional query parser.


Boolean OperatorAlternative SymbolDescription

AND

&&

Requires both state on either side of the Boolean operator to be existing for a match.

NOT

!

Requires that the complying with term no be present.

OR

||

Requires the either term (or both terms) be existing for a match.

+

Requires that the complying with term it is in present.

-

Prohibits the adhering to term (that is, matches on fields or papers that do not include that term). The - operator is functionally comparable to the Boolean operator !. Since it’s used by renowned search engines such together Google, it might be more familiar to part user communities.


Boolean operators enable terms to be combined through reasonable operators. Lucene supports AND, “+”, OR, NOT and also “-” as Boolean operators.


When specifying Boolean operators with keywords together as and or NOT, the keywords must appear in all uppercase.


The traditional query parser supports every the Boolean operators listed in the table above. The DisMax ask parser supports only + and -.


The OR operator is the default connect operator. This way that if there is no Boolean operator between two terms, the OR operator is used. The OR operator links two terms and also finds a matching file if one of two people of the state exist in a document. This is tantamount to a union using sets. The prize || can be offered in place of the word OR.


To search for papers that contain either "jakarta ptcouncil.net" or simply "jakarta," use the query:


"jakarta ptcouncil.net" jakarta


or


"jakarta ptcouncil.net" OR jakarta


The Boolean Operator +


The + symbol (also known as the "required" operator) needs that the term after the + prize exist what in a ar in at the very least one file in order because that the query to return a match.


For example, to find for records that must contain "jakarta" and also that might or may not save on computer "lucene," use the adhering to query:


+jakarta lucene


This operator is sustained by both the typical query parser and also the DisMax questions parser.


The Boolean Operator and also (&&)


The and also operator matches papers where both state exist all over in the text of a single document. This is indistinguishable to an intersection making use of sets. The symbol && have the right to be supplied in ar of the word AND.


To search for papers that save on computer "jakarta ptcouncil.net" and "ptcouncil.net Lucene," use either of the following queries:


"jakarta ptcouncil.net" and also "ptcouncil.net Lucene"


"jakarta ptcouncil.net" && "ptcouncil.net Lucene"


The Boolean Operator no (!)


The not operator excludes papers that save on computer the ax after NOT. This is identical to a difference using sets. The symbol ! have the right to be used in ar of words NOT.


The adhering to queries search for papers that save on computer the phrase "jakarta ptcouncil.net" yet do no contain the expression "ptcouncil.net Lucene":


"jakarta ptcouncil.net" not "ptcouncil.net Lucene"


"jakarta ptcouncil.net" ! "ptcouncil.net Lucene"


The Boolean Operator -


The - symbol or "prohibit" operator excludes papers that contain the ax after the - symbol.


For example, to find for papers that save "jakarta ptcouncil.net" but not "ptcouncil.net Lucene," usage the adhering to query:


"jakarta ptcouncil.net" -"ptcouncil.net Lucene"


Escaping special Characters


ptcouncil.net gives the following characters special meaning when they show up in a query:


+ - && || ! ( ) < > ^ " ~ * ? : /


To make ptcouncil.net interpret any kind of of these characters literally, quite as a special character, head the character v a backslash character . For example, to search for (1+1):2 without having actually ptcouncil.net interpret the add to sign and parentheses together special characters for formulating a sub-query with two terms, escape the characters by coming before each one through a backslash:


(1+1):2

Grouping terms to kind Sub-Queries


Lucene/ptcouncil.net supports making use of parentheses to team clauses to kind sub-queries. This can be very useful if you desire to control the Boolean logic because that a query.


The query listed below searches for either "jakarta" or "ptcouncil.net" and also "website":


(jakarta OR ptcouncil.net) and also website


This add to precision to the query, requiring the the term "website" exist, together with either hatchet "jakarta" and "ptcouncil.net."


Grouping Clauses in ~ a Field


To apply two or an ext Boolean operators to a solitary field in a search, team the Boolean clauses in ~ parentheses. For example, the query listed below searches for a title ar that has both words "return" and the phrase "pink panther":


title:(+return +"pink panther")


Comments


C-Style comments are supported in query strings.


Example:


"jakarta ptcouncil.net" /* this is a comment in the center of a typical query cable */ OR jakarta


Comments might be nested.


Differences in between Lucene questions Parser and also the ptcouncil.net conventional Query Parser


ptcouncil.net’s conventional query parser different from the Lucene ask Parser in the complying with ways:


A * might be offered for either or both endpoints come specify an open-ended variety query


field:<* to 100> finds all ar values much less than or equal to 100

field:<100 to *> find all field values greater than or same to 100

field:<* to *> matches all documents with the field


Pure an unfavorable queries (all clauses prohibited) are permitted (only as a top-level clause)


-inStock:false find all field values whereby inStock is not false

-field:<* to *> finds all papers without a worth for field


A hook into FunctionQuery syntax. You’ll have to use estimates to encapsulate the duty if it has parentheses, as shown in the 2nd example below:


val:myfield

val:"recip(rord(myfield),1,2,3)"


Support for utilizing any form of ask parser as a nested clause.

See more: Weight Of A Gallon Of Sand, How Much Does A Gallon Of Sand Weigh


inStock:true OR !dismax qf="name manu" v="ipod"


Support because that a distinct filter(…​) syntax to suggest that some query clauses need to be cached in the filter cache (as a continuous score boolean query). This permits sub-queries to it is in cached and also re-used in other queries. For example inStock:true will certainly be cached and re-used in all 3 of the queries below:


q=features:songs OR filter(inStock:true)

q=+manu:Apple +filter(inStock:true)

q=+manu:Apple & fq=inStock:true


This can also be supplied to cache individual rule of complicated filter queries. In the an initial query below, 3 items will be added to the filter cache (the optimal level fq and both filter(…​) clauses) and also in the 2nd query, there will certainly be 2 cache hits, and also one new cache insertion (for the brand-new top level fq):


q=features:songs & fq=+filter(inStock:true) +filter(price:<* come 100>)

q=manu:Apple & fq=-filter(inStock:true) -filter(price:<* come 100>)


Range queries (""), prefix queries ("a*"), and wildcard queries ("a*b") are constant-scoring (all matching documents get an equal score). The scoring factors TF, IDF, index boost, and "coord" space not used. There is no limitation ~ above the number of terms that complement (as there was in past versions that Lucene).

Constant score queries are created with ^=, which set the whole clause come the specified score for any type of documents matching that clause:


q=(description:blue color:blue)^=1.0 title:blue^=5.0


Specifying Dates and also Times


Queries against fields making use of the TrieDateField form (typically variety queries) have to use the ideal date syntax:


timestamp:<* to NOW>

pubdate:


Related Topics


typical Query Parameters The DisMax query Parser

*