In solr we can create a field which can update as the related doc is searched by user.
For that we need to add a field in schema.xml as:
<field name="popularity" type="long" indexed="true" stored="true"/>
In the below code we have used a map which takes the incremented value with the option(inc - incremental), this will always increment the field by the defined value, in this case by a value of 1.
SolrInputDocument doc = new SolrInputDocument();
Map<String, Object> partialUpdate = new HashMap<String, Object>();
partialUpdate.put("inc", new Integer(1));// keep increasing the value by 1
doc.addField("id", id);
doc.addField("popularity", partialUpdate);
server.add(doc);
server.commit();
0 Comment(s)