Skip to content

SOLR-117 : Add the update function to update the existing indexes #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ private static void writeNoCommit( SolrItem solrItem, StringBuffer sbLogs ) thro
}
}

private static void updateNoCommit (SolrItem solrItem, StringBuffer sbLogs )
{
try
{
sbLogs.append( "Indexing " );
sbLogs.append( solrItem.getType( ) );
sbLogs.append( " #" );
sbLogs.append( solrItem.getUid( ) );
sbLogs.append( " - " );
sbLogs.append( solrItem.getTitle( ) );
SolrInputDocument solrInputDocument = solrItem2SolrInputDocumentUpdate( solrItem );
SOLR_SERVER.add( solrInputDocument );
sbLogs.append( "\r\n" );
}
catch (Exception e)
{
printIndexMessage( e, sbLogs );
}
}

/**
* Index one document, called by plugin indexers
* @param solrItem The item
Expand All @@ -132,6 +152,11 @@ public static void write( SolrItem solrItem ) throws CorruptIndexException, IOEx
write( solrItem, _sbLogs );
}

public static void update( SolrItem solrItem ) throws CorruptIndexException, IOException
{
update( solrItem, _sbLogs );
}

/**
* Index one document, called by external code
* @param solrItem The item
Expand All @@ -152,6 +177,19 @@ public static void write( SolrItem solrItem, StringBuffer sbLogs ) throws Corrup
}
}

public static void update( SolrItem solrItem, StringBuffer sbLogs ) throws CorruptIndexException, IOException
{
try
{
updateNoCommit( solrItem, sbLogs );
SOLR_SERVER.commit( );
}
catch ( Exception e )
{
printIndexMessage( e, sbLogs );
}
}

/**
* Index a collection of documents, called by plugin indexers
* @param solrItems The item
Expand All @@ -163,6 +201,11 @@ public static void write( Collection<SolrItem> solrItems ) throws CorruptIndexEx
write( solrItems, _sbLogs );
}

public static void update( Collection<SolrItem> solrItems ) throws CorruptIndexException, IOException
{
update( solrItems, _sbLogs );
}

/**
* Index a collection of documents, called by external code
* @param solrItems The item
Expand All @@ -185,6 +228,20 @@ public static void write( Collection<SolrItem> solrItems, StringBuffer sbLogs )
}
}

public static void update(Collection<SolrItem> solrItems, StringBuffer sbLogs )
{
try {
for ( SolrItem solrItem: solrItems ) {
updateNoCommit( solrItem, sbLogs );
}
SOLR_SERVER.commit( );
}
catch (Exception e)
{
printIndexMessage(e, sbLogs);
}
}

/**
* Process the indexing
* @param bCreate tell if it's total indexing or total (total = true)
Expand Down Expand Up @@ -500,6 +557,25 @@ private static SolrInputDocument solrItem2SolrInputDocument( SolrItem solrItem )
return solrInputDocument;
}

private static SolrInputDocument solrItem2SolrInputDocumentUpdate (SolrItem solrItem) {
SolrInputDocument solrInputDocument = new SolrInputDocument( );
String strWebappName = getWebAppName( );

solrInputDocument.addField( SearchItem.FIELD_UID,
strWebappName + SolrConstants.CONSTANT_UNDERSCORE + solrItem.getUid( ) );

Map<String, Object> mapDynamicFields = solrItem.getDynamicFields( );

for ( String strDynamicField : mapDynamicFields.keySet( ) )
{
Map<String, Object> map = new HashMap<>();
map.put("set", mapDynamicFields.get( strDynamicField ));
solrInputDocument.addField(strDynamicField, map);
}

return solrInputDocument;
}

/**
* Initialize the indexers List.
* @return the indexers List
Expand Down
1 change: 1 addition & 0 deletions webapp/WEB-INF/plugins/solr/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<field name="hiedate" type="string" indexed="true" stored="true"/>
<field name="metadata" type="string" indexed="true" stored="true"/>
<field name="document_portlet_id" type="string" indexed="true" stored="true"/>
<field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
<dynamicField name="*_string" type="string" indexed="true" stored="true"/>
<dynamicField name="*_text" type="text" indexed="true" stored="true"/>
<dynamicField name="*_date" type="date" indexed="true" stored="true"/>
Expand Down
6 changes: 6 additions & 0 deletions webapp/WEB-INF/plugins/solr/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
<str name="queryAnalyzerFieldType">text</str>
</searchComponent>

<updateHandler class="solr.DirectUpdateHandler2">
<updateLog>
<str name="dir">${solr.ulog.dir:}</str>
</updateLog>
</updateHandler>

<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
<lst name="defaults">
<str name="spellcheck">true</str>
Expand Down