
# Differences from Spring

Spring has no full-text search of its own. A Spring application uses Hibernate Search (Lucene or Elasticsearch behind JPA entities) or the client of a search server (Spring Data Elasticsearch). `spring_search_dart` plays that part inside the application, in memory, with Spring's model: beans for the sources, analyzers and rankers, properties for the rest, an event to rebuild.

## Why

Knowing what it is not helps choosing it: it is an in-memory index for the documents an application holds, not a search server.

## Example

```java
// Hibernate Search: an entity marked for indexing
@Indexed
@Entity
class Book {
  @FullTextField(analyzer = "english") String title;
}
```

```dart
// Here: a bean gives the documents, the analyzer comes from the language
@Component()
class BookDocuments implements SearchDocumentSource {
  BookDocuments(this.books);
  final BookRepository books;

  @override
  Stream<SearchDocument> documents() async* {
    for (final book in await books.findAll()) {
      yield SearchDocument(id: 'book-${book.id}', fields: {'title': book.title});
    }
  }
}
```

## Compared with a search server

| A search server (Elasticsearch) | Here |
|---|---|
| A separate process, network calls | In the application's memory, no network |
| Indexes kept on disk, updated document by document | Rebuilt from the sources at the first search, and after a `SearchIndexInvalidatedEvent` |
| Millions of documents | Thousands: a site's sections, a shop's products, an app's notes |
| Language analyzers with dictionaries | `standard` and `english`, and analyzers of your own; Chinese, Japanese and Korean in pairs of characters, without a dictionary |
| Facets, aggregations, geo queries | None; `collapse-by` keeps one hit per value of an attribute |

## Limits

- Not on pub.dev yet: a git dependency of the framework's repository.
- The index is rebuilt whole when the documents change; there is no update of one document.
- Only English has a stemmer and stop words built in.

## See also

- [Overview](index.md)
- [Analyzers and rankers](analyzers.md)
