private LuceneSearcher(LanguageSet languages, File root, LuceneOptions options) { try { System.err.println("LOADING LANGUAGES " + languages); this.root = root; this.searchers = new HashMap<Language, IndexSearcher>(); this.readers = new HashMap<Language, DirectoryReader>(); this.analyzers = new HashMap<Language, WikiBrainAnalyzer>(); for (Language language : languages) { File langRoot = new File(root, language.getLangCode()); if (!langRoot.isDirectory()) { throw new IllegalArgumentException("no index at location: " + langRoot); } Directory directory = FSDirectory.open(langRoot); DirectoryReader reader = DirectoryReader.open(directory); readers.put(language, reader); searchers.put(language, new IndexSearcher(reader)); analyzers.put(language, new WikiBrainAnalyzer(language, options)); } this.options = options; } catch (IOException e) { throw new RuntimeException(e); } }
private LuceneIndexer(Language language, File root, LuceneOptions... options) throws ConfigurationException { try { this.root = root; this.language = language; this.options = options; this.mainOptions = options[0]; this.builder = new TextFieldBuilder( mainOptions.configurator.get(LocalPageDao.class), mainOptions.configurator.get(RawPageDao.class), mainOptions.configurator.get(RedirectDao.class)); File langRoot = new File(root, language.getLangCode()); if (langRoot.exists()) { FileUtils.deleteQuietly(langRoot); } WikiBrainAnalyzer analyzer = new WikiBrainAnalyzer(language, mainOptions); Directory directory = FSDirectory.open(langRoot); IndexWriterConfig iwc = new IndexWriterConfig(mainOptions.matchVersion, analyzer); writer = new IndexWriter(directory, iwc); } catch (IOException e) { throw new RuntimeException(e); } }