Hi,
I'm working on DSpace 3.2 XMLUI and now I'm trying to add "Related
Items" below simple view of an item. I have been searching in which
classes Solr implements this functionality, and I found this files:
-discovery.xml
-RelatedItems.java
-SolrServiceImpl.java
First I suspected that RelatedItems.java doesn't show the results, but I
tried to force to add one item to the query results and it's showed
well, so I discarted this option.
Then I checked if the parameters that discovery.xml contains are the
parameters that Solr are using when search related items, and are OK.
Finally, I checked this part of code in SolrServiceImpl:
public List<Item> getRelatedItems(Context context, Item item,
DiscoveryMoreLikeThisConfiguration mltConfig)
{
List<Item> results = new ArrayList<Item>();
int i=0;
try{
SolrQuery solrQuery = new SolrQuery();
//Set the query to handle since this is unique
solrQuery.setQuery("handle: " + item.getHandle());
//Add the more like this parameters !
solrQuery.setParam(MoreLikeThisParams.MLT, true);
//Add a comma separated list of the similar fields
@SuppressWarnings("unchecked")
java.util.Collection<String> similarityMetadataFields =
CollectionUtils.collect(mltConfig.getSimilarityMetadataFields(), new
Transformer()
{
@Override
public Object transform(Object input)
{
//Add the mlt appendix !
return input + "_mlt";
}
});
solrQuery.setParam(MoreLikeThisParams.SIMILARITY_FIELDS,
StringUtils.join(similarityMetadataFields, ','));
solrQuery.setParam(MoreLikeThisParams.MIN_TERM_FREQ,
String.valueOf(mltConfig.getMinTermFrequency()));
solrQuery.setParam(MoreLikeThisParams.DOC_COUNT,
String.valueOf(mltConfig.getMax()));
solrQuery.setParam(MoreLikeThisParams.MIN_WORD_LEN,
String.valueOf(mltConfig.getMinWordLength()));
QueryResponse rsp = getSolr().query(solrQuery);
NamedList mltResults = (NamedList)
rsp.getResponse().get("moreLikeThis");
if(mltResults != null && mltResults.get(item.getType() +
"-" + item.getID()) != null)
{
SolrDocumentList relatedDocs = (SolrDocumentList)
mltResults.get(item.getType() + "-" + item.getID());
for (Object relatedDoc : relatedDocs)
{
SolrDocument relatedDocument = (SolrDocument)
relatedDoc;
DSpaceObject relatedItem =
findDSpaceObject(context, relatedDocument);
if (relatedItem.getType() == Constants.ITEM)
{
results.add((Item) relatedItem);
}
}
}
} catch (Exception e)
{
log.error(LogManager.getHeader(context, "Error while
retrieving related items", "Handle: " + item.getHandle()), e);
}
return results;
}
I found "mltResults.get(item.getType() + "-" + item.getID())" empty (all
parameters of mltConfig are also checked). His content is:
{numFound=0,start=0,docs=[]}
Why Solr didn't found any related item?
My config in discovery.xml is:
</bean>
</property>
<property name="moreLikeThisConfiguration">
<bean
class="org.dspace.discovery.configuration.DiscoveryMoreLikeThisConfiguration">
<!--When altering this list also alter the
"xmlui.Discovery.RelatedItems.help" key as it describes
the metadata fields below-->
<property name="similarityMetadataFields">
<list>
<value>dc.title</value>
</list>
</property>
<!--The minimum number of matching terms across the
metadata fields above before an item is found as related -->
<property name="minTermFrequency" value="1"/>
<!--The maximum number of related items displayed-->
<property name="max" value="5"/>
<!--The minimum word length below which words will be
ignored-->
<property name="minWordLength" value="1"/>
</bean>
</property>
</bean>
If I have two items with the same dc.title, Solr must match this
occurrence, but it doesn't.
Thanks in advance,
Rubén Boada
------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos. Get
unparalleled scalability from the best Selenium testing platform available.
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech
List Etiquette: https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette