Fields and methods of the helma.Search class
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/helma/Search.js')
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/helma/Search.js')
Constructs a new instance of helma.Search. This merely
checks if the Apache Lucene library is in the application
classpath.
methods
- getDirectory(dir, create)
- getRAMDirectory(dir)
- createIndex(dir, analyzer)
Constructs a new QueryFilter instance. This class
wraps a lucene QueryFilter.
parameters
| helma.Search.Query | q | The query object to use as the basis for the QueryFilter instance. |
methods
Creates a new instance of helma.Search.Index
parameters
| org.apache.lucene.store.Directory | directory | The directory where the Lucene index is located at. |
| org.apache.lucene.analysis.Analyzer | analyzer | The analyzer to use when modifying the index. |
methods
- getWriter(create, autoCommit)
- addIndexes(dir)
- create()
- size()
- count(fieldName, fieldValue)
- optimize()
- isLocked()
- unlock()
- close()
- addDocument(doc)
- addDocuments(docs)
- removeDocument(fieldName, fieldValue)
- removeDocuments(fieldName, values)
- updateDocument(docObj, fieldName)
Creates a new instance of helma.Search.Seacher
parameters
| helma.Search.Index | index | The index to search in. |
methods
- search(query, filter)
- sortBy(fieldName, type)
- close()
properties
- helma.Search.HitCollection hits
- java.util.Vector sortFields
Creates a new instance of helma.Search.HitCollection
parameters
| org.lucene.search.Hits | hits | The hit collection returned by lucene. |
methods
- get(idx)
- size()
- length()
- forEach(fun, context)
Creates a new instance of helma.Search.TermQuery
parameters
| String | field | The name of the field |
| String | str | The value of the field |
properties
- org.apache.lucene.search.TermQuery query
inherits
getQuery() from helma.Search.Query
getBoost() from helma.Search.Query
setBoost(fact) from helma.Search.Query
Creates a new instance of helma.Search.BooleanQuery
parameters
| String | name of the field | |
| String | query string |
methods
- addTerm(field, str, clause, analyzer)
- addQuery(q, clause)
properties
- org.apache.lucene.search.BooleanQuery query
inherits
getQuery() from helma.Search.Query
getBoost() from helma.Search.Query
setBoost(fact) from helma.Search.Query
Constructs a new helma.Search.PhraseQuery instance that wraps
a Lucene Phrase Query object.
parameters
| String | field | The name of the field |
| String | str | The phrase query string |
methods
- addTerm(field, str)
properties
- org.apache.lucene.search.PhraseQuery query
inherits
getQuery() from helma.Search.Query
getBoost() from helma.Search.Query
setBoost(fact) from helma.Search.Query
Constructs a new helma.Search.RangeQuery instance.
parameters
| String | field | The name of the field |
| String | from | The minimum value to match (can be null) |
| String | to | The maximum value to match (can be null) |
| Boolean | inclusive | If true the given min/max values are included |
properties
- org.apache.lucene.search.RangeQuery query
inherits
getQuery() from helma.Search.Query
getBoost() from helma.Search.Query
setBoost(fact) from helma.Search.Query
Constructs a new helma.Search.FuzzyQuery instance.
parameters
| String | field | The name of the field |
| String | str | The query string to match |
properties
- org.apache.lucene.search.FuzzyQuery query
inherits
getQuery() from helma.Search.Query
getBoost() from helma.Search.Query
setBoost(fact) from helma.Search.Query
Constructs a new helma.Search.PrefixQuery instance.
parameters
| String | field | The name of the field |
| String | str | The query string to match |
properties
- org.apache.lucene.search.PrefixQuery query
inherits
getQuery() from helma.Search.Query
getBoost() from helma.Search.Query
setBoost(fact) from helma.Search.Query
Constructs a new helma.Search.WildcardQuery instance.
parameters
| String | field | The name of the field |
| String | str | The query string to match |
properties
- org.apache.lucene.search.WildcardQuery query
inherits
getQuery() from helma.Search.Query
getBoost() from helma.Search.Query
setBoost(fact) from helma.Search.Query
Creates a new instance of helma.Search.Document.
parameters
| org.apache.lucene.document.Document | document | Optional Lucene Document object that should be wrapped by this Document instance. |
methods
- addField(name, value, options)
- getField(name)
- getFields(name)
- removeField(name)
- getBoost()
- setBoost(boost)
Creates a new Field instance
parameters
| Object | name | The name of the field |
| Object | value | The value of the field |
| Object | options |
Optional object containing the following properties
(each of them is optional too):
|
methods
- getField()
- getBoost()
- setBoost(boost)
- isStored()
properties
- String name
- String value
- String dateValue
The search results.
A vector with SortField instances, if any have been defined.
see
Contains the wrapped TermQuery instance
Contains the wrapped BooleanQuery instance
Contains the wrapped PhraseQuery instance
Contains the wrapped RangeQuery instance
Contains the wrapped FuzzyQuery instance
Contains the wrapped PrefixQuery instance
Contains the wrapped WildcardQuery instance
Contains the name of the field
Contains the string value of the field
Contains the value of the field converted into a date object.
Methods
Returns a new Analyzer instance depending on the key
passed as argument. Currently supported arguments are
"br" (BrazilianAnalyzer), "cn" (ChineseAnalyzer), "cz" (CzechAnalyzer),
"nl" (DutchAnalyzer), "fr" (FrenchAnalyzer), "de" (GermanAnalyzer),
"el" (GreekAnalyzer), "keyword" (KeywordAnalyzer), "ru" (RussianAnalyzer),
"simple" (SimpleAnalyzer), "snowball" (SnowballAnalyzer), "stop" (StopAnalyzer)
"whitespace" (WhitespaceAnalyzer). If no argument is given, a StandardAnalyzer
is returned.
parameters
| String | key | The key identifying the analyzer |
returns
| A newly created Analyzer instance |
Returns the wrapped filter instance
Returns an instance of org.apache.lucene.store.FSDirectory. If
no index is present in the given directory, it is created on the fly.
parameters
| File, helma.File, java.io.File, String | dir | The directory where the index is located or should be created at. |
| Boolean | create | If true the index will be created, removing any existing index in the same directory |
returns
| The index directory. |
Returns a RAM directory object.
parameters
| File, helma.File, java.io.File, String | dir | Optional directory containing a Lucene index from which this RAM directory should be created. |
returns
| A RAM directory instance. |
Creates a new Lucene index in the directory passed as
argument, using an optional analyzer, and returns an instance
of helma.Search.Index. Any already existing index in this
directory will be preserved.
parameters
| org.apache.lucene.store.Directory | dir | The directory where the index should be stored. This can be either a FSDirectory or a RAMDirectory instance. |
| org.apache.lucene.analysis.Analyzer | analyzer | The analyzer to use for the index. If not specified a StandardAnalyzer will be used. |
returns
| The index instance. |
Returns an IndexWriter instance that can be used to add documents to
the underlying index or to perform various other modifying operations.
If the index is currently locked this method will try for the next
two seconds to create the IndexWriter, otherwise it will
throw an error.
parameters
| Boolean | create | True to create the index (overwriting an existing index), false to append to an existing index. Defaults to false |
| Boolean | autoCommit | Enables or disables auto commit (defaults to false) |
returns
| An IndexWriter instance. |
Returns an IndexReader instance. Due to locking issues an
IndexModifier should be used for deleting documents.
returns
| An IndexReader instance |
Returns the directory the underlying Lucene index is located at.
returns
| The directory of this index |
Returns the analyzer used within this index.
returns
| The analyzer used within this index. |
Returns a searcher for querying this index.
returns
| A searcher useable for querying the index. |
Merges the indexes passed as argument into this one.
parameters
| org.apache.lucene.store.Directory | dir | At least one index director to add to this index. |
Creates a new index. This will delete any existing index
files in the directory of this index.
returns
| True if creating the index was successful, false otherwise |
Returns the number of documents in this index.
returns
| The number of documents in this index. |
Returns the number of documents with the given field name and value.
parameters
| String | fieldName | The name of the field |
| String | fieldValue | The value of the field |
returns
| The number of documents |
Optimizes the underlying index.
Returns an array containing all field names in this index.
returns
| An array with the field names in this index. |
Checks if the index is locked.
returns
| True if the underlying index is locked, false otherwise. |
Unlocks the index. Use this with caution, as it removes
any active locks in the Lucene index, which might lead
to index corruption.
Closes the underlying index directory for future operations.
Adds a document to the index.
parameters
| helma.Search.Document | doc | The document to add to the index. |
Adds all documents in the passed collection to this index.
parameters
| java.util.Hashtable, java.util.Vector, Array | docs | The documents to add to the index. |
Remove all documents from the index whose field-value
with the given name matches the passed value argument.
parameters
| String | fieldName | The name of the field |
| String | fieldValue | The value of the field. |
Removes all documents whose field with the given name matches
the values passed as argument.
parameters
| String | fieldName | The name of the field |
| java.util.Hashtable, java.util.Vector, Array | values | The values that define the documents that should be removed from the index. |
Updates the index with the document passed as argument. In contrast
to addDocument() this removes any existing objects whose fieldName
matches the one of the document object. Eg. if the document object
has a field "Id" with the value "123", all document objects whose
fieldName "Id" matches "123" will be removed from the index before.
parameters
| helma.Search.Document | docObj | Document object to add to index. |
| String | fieldName | The name of the identifier field. |
Returns the wrapped IndexSearcher instance.
Searches an index using the query passed as argument.
The resulting collection of hits is stored in the property "hits"
of this Searcher instance. Don't forget to close the searcher
when finished processing its hits.
parameters
| helma.Search.Query | query | The query to use for searching |
| helma.Search.QueryFilter | filter | An optional query filter for filtering the results. |
returns
| The number of hits. |
Sets a field as result sorting field. This method can be called
with a different number of arguments:
sortBy(fieldName)
sortBy(fieldName, type)
sortBy(fieldName, reverse)
sortBy(fieldName, type, reverse)
parameters
| String | fieldName | The name of the field in the index by which the search result should be ordered. |
| String | type | The type of the field defined by argument fieldName. Valid arguments are "string", "float", "int", "score", "doc", "auto", "custom". Default is "auto". See http://lucene.apache.org/java/docs/api/org/apache/lucene/search/SortField.html for an explanation. |
Closes the wrapped IndexSearcher instance.
Silently converts the hit at the given index position into
an instance of helma.Search.Document.
parameters
| Number | idx | The index position of the hit |
returns
| The document object at the given index position |
Returns the number of hits in this collection.
returns
| The number of hits. |
Returns the number of hits in this collection.
This method is deprecated, use {@link #size} instead.
returns
| The number of hits. |
see
Executes a provided function once per hit.
parameters
| Function | fun | Function to execute for each element |
| Object | context | Object to use as "this" when executing callback. |
see
Returns the wrapped Lucene Query object.
returns
| The wrapped query object |
Returns the boost factor of this query.
Sets the boost factor of this query clause to
the given number. Documents matching this query
will have their score multiplied with the given
factor
parameters
| Number | fact | The factor to multiply the score of matching documents with. |
Adds a term to the wrapped query object. This method can be called
with two, three or four arguments, eg.:
addTerm("fieldname", "querystring")
addTerm("fieldname", "querystring", "and")
addTerm("fieldname", "querystring", helma.Search.getAnalyzer("de"))
addTerm("fieldname", "querystring", "not", helma.Search.getAnalyzer("simple"))parameters
| String, Array | field | Either a String or an Array containing Strings that determine the index field(s) to match |
| String | str | Query string to match |
| String | clause | Boolean clause ("or", "not" or "and", default is "and") |
| org.apache.lucene.analysis.Analyzer | analyzer | An analyzer to use |
Adds an additional query clause to this query.
parameters
| helma.Search.Query | q | The query to add |
| String | clause | Boolean clause ("or", "not", or "and", default is "and") |
add a term to the end of the phrase query
parameters
| field | ||
| str |
Returns the wrapped Lucene Document object
returns
| The wrapped Document object |
Adds a field to this document.
parameters
| String, helma.Search.Document.Field | name | The name of the field, or an instance of {@link helma.Search.Document.Field}, in which case the other arguments are ignored. |
| String | value | The value of the field |
| Object | options |
Optional object containing the following properties
(each of them is optional too):
|
Returns a single document field.
parameters
| String | name | The name of the field in this document object. |
returns
| The field with the given name |
Returns the fields of a document object. If a name is passed as argument,
this method returns only the fields with the given name
parameters
| String | name | Optional name of the fields to return |
returns
| An array containing all fields in this document object. |
Removes all fields with the given name from this document
parameters
| String | name | The name of the field(s) to remove |
Returns the boost factor of a document.
returns
| The boost factor of a document |
Sets the boost factor of a document.
parameters
| Number | boost | The boost factor of the document |
Returns the wrapped field instance
returns
| The wrapped field |
Converts the value passed as argument to the appropriate string value. For
null values this method returns an empty string.
parameters
| Object | value | The value to convert into a string |
returns
| The value converted into a string |
Returns the boost factor of this field.
returns
| The boost factor of this field |
Sets the boost factor of this field.
parameters
| Number | boost | The boost factor of this field |
Returns true if this field is indexed
returns
| True if this field's value is indexed, false otherwise |
Returns true if this field's value is stored in compressed form in the index
returns
| True if this field's value is compressed, false otherwise |
Returns true if this field's value is stored in the index
returns
| True if this field's value is stored, false otherwise |
Returns true if this field's value is tokenized
returns
| True if this field's value is tokenized, false otherwise |
Returns true if this field's term vector is stored in the index
returns
| True if this field's term vector is stored, false otherwise |
