0 ×

Index Query

KNIME Indexing and Searching version 3.6.0.v201805031002 by KNIME AG, Zurich, Switzerland

This node allows to query a given index. The node either creates a new data table or filters an optional input table based on the result of the query.

If no input table is available the data table is created based on the information that is available in the given index. If the index contains the original data (see "Save original data" option in the Table Indexer node) the table will contain a column for each index field that supports the storing of original data. Whereas the table contains only the row id of the matching document if the index does not contain the original data.

If an input table is available it is filtered based on the result of the query. When filtering the values of a row have to match the values of one of the result documents from the index as specified on the Result Field to Column Matching tab.

The following sections describe the query syntax that is support. The syntax is based on Lucene. For a detailed description of Lucene and its syntax see the Lucene project page.

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 "test" or "hello". A Phrase is a group of words surrounded by double quotes such as "hello dolly". Multiple terms can be combined together with Boolean operators to form a more complex query (see below). Note: The analyzer used to create the index will be used on the terms and phrases in the query string. The type of analyzer is automatically chosen based on the DataType. If the field is marked as not analyzed the term is taken as is.

Date formats

If you want to query a date/time field you have to define the date in one of the following formats:
  • yyyy-MM-dd;HH.mm.ss.S;Z e.g. 2012-05-28;17.25.33.500;PDT
  • yyyy-MM-dd;HH.mm.ss.S e.g. 2012-05-28;17.25.33.500
  • yyyy-MM-dd;HH.mm.ss;Z e.g. 2012-05-28;17.25.33;GMT
  • yyyy-MM-dd;HH.mm.ss e.g. 2012-05-28;17.25.33
  • yyyy-MM-dd e.g. 2012-05-28
  • HH.mm.ss.S e.g. 17.25.33.500
  • HH.mm.ss e.g. 17.25.33
Examples for valid time zones are: GMT,EST,PDT. The Coordinated Universal Time (UTC) is used as default time zone if none is specified. The date is internal represented as the number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

Fields

Lucene supports fielded data. When performing a search you can either specify a field, or use the default field. By default all available fields are searched. If the special characters and space must be escaped in field names using \. Fore details about the special characters and how to escape them see the "Escaping Special Characters" section below. 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 Lucene index contains two fields, title and text and text is the default field. If you want to find the document entitled "The Right Way" which contains the text "don't go this way", you can enter:

title:"The Right Way" AND text:go

or

title:"Do it right" AND right

Since text is the default field, the field indicator is not required. Note: The field is only valid for the term that it directly precedes, so the query

title:Do it right

Will only find "Do" in the title field. It will find "it" and "right" in the default field (in this case the text field).

Term Modifiers

Lucene supports modifying query terms to provide a wide range of searching options.

Wildcard Searches

Lucene 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 test, tests or tester, you can use the search:

test*

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.

Regular Expression Searches

Lucene supports regular expression searches matching a pattern between forward slashes "/". The syntax may change across releases, but the current supported syntax is documented in the RegEx class. For example to find documents containing "moat" or "boat": /[mb]oat/

Fuzzy Searches

Lucene supports fuzzy searches based on Damerau-Levenshtein Distance. To do a fuzzy search use the tilde, "~", symbol at the end of a Single word Term. For example to search for a term similar in spelling to "roam" use the fuzzy search:

roam~

This search will find terms like foam and roams. An additional (optional) parameter can specify the maximum number of edits allowed. The value is between 0 and 2, For example:

roam~1

The default that is used if the parameter is not given is 2 edit distances. Previously, a floating point value was allowed here. This syntax is considered deprecated and will be removed in Lucene 5.0

Proximity Searches

Lucene supports finding words are a within a specific distance away. To do a proximity search use the tilde, "~", symbol at the end of a Phrase. For example to search for a "apache" and "jakarta" within 10 words of each other in a document use the search:

"jakarta apache"~10

Range Searches

Range Queries allow one to match documents 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.

mod_date:[2002/01/01 TO 2003/01/01]

This will find documents whose mod_date fields have values between 2002/01/01 and 2003/01/01, inclusive. Note that Range Queries are not reserved for date fields. You could also use range queries with non-date fields:

title:{Aida TO Carmen}

This will find all documents whose titles are between Aida and Carmen, but not including Aida and Carmen. Inclusive range queries are denoted by square brackets. Exclusive range queries are denoted by curly brackets.

Boosting a Term

Lucene 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 a document by boosting its term. For example, if you are searching for

jakarta apache

and you want the term "jakarta" to be more relevant boost it using the ^ symbol along with the boost factor next to the term. You would type:

jakarta^4 apache

This will make documents with the term jakarta appear more relevant. You can also boost Phrase Terms as in the example:

"jakarta apache"^4 "Apache Lucene"

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 document if either of the terms exist in a document. This is equivalent to a union using sets. The symbol || can be used in place of the word OR. To search for documents that contain either "jakarta apache" or just "jakarta" use the query:

"jakarta apache" jakarta

or

"jakarta apache" OR jakarta

AND

The AND operator matches documents where both terms exist anywhere in the text of a single document. 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 "jakarta apache" and "Apache Lucene" use the query:

"jakarta apache" AND "Apache Lucene"

+

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 "jakarta" and may contain "lucene" use the query:

+jakarta lucene

NOT

The NOT operator excludes documents 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 documents that contain "jakarta apache" but not "Apache Lucene" use the query:

"jakarta apache" NOT "Apache Lucene"

Note: The NOT operator cannot be used with just one term. For example, the following search will return no results:

NOT "jakarta apache"

-

The "-" or prohibit operator excludes documents that contain the term after the "-" symbol. To search for documents that contain "jakarta apache" but not "Apache Lucene" use the query:

"jakarta apache" -"Apache Lucene"

Grouping

Lucene 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 "jakarta" or "apache" and "website" use the query:

(jakarta OR apache) AND website

This eliminates any confusion and makes sure you that website must exist and either term jakarta or apache may exist.

Field Grouping

Lucene supports using parentheses to group multiple clauses to a single field. To search for a title that contains both the word "return" and the phrase "pink panther" use the query:

title:(+return +"pink panther")

Escaping Special Characters

Lucene supports escaping special characters that are part of the query syntax. The current list special characters are

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /

To escape these character use the \ before the character. For example to search for (1+1):2 use the query: \(1\+1\)\:2

Options

Query

Field List
List of all fields that are available in the index. You can add a field to the query text by clicking on its name in the list. The field name and the current selected operator are added to the query text at the current cursor position.
Operator
The operator that should be used to combine field queries. The operator is used when a field name is added to the query text by clicking on its corresponding name in the field list.
Query Text
The query to execute. The query syntax is described in detail above. The query can be assembled by clicking on the names of the fields that should be used in the field list. If the query contains already a field name the new field name is added using the selected operator from the operator select box.
Add Score Column
If this option is selected a score column is added at the end of the table that contains the score for the retrieved row. The score defines how well the row matches the query criteria.
Retrieve All Docs
Select this option to retrieve all documents that match the query otherwise only the top X documents that match the query are retrieved.

Result Field to Column Matching

Matcher Columns
Specifies the field-column pairs that should match. Data rows of the input table are only added to the output table if the value of the specified column in this row matches one of the result values of the corresponding field.
Match Operator
All pairs must match if the "AND" option is selected. If "OR" is selected only one of the specified pairs has to match.

Input Ports

The index
Optional data table to filter

Output Ports

Table containing matching rows

Best Friends (Incoming)

Best Friends (Outgoing)

Workflows

Update Site

To use this node in KNIME, install KNIME Indexing and Searching from the following update site:

Wait a sec! You want to explore and install nodes even faster? We highly recommend our NodePit for KNIME extension for your KNIME Analytics Platform.