Package Home

Zend Framework 2 Documentation (Manual)

PHK Home

File: /tutorials/lucene.queries.html

Size:15620
Storage flags:no_autoload,compress/gzip (25%)

Supported queries — Zend Framework 2 2.4.2 documentation

Supported queriesΒΆ

Zend\Search\Lucene and Java Lucene support a powerful query language. It allows searching for individual terms, phrases, ranges of terms; using wildcards and fuzzy search; combining queries using boolean operators; and so on.

A detailed query language description can be found in the ZendSearchLucene component documentation.

What follows are examples of some common query types and strategies.

Querying for a single word

1
hello

Searches for the word “hello” through all document fields.

Note

Default search field

Important note! Java Lucene searches only through the “contents” field by default, but Zend\Search\Lucene searches through all fields. This behavior can be modified using the Zend\Search\Lucene::setDefaultSearchField($fieldName) method.

Querying for multiple words

1
hello dolly

Searches for two words. Both words are optional; at least one of them must be present in the result.

Requiring words in a query

1
+hello dolly

Searches for two words; “hello” is required, “dolly” is optional.

Prohibiting words in queried documents

1
+hello -dolly

Searches for two words; “hello” is required, ‘dolly’ is prohibited. In other words, if the document matches “hello”, but contains the word “dolly”, it will not be returned in the set of matches.

Querying for phrases

1
"hello dolly"

Searches for the phrase “hello dolly”; a document only matches if that exact string is present.

Querying against specific fields

1
title:"The Right Way" AND text:go

Searches for the phrase “The Right Way” within the title field and the word “go” within the text field.

Querying against specific fields as well as the entire document

1
title:"The Right Way" AND  go

Searches for the phrase “The Right Way” within the title field and the word “go” word appearing in any field of the document.

Querying against specific fields as well as the entire document (alternate)

1
title:Do it right

Searches for the word “Do” within the title field and the words “it” and “right” words through all fields; any single one matching will result in a document match.

Querying with the wildcard ”?”

1
te?t

Search for words matching the pattern “te?t”, where ”?” is any single character.

Querying with the wildcard “*”

1
test*

Search for words matching the pattern “test*”, where “*” is any sequence of zero or more characters.

Querying for an inclusive range of terms

1
mod_date:[20020101 TO 20030101]

Search for the range of terms (inclusive).

Querying for an exclusive range of terms

1
title:{Aida to Carmen}

Search for the range of terms (exclusive).

Fuzzy searches

1
roam~

Fuzzy search for the word “roam”.

Boolean searches

1
(framework OR library) AND php

Boolean query.

All supported queries can be constructed through Zend\Search\Lucene‘s query construction API. Moreover, query parsing and query constructing may be combined:

Combining parsed and constructed queries

1
2
3
4
5
$userQuery = Zend\Search\Lucene\Search\QueryParser::parse($queryStr);

$query = new Zend\Search\Lucene\Search\Query\Boolean();
$query->addSubquery($userQuery, true  /* required */);
$query->addSubquery($constructedQuery, true  /* required */);

This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Supported queries on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.

For more information about the PHK package format: http://phk.tekwire.net