java - Solr updating indexwriter does not affect search until the rebooting -
i did implement solr plugin purpose of updating fields on solr events (commit, optimize , etc.). problem updated documents not affect solr search until manually try restart solr. please take @ code , tell me part caused problem?
regards.
boolean success = false; namedlist response = new simpleorderedmap(); keyword.init(searcher, params); booleanquery query = new booleanquery(); (string fieldname : keywordsourcefields) { termquery termquery = new termquery(new term(fieldname, "noval")); query.add(termquery, occur.must_not); } termquery termquery = new termquery(new term(keywordfield, "noval")); query.add(termquery, occur.must); refcounted<indexwriter> iw = null; indexwriter writer = null; try { topdocs results = searcher.search(query, maxnumdocs); scoredoc[] hits = results.scoredocs; iw = solrcorestate.getindexwriter(core); writer = iw.get(); fieldtype type = new fieldtype(stringfield.type_stored); (int = 0; < hits.length; i++) { document document = searcher.doc(hits[i].doc); list<string> keywords = keyword.getkeywords(hits[i].doc); if (keywords.size() > 0) document.removefields(keywordfield); (string word : keywords) { document.add(new field(keywordfield, word, type)); } string uniquekey = searcher.getschema().getuniquekeyfield().getname(); writer.updatedocument(new term(uniquekey, document.get(uniquekey)), document); } response.add("number of selected docs", results.totalhits); writer.commit(); } catch (ioexception | syntaxerror e) { throw new runtimeexception(); } { if (iw != null) { iw.decref(); } }
Comments
Post a Comment