You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by GitBox <gi...@apache.org> on 2021/11/04 16:06:01 UTC

[GitHub] [lucenenet] NightOwl888 commented on issue #431: Query/Filter Casting

NightOwl888 commented on issue #431:
URL: https://github.com/apache/lucenenet/issues/431#issuecomment-961188824


   I confess I was using the tests as an indicator of what a user might do, which may be an invalid assumption to make.
   
   ### MoreLikeThis.Like()
   
   I was specifically looking at the test here, but I can see that a user may not care about looking at the individual clauses under normal usage.
   
   ```c#
               BooleanQuery query = (BooleanQuery)mlt.Like(new StringReader("lucene release"), "text");
               IList<BooleanClause> clauses = query.Clauses;
   
               assertEquals("Expected " + originalValues.Count + " clauses.", originalValues.Count, clauses.Count);
   
               foreach (BooleanClause clause in clauses)
               {
                   TermQuery tq = (TermQuery)clause.Query;
                   float? termBoost = originalValues[tq.Term.Text];
                   assertNotNull("Expected term " + tq.Term.Text, termBoost);
   
                   float totalBoost = (float) (termBoost * boostFactor);
                   assertEquals("Expected boost of " + totalBoost + " for term '"
                       + tq.Term.Text + "' got " + tq.Boost, totalBoost, tq.Boost, 0.0001);
               }
   ```
   
   ### Query.Rewrite() AND IndexSearcher.Rewrite()
   
   This appears to be the same type of situation. The cast was only used so the test could check `SpanQuery.ExtractTerms()`. Most of the tests don't have any casting, and are probably more representative of what a user will do.
   
   ```c#
           [Test]
           public virtual void TestRewrite0()
           {
               SpanQuery q = new FieldMaskingSpanQuery(new SpanTermQuery(new Term("last", "sally")), "first");
               q.Boost = 8.7654321f;
               SpanQuery qr = (SpanQuery)searcher.Rewrite(q);
   
               QueryUtils.CheckEqual(q, qr);
   
               ISet<Term> terms = new JCG.HashSet<Term>();
               qr.ExtractTerms(terms);
               Assert.AreEqual(1, terms.Count);
           }
   ```
   
   ### Filter.GetDocIdSet()
   
   This also seems to be similar. Although it is a bit more difficult with this one, as this might be something a consumer actually does. That being said, casting is not required in over 90% of cases it is used.
   
   ```c#
           private Document GetParentDoc(IndexReader reader, Filter parents, int childDocID)
           {
               IList<AtomicReaderContext> leaves = reader.Leaves;
               int subIndex = ReaderUtil.SubIndex(childDocID, leaves);
               AtomicReaderContext leaf = leaves[subIndex];
               FixedBitSet bits = (FixedBitSet)parents.GetDocIdSet(leaf, null);
               return leaf.AtomicReader.Document(bits.NextSetBit(childDocID - leaf.DocBase));
           }
   ```
   
   So, I have to concur this is probably not worth the effort.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org