## org.apache.mahout.math.neighborhood
Class ProjectionSearch

    java.lang.Object
      org.apache.mahout.math.neighborhood.Searcher
          org.apache.mahout.math.neighborhood.UpdatableSearcher
              org.apache.mahout.math.neighborhood.ProjectionSearch

All Implemented Interfaces:
  Iterable<Vector>

    public class ProjectionSearch

extends UpdatableSearcher

Does approximate nearest neighbor dudes search by projecting the data.

Field Summary

Fields inherited from class org.apache.mahout.math.neighborhood.Searcher
`distanceMeasure`

Constructor Summary
`ProjectionSearch(DistanceMeasure distanceMeasure, int numProjections, int searchSize)`

Method Summary
`void` `add(Vector vector)` Adds a WeightedVector into the set of projections for later searching.
`void` `clear()`
`Iterator<Vector>` `iterator()`
`boolean` `remove(Vector vector, double epsilon)`
`List<WeightedThing<Vector>>` `search(Vector query, int limit)` Searches for the query vector returning the closest limit referenceVectors.
`WeightedThing<Vector>` `searchFirst(Vector query, boolean differentThanQuery)` Returns the closest vector to the query.
`int` `size()` Returns the number of scalarProjections that we can search

Methods inherited from class org.apache.mahout.math.neighborhood.Searcher
`addAll, addAllMatrixSlices, addAllMatrixSlicesAsWeightedVectors, getCandidateQueue, getDistanceMeasure, search, searchFirst`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ProjectionSearch

    public ProjectionSearch(DistanceMeasure distanceMeasure,
                            int numProjections,
                            int searchSize)

Method Detail

### add

    public void add(Vector vector)

  Adds a WeightedVector into the set of projections for later searching.

  Specified by:
    `add` in class `Searcher`
  Parameters:
    `vector` - The WeightedVector to add.

### size

    public int size()

  Returns the number of scalarProjections that we can search

  Specified by:
    `size` in class `Searcher`
  Returns:
    The number of scalarProjections added to the search so far.

### search

    public List<WeightedThing<Vector>> search(Vector query,
                                              int limit)

  Searches for the query vector returning the closest limit referenceVectors.

  Specified by:
    `search` in class `Searcher`
  Parameters:
    `query` - the vector to search for.
    `limit` - the number of results to return.
  Returns:
    a list of Vectors wrapped in WeightedThings where the "thing"'s weight is the distance.

### searchFirst

    public WeightedThing<Vector> searchFirst(Vector query,
                                             boolean differentThanQuery)

  Returns the closest vector to the query. When only one the nearest vector is needed, use this method, NOT search(query, limit) because it's faster (less overhead).

  Specified by:
    `searchFirst` in class `Searcher`
  Parameters:
    `query` - the vector to search for
    `differentThanQuery` - if true, returns the closest vector different than the query (this only matters if the query is among the searched vectors), otherwise, returns the closest vector to the query (even the same vector).
  Returns:
    the weighted vector closest to the query

### iterator

    public Iterator<Vector> iterator()

### remove

    public boolean remove(Vector vector,
                          double epsilon)

  Specified by:
    `remove` in class `UpdatableSearcher`

### clear

    public void clear()

  Specified by:
    `clear` in class `UpdatableSearcher`

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.