Hello all, in our last project we use solr as search engine to search for assets. we have a functionality to search for product in it's summary text, the product itself is "container for a set of products parent" so each time we add new product under it , the summary of the "parent product" should be updated to add the new text.so in this case each time we add new child product, the parent product summary text should be updated,some times the added summary text list is empty sometimes not, but in case of empty list the document all field are delted except version and id. to avoid this problem we ignore the update behavior in case of empty list.*A. in case of update with empty list:* 1.added document is : 121112 hehe go go goooooooooooooooooooooooooooooool ollay hehe doc1 1455476967916699648 2. after update 121112 1455476967916699659 *B. in case of not empty list in update request:* 1. same as in a.1. 2. 121112 hehe go go goooooooooooooooooooooooooooooool ollay hehe go go 12312312312312312 123123123 ollay 1232131231231231313 doc1 1455476967916699648 i use solrj and solr4.4.0.my schema document : my java code to test this senario is as follow://TestingSolrUpdateDoc.javapackage org.solr.test;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.common.SolrInputDocument;public class TestingSolrUpdateDoc { public static void main(String[] args) { try { addDoc(121112, false); } catch (SolrServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void addDoc(long id, boolean emptyListUpdate) throws SolrServerException, IOException { SolrInputDocument solrInputDocument = new SolrInputDocument(); solrInputDocument.setField("id", new Long(id)); solrInputDocument.setField("text", generateRandomTextList()); solrInputDocument.setField("name", "doc1"); SolrConnection connection = SolrConnection.getConnection(); connection.addDocument(solrInputDocument); if (emptyListUpdate) { solrInputDocument = new SolrInputDocument(); solrInputDocument.setField("id", new Long(id)); Map<String, Object> update = new HashMap<String, Object>(); update.put("add", new ArrayList()); solrInputDocument.addField("text", update); connection.updateDocument(solrInputDocument); } else { solrInputDocument = new SolrInputDocument(); solrInputDocument.setField("id", new Long(id)); Map<String, Object> update = new HashMap<String, Object>(); update.put("add", generateRandomUpdateTextList()); solrInputDocument.addField("text", update); connection.updateDocument(solrInputDocument); } } private static List generateRandomTextList() { List texts = new ArrayList(); texts.add("hehe"); texts.add("go go "); texts.add("goooooooooooooooooooooooooooooool"); texts.add("ollay"); return texts; } private static List generateRandomUpdateTextList() { List texts = new ArrayList(); texts.add("hehe"); texts.add("go go "); texts.add("12312312312312312 123123123"); texts.add("ollay 1232131231231231313"); return texts; }}//SolrConnection .javapackage org.solr.test;import java.io.IOException;import org.apache.solr.client.solrj.SolrServer;import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.HttpSolrServer;import org.apache.solr.common.SolrInputDocument;public class SolrConnection { private SolrServer solrServer = new HttpSolrServer("http://localhost:8983/solr/test"); private static SolrConnection solrConnection = new SolrConnection(); private SolrConnection() { } public static SolrConnection getConnection() { if (solrConnection != null) { return solrConnection; } synchronized (SolrConnection.class) { if (solrConnection != null) { return solrConnection; } solrConnection = new SolrConnection(); return solrConnection; } } public void addDocument(SolrInputDocument doc) throws SolrServerException, IOException { solrServer.add(doc); solrServer.commit(); } public void updateDocument(SolrInputDocument doc) throws SolrServerException, IOException { solrServer.add(doc); solrServer.commit(); }}Best Thanks,Mohammad yaseen
-- View this message in context: http://lucene.472066.n3.nabble.com/Solr-update-document-issue-tp4108214.html Sent from the Solr - User mailing list archive at Nabble.com.