Parse() public method

Parses the query text and returns parsed query (or null if empty)
public Parse ( string queryText ) : Query
queryText string
return Lucene.Net.Search.Query
Exemplo n.º 1
0
        public virtual void TestWeightedOR()
        {
            IDictionary <string, float> weights = new LinkedHashMap <string, float>();

            weights["field0"] = 5f;
            weights["field1"] = 10f;

            BooleanQuery expected = new BooleanQuery();
            BooleanQuery foo      = new BooleanQuery(true);
            Query        field0   = new TermQuery(new Term("field0", "foo"));

            field0.Boost = (5f);
            foo.Add(field0, Occur.SHOULD);
            Query field1 = new TermQuery(new Term("field1", "foo"));

            field1.Boost = (10f);
            foo.Add(field1, Occur.SHOULD);
            expected.Add(foo, Occur.SHOULD);

            BooleanQuery bar = new BooleanQuery(true);

            field0       = new TermQuery(new Term("field0", "bar"));
            field0.Boost = (5f);
            bar.Add(field0, Occur.SHOULD);
            field1       = new TermQuery(new Term("field1", "bar"));
            field1.Boost = (10f);
            bar.Add(field1, Occur.SHOULD);
            expected.Add(bar, Occur.SHOULD);

            Analyzer          analyzer = new MockAnalyzer(Random);
            SimpleQueryParser parser   = new SimpleQueryParser(analyzer, weights);

            assertEquals(expected, parser.Parse("foo|bar"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// helper to parse a query with whitespace+lowercase analyzer across "field",
        /// with default operator of MUST
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        private Query Parse(string text)
        {
            Analyzer          analyzer = new MockAnalyzer(Random);
            SimpleQueryParser parser   = new SimpleQueryParser(analyzer, "field");

            parser.DefaultOperator = Occur.MUST;
            return(parser.Parse(text));
        }
Exemplo n.º 3
0
        /// <summary>
        /// helper to parse a query with whitespace+lowercase analyzer across "field",
        /// with default operator of MUST
        /// </summary>
        /// <param name="text"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        private Query Parse(string text, Operator flags)
        {
            Analyzer          analyzer = new MockAnalyzer(Random);
            SimpleQueryParser parser   = new SimpleQueryParser(analyzer, new HashMap <string, float>()
            {
                { "field", 1f }
            }, flags);

            parser.DefaultOperator = Occur.MUST;
            return(parser.Parse(text));
        }
Exemplo n.º 4
0
        public virtual void TestORImplicit()
        {
            BooleanQuery expected = new BooleanQuery();

            expected.Add(new TermQuery(new Term("field", "foo")), Occur.SHOULD);
            expected.Add(new TermQuery(new Term("field", "bar")), Occur.SHOULD);

            SimpleQueryParser parser = new SimpleQueryParser(new MockAnalyzer(Random), "field");

            assertEquals(expected, parser.Parse("foo bar"));
        }
Exemplo n.º 5
0
        /** helper to parse a query with keyword analyzer across "field" */
        private Query ParseKeyword(string text, Operator flags)
        {
            Analyzer          analyzer = new MockAnalyzer(Random, MockTokenizer.KEYWORD, false);
            SimpleQueryParser parser   = new SimpleQueryParser(analyzer,
                                                               new HashMap <string, float>()
            {
                { "field", 1f }
            },
                                                               flags);

            return(parser.Parse(text));
        }
Exemplo n.º 6
0
        public virtual void TestWeightedTerm()
        {
            IDictionary <string, float> weights = new Dictionary <string, float>();

            weights["field0"] = 5f;
            weights["field1"] = 10f;

            BooleanQuery expected = new BooleanQuery(true);
            Query        field0   = new TermQuery(new Term("field0", "foo"));

            field0.Boost = (5f);
            expected.Add(field0, BooleanClause.Occur.SHOULD);
            Query field1 = new TermQuery(new Term("field1", "foo"));

            field1.Boost = (10f);
            expected.Add(field1, BooleanClause.Occur.SHOULD);

            Analyzer          analyzer = new MockAnalyzer(Random());
            SimpleQueryParser parser   = new SimpleQueryParser(analyzer, weights);

            assertEquals(expected, parser.Parse("foo"));
        }
 /** helper to parse a query with keyword analyzer across "field" */
 private Query ParseKeyword(string text, int flags)
 {
     Analyzer analyzer = new MockAnalyzer(Random(), MockTokenizer.KEYWORD, false);
     SimpleQueryParser parser = new SimpleQueryParser(analyzer,
         new HashMap<string, float>() { { "field", 1f } },
         flags);
     return parser.Parse(text);
 }
 /// <summary>
 /// helper to parse a query with whitespace+lowercase analyzer across "field",
 /// with default operator of MUST
 /// </summary>
 /// <param name="text"></param>
 /// <param name="flags"></param>
 /// <returns></returns>
 private Query Parse(string text, int flags)
 {
     Analyzer analyzer = new MockAnalyzer(Random());
     SimpleQueryParser parser = new SimpleQueryParser(analyzer, new HashMap<string, float>() { { "field", 1f } }, flags);
     parser.DefaultOperator = BooleanClause.Occur.MUST;
     return parser.Parse(text);
 }
 /// <summary>
 /// helper to parse a query with whitespace+lowercase analyzer across "field",
 /// with default operator of MUST
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 private Query Parse(string text)
 {
     Analyzer analyzer = new MockAnalyzer(Random());
     SimpleQueryParser parser = new SimpleQueryParser(analyzer, "field");
     parser.DefaultOperator = BooleanClause.Occur.MUST;
     return parser.Parse(text);
 }
        public virtual void TestWeightedTerm()
        {
            IDictionary<string, float> weights = new Dictionary<string, float>();
            weights["field0"] = 5f;
            weights["field1"] = 10f;

            BooleanQuery expected = new BooleanQuery(true);
            Query field0 = new TermQuery(new Term("field0", "foo"));
            field0.Boost = (5f);
            expected.Add(field0, BooleanClause.Occur.SHOULD);
            Query field1 = new TermQuery(new Term("field1", "foo"));
            field1.Boost = (10f);
            expected.Add(field1, BooleanClause.Occur.SHOULD);

            Analyzer analyzer = new MockAnalyzer(Random());
            SimpleQueryParser parser = new SimpleQueryParser(analyzer, weights);
            assertEquals(expected, parser.Parse("foo"));
        }
        public virtual void TestORImplicit()
        {
            BooleanQuery expected = new BooleanQuery();
            expected.Add(new TermQuery(new Term("field", "foo")), BooleanClause.Occur.SHOULD);
            expected.Add(new TermQuery(new Term("field", "bar")), BooleanClause.Occur.SHOULD);

            SimpleQueryParser parser = new SimpleQueryParser(new MockAnalyzer(Random()), "field");
            assertEquals(expected, parser.Parse("foo bar"));
        }