lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: Lucene updateDocument does not affect index until restarting solr
Date Wed, 15 Apr 2015 17:30:08 GMT

the short answer is that you need something to re-open the searcher -- but 
i'm not going to go into specifics on how to do that because...

You are dealing with a VERY low level layer of the lucene/solr code stack 
-- w/o more details on why you've written this particular bit of code (and 
where in the solr stack this code lives) it's hard to give you general 
advice on the best way to proceed and i don't wnat to encourage you along 
a dangerous path when there are likely much 
easier/better/safer/more-supported ways to do what you are trying to do -- 
you just need to explain to us what that is.

https://people.apache.org/~hossman/#xyproblem
XY Problem

Your question appears to be an "XY Problem" ... that is: you are dealing
with "X", you are assuming "Y" will help you, and you are asking about "Y"
without giving more details about the "X" so that we can understand the
full issue.  Perhaps the best solution doesn't involve "Y" at all?
See Also: http://www.perlmonks.org/index.pl?node_id=542341




: Date: Thu, 9 Apr 2015 01:02:16 +0430
: From: Ali Nazemian <alinazemian@gmail.com>
: Reply-To: solr-user@lucene.apache.org
: To: "solr-user@lucene.apache.org" <solr-user@lucene.apache.org>
: Subject: Lucene updateDocument does not affect index until restarting solr
: 
: Dear all,
: Hi,
: As a part of my code I have to update Lucene document. For this purpose I
: used writer.updateDocument() method. My problem is the update process is
: not affect index until restarting Solr. Would you please tell me what part
: of my code is wrong? Or what should I add in order to apply the changes?
: 
: RefCounted<IndexWriter> iw = solrCoreState.getIndexWriter(core);
:       try {
:         IndexWriter writer = iw.get();
:         FieldType type= new FieldType(StringField.TYPE_STORED);
:         for (int i = 0; i < 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);
:           for (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);
:         }
:         writer.commit();
:       } finally {
:         iw.decref();
:       }
: 
: 
: Best regards.
: 
: -- 
: A.Nazemian
: 

-Hoss
http://www.lucidworks.com/

Mime
View raw message