public class IndexRepository extends Object implements Closeable
Represents a container for combining multiple indexes and performing common operations on them.
Learn more
The example demonstrates a typical usage of the class.
String indexFolder1 = "c:\\MyIndex\\";
String indexFolder2 = "c:\\MyIndex\\";
String query = "Einstein";
IndexRepository repository = new IndexRepository();
repository.addToRepository(indexFolder1); // Loading an existing index
repository.addToRepository(indexFolder2); // Loading another existing index
SearchResult result = repository.search(query); // Searching in indexes of the repository
Constructor and Description |
---|
IndexRepository()
Initializes a new instance of the
IndexRepository class. |
Modifier and Type | Method and Description |
---|---|
void |
addToRepository(Index index)
Adds an index to the index repository.
|
void |
addToRepository(String indexFolder)
Opens and adds an index to the index repository.
|
void |
close()
Releases all resources used by the
IndexRepository . |
Index |
create()
Creates a new index in memory.
|
Index |
create(IndexSettings settings)
Creates a new index in memory.
|
Index |
create(String indexFolder)
Creates a new index on disk.
|
Index |
create(String indexFolder,
IndexSettings settings)
Creates a new index on disk.
|
protected void |
finalize()
Finalizes an instance of the
IndexRepository class. |
EventHub |
getEvents()
Gets the event hub for subscribing to events.
|
Index[] |
getIndexes()
Gets the indexes contained in this
IndexRepository . |
SearchResult |
search(SearchQuery query)
Searches in all indexes of the repository.
|
SearchResult |
search(SearchQuery query,
SearchOptions options)
Searches in all indexes of the repository.
|
SearchResult |
search(String query)
Searches in all indexes of the repository.
|
SearchResult |
search(String query,
SearchOptions options)
Searches in all indexes of the repository.
|
void |
update()
Updates all indexes in the repository.
|
void |
update(UpdateOptions options)
Updates all indexes in the repository.
|
public IndexRepository()
Initializes a new instance of the IndexRepository
class.
protected void finalize() throws Throwable
Finalizes an instance of the IndexRepository
class.
public final EventHub getEvents()
Gets the event hub for subscribing to events.
public final Index[] getIndexes()
Gets the indexes contained in this IndexRepository
.
public final void close()
Releases all resources used by the IndexRepository
.
close
in interface Closeable
close
in interface AutoCloseable
public final Index create()
Creates a new index in memory.
The example demonstrates how to create an index in memory through the index repository.
IndexRepository indexRepository = new IndexRepository();
Index index = indexRepository.create();
public final Index create(IndexSettings settings)
Creates a new index in memory.
settings
- The index settings.
The example demonstrates how to create an index in memory through the index repository.
IndexRepository indexRepository = new IndexRepository();
IndexSettings settings = new IndexSettings();
settings.setUseStopWords(false); // Disabling use of stop words during indexing
Index index = indexRepository.create(settings);
public final Index create(String indexFolder)
Creates a new index on disk. The index folder will be cleaned before the index creation.
indexFolder
- The index folder.
The example demonstrates how to create an index on disk through the index repository.
String indexFolder = "c:\\MyIndex\\";
IndexRepository indexRepository = new IndexRepository();
Index index = indexRepository.create(indexFolder);
public final Index create(String indexFolder, IndexSettings settings)
Creates a new index on disk. The index folder will be cleaned before the index creation.
indexFolder
- The index folder.settings
- The index settings.
The example demonstrates how to create an index on disk through the index repository.
String indexFolder = "c:\\MyIndex\\";
IndexRepository indexRepository = new IndexRepository();
IndexSettings settings = new IndexSettings();
settings.setUseStopWords(false); // Disabling use of stop words during indexing
Index index = indexRepository.create(indexFolder, settings);
public final void addToRepository(Index index)
Adds an index to the index repository.
index
- The index to add.
The example demonstrates how to add an index to the index repository.
Index index = new Index();
IndexRepository indexRepository = new IndexRepository();
indexRepository.addToRepository(index);
public final void addToRepository(String indexFolder)
Opens and adds an index to the index repository.
indexFolder
- The index folder.
The example demonstrates how to add an index to the index repository.
String indexFolder = "c:\\MyIndex\\";
IndexRepository indexRepository = new IndexRepository();
indexRepository.addToRepository(indexFolder);
public final void update()
Updates all indexes in the repository.
The example demonstrates how to update indexes in the repository.
String indexFolder = "c:\\MyIndex\\";
String documentsFolder = "c:\\MyDocuments\\";
IndexRepository repository = new IndexRepository();
Index index = repository.create(indexFolder); // Creating index
index.add(documentsFolder); // Indexing documents
// Delete documents from the documents folder or modify them or add new documents to the folder
repository.update();
public final void update(UpdateOptions options)
Updates all indexes in the repository.
options
- The update options.
The example demonstrates how to update indexes in the repository.
String indexFolder = "c:\\MyIndex\\";
String documentsFolder = "c:\\MyDocuments\\";
IndexRepository repository = new IndexRepository();
Index index = repository.create(indexFolder); // Creating index
index.add(documentsFolder); // Indexing documents
// Delete documents from the documents folder or modify them or add new documents to the folder
UpdateOptions options = new UpdateOptions();
options.setThreads(2); // Setting the number of indexing threads
repository.update(options);
public final SearchResult search(String query)
Searches in all indexes of the repository.
query
- The search query.
The example demonstrates how to perform search in index repository.
String indexFolder = "c:\\MyIndex\\";
String documentsFolder = "c:\\MyDocuments\\";
String query = "Einstein";
IndexRepository repository = new IndexRepository();
Index index = repository.create(indexFolder); // Creating index
index.add(documentsFolder); // Indexing documents
SearchResult result = repository.search(query); // Searching
public final SearchResult search(String query, SearchOptions options)
Searches in all indexes of the repository.
query
- The search query.options
- The search options.
The example demonstrates how to perform search in index repository.
String indexFolder = "c:\\MyIndex\\";
String documentsFolder = "c:\\MyDocuments\\";
String query = "Einstein";
IndexRepository repository = new IndexRepository();
Index index = repository.create(indexFolder); // Creating index
index.add(documentsFolder); // Indexing documents
SearchOptions options = new SearchOptions();
options.setUseCaseSensitiveSearch(true); // Setting flag of case sensitive search
SearchResult result = repository.search(query, options); // Searching
public final SearchResult search(SearchQuery query)
Searches in all indexes of the repository.
query
- The search query.
The example demonstrates how to perform search in index repository.
String indexFolder = "c:\\MyIndex\\";
String documentsFolder = "c:\\MyDocuments\\";
IndexRepository repository = new IndexRepository();
Index index = repository.create(indexFolder); // Creating index
index.add(documentsFolder); // Indexing documents
SearchQuery query = SearchQuery.createWordQuery("Einstein"); // Creating search query in object form
SearchResult result = repository.search(query); // Searching
public final SearchResult search(SearchQuery query, SearchOptions options)
Searches in all indexes of the repository.
query
- The search query.options
- The search options.
The example demonstrates how to perform search in index repository.
String indexFolder = "c:\\MyIndex\\";
String documentsFolder = "c:\\MyDocuments\\";
IndexRepository repository = new IndexRepository();
Index index = repository.create(indexFolder); // Creating index
index.add(documentsFolder); // Indexing documents
SearchOptions options = new SearchOptions();
options.setUseCaseSensitiveSearch(true); // Setting flag of case sensitive search
SearchQuery query = SearchQuery.createWordQuery("Einstein"); // Creating search query in object form
SearchResult result = repository.search(query, options); // Searching