Performing Searches
CostOS uses the Lucene Engine to perform searches. This is the same engine that google uses, so there are many similarities with google in the way that searches are performed within CostOS. The searches can be performed on projects or on the resource database.
Terms¶
A query is broken up into terms and operators. There are two types of terms: Single Terms and Phrases. A Single Term is a single word such as "wall" or "pipe". A Phrase is a group of words surrounded by double quotes such as "masonry wall". Multiple terms can be combined together with Boolean operators to form a more complex query (see below).
Fields¶
CostOS supports fielded data. When performing a search you can either specify a field, or use all fields related to the item you are searching for.
You can search any field by typing the field name followed by a colon ":" and then the term you are looking for.
As an example, let's assume a CostOS BOQ Item which has a Title and a Note. If you want to find the item entitled "Masonry Wall" which contains the note "no thermal insulation", you can enter:
title: "Masonry Wall" AND note:no
or
title: "Masonry Wall" AND thermal
in this case CostOS will search for the word thermal on all BOQ Items. If you want to find the exact match then you can enter:
title: "Masonry Wall" AND note:"no thermal insulation"
Note: The field is only valid for the term that it directly precedes, so the query
title: Masonry Wall
Will only find "Masonry" in the title field. It will find "Wall" in all fields.
Wildcard Searches¶
CostOS supports single and multiple character wildcard searches within single terms (not within phrase queries). To perform a single character wildcard search use the "?" symbol. To perform a multiple character wildcard search use the "*" symbol. The single character wildcard search looks for terms that match that with the single character replaced. For example, to search for "text" or "test" you can use the search:
te?t
Multiple character wildcard searches looks for 0 or more characters. For example, to search for paint, paints or painting, you can use the search:
paint*
You can also use the wildcard searches in the middle of a term.
te*t
Note: You cannot use a * or ? symbol as the first character of a search.
Range Searches¶
Range Queries allow one to match items or database entries whose field(s) values are between the lower and upper bound specified by the Range Query. Range Queries can be inclusive or exclusive of the upper and lower bounds. Sorting is done lexicographically.
lastUpdate:[20020101 TO 20101210] This will find Items that have been last time updated, lastUpdate fields that have values, between 20020101 and 20101210, inclusive. Note that Range Queries are not reserved for date fields. You could also use range queries with non-date fields:
Country:{Bahamas TO Brazil} This will find all Items whose whose countries are between Bahamas and Brazil, but not including Bahamas and Brazil.
Inclusive range queries are denoted by square brackets. Exclusive range queries are denoted by curly brackets.
Boosting a Term¶
CostOS provides the relevance level of matching documents based on the terms found. To boost a term use the caret, "^", symbol with a boost factor (a number) at the end of the term you are searching. The higher the boost factor, the more relevant the term will be.
Boosting allows you to control the relevance of an item by boosting its term. For example, if you are searching for
masonry wall
and you want the term "masonry" to be more relevant boost it using the ^ symbol along with the boost factor next to the term. You would type:
masonry^4 wall
This will make items with the term masonry appear more relevant. You can also boost Phrase Terms as in the example:
"masonry wall"^4 "stone wall" By default, the boost factor is 1. Although the boost factor must be positive, it can be less than 1 (e.g. 0.2)
Boolean Operators¶
Boolean operators allow terms to be combined through logic operators. Lucene supports AND, "+", OR, NOT and "-" as Boolean operators(Note: Boolean operators must be ALL CAPS).
OR¶
The OR operator is the default conjunction operator. This means that if there is no Boolean operator between two terms, the OR operator is used. The OR operator links two terms and finds a matching item if either of the terms exist in the item. This is equivalent to a union using sets. The symbol || can be used in place of the word OR.
To search for a resource that contain either "reinforced concrete" or just "concrete" use the query:
"reinforced concrete" concrete
or
"reinforced concrete" OR concrete
AND¶
The AND operator matches items where both terms exist anywhere in the fields of a single item. This is equivalent to an intersection using sets. The symbol && can be used in place of the word AND.
To search for documents that contain "reinforced concrete" and "grade 20MPa" use the query:
"reinforced concrete" AND "grade 20MPa"
+¶
The "+" or required operator requires that the term after the "+" symbol exist somewhere in a the field of a single document.
To search for documents that must contain "reinforced" and may contain "concrete" use the query:
+reinforced concrete
NOT¶
The NOT operator excludes items that contain the term after NOT. This is equivalent to a difference using sets. The symbol ! can be used in place of the word NOT.
To search for items that contain "reinforced concrete" but not "grade 20MPa" use the query:
"reinforced concrete" NOT "grade 20Mpa"
Warning
The NOT operator cannot be used with just one term. For example, the following search will return no results:
NOT "20Mpa"
** - ** The "-" or prohibit operator excludes items that contain the term after the "-" symbol.
To search for items that contain "reinforced concrete" but not "grade 20MPA" use the query:
"reinforced concrete" -"grade 20MPa"
Grouping¶
CostOS Search supports using parentheses to group clauses to form sub queries. This can be very useful if you want to control the boolean logic for a query.
To search for either "pipe" or "valve" and "stainless" use the query:
(pipe OR valve) AND stainless
This eliminates any confusion and makes sure you that stainless must exist and either term pipe or valve may exist.
Field Grouping¶
CostOS Search supports using parentheses to group multiple clauses to a single field. To search for a title that contains both the word "paint" and the phrase "carbon steel" use the query:
title:(+paint +"carbon steel")