# Class: Searcher

## helma.Search.Searcher(index)

This class provides basic functionality for searching an index.

## Constructor

#### new Searcher(index)

Creates a new instance of helma.Search.Seacher

##### Parameters:

Name | Type | Description
--- | --- | ---
`index` | helma.Search.Index | The index to search in.

Source:
  - helma/Search.js, line 616

##### Returns:

A newly created index searcher

### Members

#### hits :helma.Search.HitCollection

The search results.

##### Type:

- helma.Search.HitCollection

Source:
  - helma/Search.js, line 623

#### sortFields :java.util.Vector

A vector with SortField instances, if any have been defined.

##### Type:

- java.util.Vector

Source:
  - helma/Search.js, line 630
See:
  - #sortBy

### Methods

#### close()

Closes the wrapped IndexSearcher instance.

Source:
  - helma/Search.js, line 724

#### getSearcher()

Returns the wrapped IndexSearcher instance.

Source:
  - helma/Search.js, line 636

#### search(query, filter)

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:

Name | Type | Description
--- | --- | ---
`query` | helma.Search.Query | The query to use for searching
`filter` | helma.Search.QueryFilter | An optional query filter for filtering the results.

Source:
  - helma/Search.js, line 659

##### Returns:

The number of hits.

#### sortBy(fieldName, type)

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:

Name | Type | Description
--- | --- | ---
`fieldName` | String | The name of the field in the index by which the search result should be ordered.
`type` | String | 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.

Source:
  - helma/Search.js, line 700