Exception in thread “main” class com.groupdocs.search.internal.c.a.ms.System.V: Incorrect index version. Please use IndexUpdater class to update index version.
import com.groupdocs.search.Index;
import com.groupdocs.search.licenses.License;
import com.groupdocs.search.results.SearchResult;
public class SearchResults {
public static void main(String[] args) throws Exception {
// Apply the license to remove the restrictions
// imposed by the Search library
License license = new License();
license.setLicense("GroupDocs.Search.lic");
// The path where the index will be stored
String indexFolder = "c:\\MyIndex\\";
// The folder containing the documents you want to search
String documentsFolder = "c:\\MyDocuments\\";
// The word or phrase you want to search for within the documents
String searchTerm = "Lorem";
// Creating index in the specified folder
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
index.add(documentsFolder);
// Searches for the specific word within the indexed documents
SearchResult result = index.search(searchTerm);
System.out.println("Documents: " + result.getDocumentCount());
System.out.println("Occurrences: " + result.getOccurrenceCount());
}
}
@tahir.manzoor
The error message you are encountering, “Incorrect index version. Please use IndexUpdater class to update index version,” indicates that the index you are trying to use is not compatible with the current version of the GroupDocs.Search library you are using. This typically happens when the index format has changed between versions of the library.
To resolve this issue, you need to update the index using the IndexUpdater
class. Here’s how you can do that in your Java code:
- Create an instance of
IndexUpdater
.
- Check if the index can be updated using the
CanUpdateVersion
method.
- If it can be updated, call the
UpdateVersion
method to create a new index in the updated format.
Here’s an example of how you can implement this:
import com.groupdocs.search.Index;
import com.groupdocs.search.IndexUpdater;
import com.groupdocs.search.results.SearchResult;
public class UpdateIndexExample {
public static void main(String[] args) throws Exception {
String oldIndexFolder = "c:\\MyOldIndex\\";
String newIndexFolder = "c:\\MyNewIndex\\";
// Create an instance of IndexUpdater
IndexUpdater updater = new IndexUpdater();
// Check if the old index can be updated
if (updater.canUpdateVersion(oldIndexFolder)) {
// Update the index version
updater.updateVersion(oldIndexFolder, newIndexFolder);
System.out.println("Index updated successfully.");
} else {
System.out.println("The index cannot be updated.");
}
// Now you can create a new Index instance with the updated index
Index index = new Index(newIndexFolder);
// Proceed with your indexing and searching as before
}
}
Make sure to replace the paths with your actual index folder paths. After updating the index, you should be able to perform searches without encountering the version error.
For more detailed information on updating the index, you can refer to the official documentation on updating indexed documents and versions.
If you continue to experience issues, consider checking for any updates or patches for the GroupDocs.Search library that may address this problem.
Sources:
[1]: Update index - Documentation
@Professionalize.Discourse
Thank you for the reply; however, I’m still encountering the issue. I think, there’s no need to use IndexUpdater. If you simply run the following code example, the exception will be thrown.
error.png (112.6 KB)
// Creating index in the specified folder
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
index.add(documentsFolder);
The second issue is, the setLicense method prints path of license. please check the attached image.
@tahir.manzoor
We are investigating this issue. Your investigation ticket ID is SEARCHJAVA-329.
We couldn’t reproduce this issue at our end. Please take a look at this screenshot (32.5 KB).