Ejemplo n.º 1
0
 public AnonymousSimilarityDelegator(FuzzyTermQuery parent, Similarity result) : base(result)
 {
     this.parent = parent;
 }
Ejemplo n.º 2
0
        public override Query Rewrite(IndexReader reader)
        {
            if (rewrittenQuery != null)
            {
                return(rewrittenQuery);
            }
            //load up the list of possible terms
            foreach (FieldVals f in fieldVals)
            {
                AddTerms(reader, f);
            }
            //for (Iterator iter = fieldVals.iterator(); iter.hasNext(); )
            //{
            //    FieldVals f = (FieldVals)iter.next();
            //    addTerms(reader, f);
            //}
            //clear the list of fields
            fieldVals.Clear();

            BooleanQuery bq = new BooleanQuery();


            //create BooleanQueries to hold the variants for each token/field pair and ensure it
            // has no coord factor
            //Step 1: sort the termqueries by term/field
            Hashtable variantQueries = new Hashtable();
            int       size           = q.Size();

            for (int i = 0; i < size; i++)
            {
                ScoreTerm st = (ScoreTerm)q.Pop();
                ArrayList l  = (ArrayList)variantQueries[st.fuzziedSourceTerm];
                if (l == null)
                {
                    l = new ArrayList();
                    variantQueries.Add(st.fuzziedSourceTerm, l);
                }
                l.Add(st);
            }
            //Step 2: Organize the sorted termqueries into zero-coord scoring boolean queries
            foreach (ArrayList variants in variantQueries.Values)
            //for (Iterator iter = variantQueries.values().iterator(); iter.hasNext(); )
            {
                //ArrayList variants = (ArrayList)iter.next();
                if (variants.Count == 1)
                {
                    //optimize where only one selected variant
                    ScoreTerm st = (ScoreTerm)variants[0];
                    TermQuery tq = new FuzzyTermQuery(st.term, ignoreTF);
                    tq.SetBoost(st.score); // set the boost to a mix of IDF and score
                    bq.Add(tq, BooleanClause.Occur.SHOULD);
                }
                else
                {
                    BooleanQuery termVariants = new BooleanQuery(true); //disable coord and IDF for these term variants
                    foreach (ScoreTerm st in variants)
                    //for (Iterator iterator2 = variants.iterator(); iterator2.hasNext(); )
                    {
                        //ScoreTerm st = (ScoreTerm)iterator2.next();
                        TermQuery tq = new FuzzyTermQuery(st.term, ignoreTF); // found a match
                        tq.SetBoost(st.score);                                // set the boost using the ScoreTerm's score
                        termVariants.Add(tq, BooleanClause.Occur.SHOULD);     // add to query
                    }
                    bq.Add(termVariants, BooleanClause.Occur.SHOULD);         // add to query
                }
            }
            //TODO possible alternative step 3 - organize above booleans into a new layer of field-based
            // booleans with a minimum-should-match of NumFields-1?
            bq.SetBoost(GetBoost());
            this.rewrittenQuery = bq;
            return(bq);
        }