[ 
https://issues.apache.org/jira/browse/SOLR-5351?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13969610#comment-13969610
 ] 

Upayavira commented on SOLR-5351:
---------------------------------

These two snippets of code seem to work. I will recraft it as a patch soon. 
However, I wonder if there are more standard ways of rereading a Reader.

{code:java}
    private class ResettingReader extends Reader {
        Reader wrapped;
        public ResettingReader(Reader reader) {
                wrapped = reader;
        }
        public int read(char[]buf, int off, int len) throws IOException {
                return wrapped.read(buf, off, len);
        }
        public void close() throws IOException {
                wrapped.reset();
        }
        public void reallyClose() throws IOException {
                wrapped.close();
        }
    }
{code}
 
{code:java}
public DocListAndSet getMoreLikeThis( Reader reader, int start, int rows, 
List<Query> filters, List<InterestingTerm> terms, int flags ) throws IOException
    {
     if (mlt.getFieldNames().length==1) {
        rawMLTQuery = mlt.like(reader, mlt.getFieldNames()[0]);
      } else {
        BooleanQuery mltQuery = new BooleanQuery();
        ResettingReader reader2 = new ResettingReader(reader);
        for (String fieldName : mlt.getFieldNames()) {
          BooleanQuery singleFieldQuery = (BooleanQuery)mlt.like(reader2, 
fieldName);
          for (BooleanClause clause : singleFieldQuery.getClauses()) {
            mltQuery.add(clause);
          }
        }
        reader2.reallyClose();
        rawMLTQuery = mltQuery;
      }
      ...
{code}

> More Like This Handler uses only first field in mlt.fl when using stream.body
> -----------------------------------------------------------------------------
>
>                 Key: SOLR-5351
>                 URL: https://issues.apache.org/jira/browse/SOLR-5351
>             Project: Solr
>          Issue Type: Bug
>          Components: MoreLikeThis
>    Affects Versions: 4.4
>         Environment: Linux,Windows
>            Reporter: Zygmunt Wiercioch
>            Assignee: Tommaso Teofili
>            Priority: Minor
>
> The documentation at: http://wiki.apache.org/solr/MoreLikeThisHandler 
> indicates that one can use multiple fields for similarity in mlt.fl:
> http://localhost:8983/solr/mlt?stream.body=electronics%20memory&mlt.fl=manu,cat&mlt.interestingTerms=list&mlt.mintf=0
> In trying this, only one field is used. 
> Looking at the code, it only looks at the firs field:
>  public DocListAndSet getMoreLikeThis( Reader reader, int start, int rows, 
> List<Query> filters, List<InterestingTerm> terms, int flags ) throws 
> IOException
>     {
>       // analyzing with the first field: previous (stupid) behavior
>       rawMLTQuery = mlt.like(reader, mlt.getFieldNames()[0]); 



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to