{"record":{"id":"480df0722fba0550","repo":"languagetool-org/languagetool","slug":"no-ngramsize-grams-directory-found-in-topindex","errorCode":null,"errorMessage":"No ${ngramSize}grams directory found in ${topIndexDir}","messagePattern":"No (.+?)grams directory found in (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/languagemodel/LuceneSingleIndexLanguageModel.java","lineNumber":173,"sourceCode":"        for (ScoreDoc scoreDoc : docs.scoreDocs) {\n          long tmp = Long.parseLong(luceneSearcher.reader.document(scoreDoc.doc).get(\"totalTokenCount\"));\n          if (tmp > result) {\n            // due to the way FrequencyIndexCreator adds these totalTokenCount fields, we must not sum them,\n            // but take the largest one:\n            result = tmp;\n          }\n        }\n        return result;\n      }\n    } catch (IOException e) {\n      throw new RuntimeException(e);\n    }\n  }\n\n  protected LuceneSearcher getLuceneSearcher(int ngramSize) {\n    LuceneSearcher luceneSearcher = luceneSearcherMap.get(ngramSize);\n    if (luceneSearcher == null) {\n      throw new RuntimeException(\"No \" + ngramSize + \"grams directory found in \" + topIndexDir);\n    }\n    return luceneSearcher;\n  }\n\n  private LuceneSearcher getCachedLuceneSearcher(File indexDir) {\n    LuceneSearcher luceneSearcher = dirToSearcherMap.get(indexDir);\n    if (luceneSearcher == null) {\n      try {\n        LuceneSearcher newSearcher = new LuceneSearcher(indexDir);\n        dirToSearcherMap.put(indexDir, newSearcher);\n        return newSearcher;\n      } catch (IOException e) {\n        throw new RuntimeException(e);\n      }\n    } else {\n      return luceneSearcher;\n    }\n  }","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/languagemodel/LuceneSingleIndexLanguageModel.java#L155-L191","documentation":"getLuceneSearcher(ngramSize) looks up a pre-loaded LuceneSearcher for the requested ngram size in luceneSearcherMap. If no searcher was registered for that size (because no '<n>grams' directory exists under the top index directory), it throws. This typically means the index layout on disk does not match what the model was configured to load.","triggerScenarios":"Calling getCount() (or anything resolving a searcher) with an ngram size whose '<n>grams' directory was not found or not registered when the model scanned topIndexDir; e.g. requesting trigram lookups when only 1grams/2grams directories exist.","commonSituations":"Downloading an index that ships only 1grams/2grams but running rules that need 3grams; mistyping/misplacing directories so names don't match the expected '<n>grams' pattern; incomplete archive extraction.","solutions":["Download/use the full ngram index for the language that includes all needed '<n>grams' directories (1grams, 2grams, 3grams).","Verify the top index directory contains subdirectories literally named '<n>grams' (e.g. '3grams', not '3-grams' or 'trigrams').","Check extraction of the index archive completed (no truncated/missing subdirectories).","Match the index release to your LanguageTool version; older indexes may have different layouts."],"exampleFix":"// before: only 1grams/2grams present\n$ ls /data/ngrams/en -> 1grams 2grams\n// after: fetch full index\n$ ls /data/ngrams/en -> 1grams 2grams 3grams","handlingStrategy":"validation","validationCode":"for (int n : new int[]{1,2,3}) {\n  File d = new File(topIndexDir, n + \"grams\");\n  if (!d.isDirectory()) throw new IllegalStateException(\"Missing \" + d);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check '<n>grams' subdirectories exist before constructing the model","Fully extract the index archive before use","Match index release to LanguageTool version"],"tags":["lucene","ngram-index","missing-directory"],"backgroundTag":"file-not-found","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}