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
```
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);
```
Creates a new index on disk.
The index folder will be cleaned before the index creation.
Parameters:
Parameter
Type
Description
indexFolder
java.lang.String
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);
```
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);
```
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();
```
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);
```
|
search(String query)
public final SearchResult search(String query)
Searches in all indexes of the repository.
Parameters:
Parameter
Type
Description
query
java.lang.String
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
```