override public void  Run()
        {
            try
            {
                docs = (sort == null)?searchable.Search(weight, filter, nDocs):searchable.Search(weight, filter, nDocs, sort);
            }
            // Store the IOException for later use by the caller of this thread
            catch (System.IO.IOException ioe)
            {
                this.ioe = ioe;
            }
            if (this.ioe == null)
            {
                // if we are sorting by fields, we need to tell the field sorted hit queue
                // the actual type of fields, in case the original list contained AUTO.
                // if the searchable returns null for fields, we'll have problems.
                if (sort != null)
                {
                    TopFieldDocs docsFields = (TopFieldDocs)docs;
                    // If one of the Sort fields is FIELD_DOC, need to fix its values, so that
                    // it will break ties by doc Id properly. Otherwise, it will compare to
                    // 'relative' doc Ids, that belong to two different searchables.
                    for (int j = 0; j < docsFields.fields.Length; j++)
                    {
                        if (docsFields.fields[j].GetType() == SortField.DOC)
                        {
                            // iterate over the score docs and change their fields value
                            for (int j2 = 0; j2 < docs.scoreDocs.Length; j2++)
                            {
                                FieldDoc fd = (FieldDoc)docs.scoreDocs[j2];
                                fd.fields[j] = (System.Int32)(((System.Int32)fd.fields[j]) + starts[i]);
                            }
                            break;
                        }
                    }

                    ((FieldDocSortedHitQueue)hq).SetFields(docsFields.fields);
                }
                ScoreDoc[] scoreDocs = docs.scoreDocs;
                for (int j = 0; j < scoreDocs.Length; j++)
                {
                    // merge scoreDocs into hq
                    ScoreDoc scoreDoc = scoreDocs[j];
                    scoreDoc.doc += starts[i];                     // convert doc
                    //it would be so nice if we had a thread-safe insert
                    lock (hq)
                    {
                        if (!hq.Insert(scoreDoc))
                        {
                            break;
                        }
                    }                     // no more scores > minScore
                }
            }
        }
예제 #2
0
 // javadoc inherited
 public override void  Collect(int doc, float score)
 {
     if (score > 0.0f)
     {
         totalHits++;
         if (hq.Size() < numHits || score >= minScore)
         {
             hq.Insert(new ScoreDoc(doc, score));
             minScore = ((ScoreDoc)hq.Top()).score;  // maintain minScore
         }
     }
 }
 override public void  Run()
 {
     try
     {
         docs = (sort == null) ? searchable.Search(weight, filter, nDocs) : searchable.Search(weight, filter, nDocs, sort);
     }
     // Store the IOException for later use by the caller of this thread
     catch (System.IO.IOException ioe)
     {
         this.ioe = ioe;
     }
     if (this.ioe == null)
     {
         // if we are sorting by fields, we need to tell the field sorted hit queue
         // the actual type of fields, in case the original list contained AUTO.
         // if the searchable returns null for fields, we'll have problems.
         if (sort != null)
         {
             ((FieldDocSortedHitQueue)hq).SetFields(((TopFieldDocs)docs).fields);
         }
         ScoreDoc[] scoreDocs = docs.scoreDocs;
         for (int j = 0; j < scoreDocs.Length; j++)
         {
             // merge scoreDocs into hq
             ScoreDoc scoreDoc = scoreDocs[j];
             scoreDoc.doc += starts[i];                     // convert doc
             //it would be so nice if we had a thread-safe insert
             lock (hq)
             {
                 if (!hq.Insert(scoreDoc))
                 {
                     break;
                 }
             }                     // no more scores > minScore
         }
     }
 }