r 8289 change for index update

This commit is contained in:
anupsawant 2011-06-27 21:44:25 +00:00
parent e41f90a653
commit 5136b7c095

View file

@ -7,14 +7,19 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.response.*;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.search.IndexingException;
import edu.cornell.mannlib.vitro.webapp.search.docbuilder.Obj2DocIface;
@ -53,13 +58,10 @@ public class SolrIndexer implements IndexerIface {
urisIndexed.add(ind.getURI());
}
log.debug("indexing " + ind.getURI());
// synchronized(individualToSolrDoc){
solrDoc = individualToSolrDoc.translate(ind);
// }
if( solrDoc != null){
//sending each doc individually is inefficient
// Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
// docs.add( solrDoc );
UpdateResponse res = server.add( solrDoc );
log.debug("response after adding docs to server: "+ res);
}else{
@ -95,7 +97,7 @@ public class SolrIndexer implements IndexerIface {
@Override
public synchronized void startIndexing() throws IndexingException {
while( indexing ){ //wait for indexing to end.
log.debug("LuceneIndexer.startIndexing() waiting...");
log.debug("SolrIndexer.startIndexing() waiting...");
try{ wait(); } catch(InterruptedException ex){}
}
@ -149,8 +151,24 @@ public class SolrIndexer implements IndexerIface {
@Override
public long getModified() {
// TODO Auto-generated method stub
return 0;
long modified = 0;
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.addSortField("indexedTime", SolrQuery.ORDER.desc);
try {
QueryResponse rsp = server.query(query);
SolrDocumentList docs = rsp.getResults();
if(docs!=null){
modified = (Long)docs.get(0).getFieldValue("indexedTime");
}
} catch (SolrServerException e) {
// TODO Auto-generated catch block
log.error(e,e);
}
return modified;
}
public boolean isIndexEmpty() {