private void checkHits(SpatialArgs args, int assertNumFound, int[] assertIds)
 {
     SearchResults got = executeQuery(strategy.MakeQuery(args), 100);
     assertEquals("" + args, assertNumFound, got.numFound);
     if (assertIds != null)
     {
         ISet<int?> gotIds = new HashSet<int?>();
         foreach (SearchResult result in got.results)
         {
             gotIds.add(int.Parse(result.document.Get("id"), CultureInfo.InvariantCulture));
         }
         foreach (int assertId in assertIds)
         {
             assertTrue("has " + assertId, gotIds.contains(assertId));
         }
     }
 }
Example #2
0
        public virtual void _minimizeRuleSet( HashSet<string> ruleDefs, HashSet<string> ruleRefs, CompositeGrammarTree p )
        {
            var localRuleDefs = new HashSet<string>();
            foreach ( Rule r in p.grammar.Rules )
            {
                if ( !ruleDefs.contains( r.name ) )
                {
                    localRuleDefs.add( r.name );
                    ruleDefs.add( r.name );
                }
            }
            System.Console.Out.WriteLine( "rule defs for " + p.grammar.name + ": " + localRuleDefs );

            // remove locally-defined rules not in ref set
            // find intersection of local rules and references from delegator
            // that is set of rules needed by delegator
            HashSet<string> localRuleDefsSatisfyingRefsFromBelow = new HashSet<string>();
            foreach ( string r in ruleRefs )
            {
                if ( localRuleDefs.contains( r ) )
                {
                    localRuleDefsSatisfyingRefsFromBelow.add( r );
                }
            }

            // now get list of refs from localRuleDefsSatisfyingRefsFromBelow.
            // Those rules are also allowed in this delegate
            foreach ( GrammarAST refAST in p.grammar.ruleRefs )
            {
                if ( localRuleDefsSatisfyingRefsFromBelow.contains( refAST.enclosingRuleName ) )
                {
                    // found rule ref within needed rule
                }
            }

            // remove rule refs not in the new rule def set

            // walk all children, adding rules not already defined
            if ( p.children != null )
            {
                foreach ( CompositeGrammarTree @delegate in p.children )
                {
                    _minimizeRuleSet( ruleDefs, ruleRefs, @delegate );
                }
            }
        }
Example #3
0
        public virtual void runTestQuery(SpatialMatchConcern concern, SpatialTestQuery q)
        {
            String msg = q.toString(); //"Query: " + q.args.toString(ctx);
            SearchResults got = executeQuery(makeQuery(q), Math.Max(100, q.ids.size() + 1));
            if (storeShape && got.numFound > 0)
            {
                //check stored value is there
                assertNotNull(got.results[0].document.Get(strategy.FieldName));
            }
            if (concern.orderIsImportant)
            {
                IEnumerator<String> ids = q.ids.GetEnumerator();
                foreach (SearchResult r in got.results)
                {
                    String id = r.document.Get("id");
                    if (!ids.MoveNext())
                    {
                        fail(msg + " :: Did not get enough results.  Expect" + q.ids + ", got: " + got.toDebugString());
                    }
                    assertEquals("out of order: " + msg, ids.Current, id);
                }

                if (ids.MoveNext())
                {
                    fail(msg + " :: expect more results then we got: " + ids.Current);
                }
            }
            else
            {
                // We are looking at how the results overlap
                if (concern.resultsAreSuperset)
                {
                    ISet<string> found = new HashSet<string>();
                    foreach (SearchResult r in got.results)
                    {
                        found.add(r.document.Get("id"));
                    }
                    foreach (String s in q.ids)
                    {
                        if (!found.contains(s))
                        {
                            fail("Results are mising id: " + s + " :: " + found);
                        }
                    }
                }
                else
                {
                    List<string> found = new List<string>();
                    foreach (SearchResult r in got.results)
                    {
                        found.Add(r.document.Get("id"));
                    }

                    // sort both so that the order is not important
                    CollectionUtil.TimSort(q.ids);
                    CollectionUtil.TimSort(found);
                    assertEquals(msg, q.ids.toString(), found.toString());
                }
            }
        }