|
|
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 Zend_Search_Lucene component documentation.
What follows are examples of some common query types and strategies.
例1 Querying for a single word
hello
Searches for the word "hello" through all document fields.
注意: Default search field
Important note! Java Lucene searches only through the "contents" field by default, but
Zend_Search_Lucenesearches through all fields. This behavior can be modified using the Zend_Search_Lucene::setDefaultSearchField($fieldName) method.
例2 Querying for multiple words
hello dolly
Searches for two words. Both words are optional; at least one of them must be present in the result.
例3 Requiring words in a query
+hello dolly
Searches for two words; "hello" is required, "dolly" is optional.
例4 Prohibiting words in queried documents
+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.
例5 Querying for phrases
"hello dolly"
Searches for the phrase "hello dolly"; a document only matches if that exact string is present.
例6 Querying against specific fields
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.
例7 Querying against specific fields as well as the entire document
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.
例8 Querying against specific fields as well as the entire document (alternate)
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.
例9 Querying with the wildcard "?"
te?t
Search for words matching the pattern "te?t", where "?" is any single character.
例10 Querying with the wildcard "*"
test*
Search for words matching the pattern "test*", where "*" is any sequence of zero or more characters.
例11 Querying for an inclusive range of terms
mod_date:[20020101 TO 20030101]
Search for the range of terms (inclusive).
例12 Querying for an exclusive range of terms
title:{Aida to Carmen}
Search for the range of terms (exclusive).
例13 Fuzzy searches
roam~
Fuzzy search for the word "roam".
例14 Boolean searches
(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:
例15 Combining parsed and constructed queries
$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 */);
|
|
Copyright © 2005-2011 Zend Technologies Inc (compiled by mikaelkael with ZFDocumentor - SVN 22750).

