Parse() public method

public Parse ( string query ) : Query
query string
return Lucene.Net.Search.Query
Esempio n. 1
0
        public virtual void TestHashcodeEquals()
        {
            ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);

            qp.InOrder           = true;
            qp.FuzzyPrefixLength = 1;

            String qString = "\"aaa* bbb*\"";

            Query q  = qp.Parse(qString);
            Query q2 = qp.Parse(qString);

            assertEquals(q.GetHashCode(), q2.GetHashCode());
            assertEquals(q, q2);

            qp.InOrder = (false); // SOLR-6011

            q2 = qp.Parse(qString);

            // although the general contract of hashCode can't guarantee different values, if we only change one thing
            // about a single query, it normally should result in a different value (and will with the current
            // implementation in ComplexPhraseQuery)
            assertTrue(q.GetHashCode() != q2.GetHashCode());
            assertTrue(!q.equals(q2));
            assertTrue(!q2.equals(q));
        }
Esempio n. 2
0
        private void CheckMatches(string qString, string expectedVals)
        {
            ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);

            qp.InOrder           = inOrder;
            qp.FuzzyPrefixLength = 1; // usually a good idea

            Query q = qp.Parse(qString);

            HashSet <string> expecteds = new HashSet <string>();

            string[] vals = expectedVals.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < vals.Length; i++)
            {
                if (vals[i].Length > 0)
                {
                    expecteds.Add(vals[i]);
                }
            }

            TopDocs td = searcher.Search(q, 10);

            ScoreDoc[] sd = td.ScoreDocs;
            for (int i = 0; i < sd.Length; i++)
            {
                Document doc = searcher.Doc(sd[i].Doc);
                string   id  = doc.Get("id");
                assertTrue(qString + "matched doc#" + id + " not expected", expecteds
                           .Contains(id));
                expecteds.Remove(id);
            }

            assertEquals(qString + " missing some matches ", 0, expecteds.Count);
        }
Esempio n. 3
0
        private void CheckBadQuery(String qString)
        {
            ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);

            qp.InOrder = inOrder;
            Exception expected = null;

            try
            {
                qp.Parse(qString);
            }
            catch (Exception e)
            {
                expected = e;
            }
            assertNotNull("Expected parse error in " + qString, expected);
        }
Esempio n. 4
0
            // Called by ComplexPhraseQueryParser for each phrase after the main
            // parse
            // thread is through
            protected internal void ParsePhraseElements(ComplexPhraseQueryParser qp)
            {
                // TODO ensure that field-sensitivity is preserved ie the query
                // string below is parsed as
                // field+":("+phrasedQueryStringContents+")"
                // but this will need code in rewrite to unwrap the first layer of
                // boolean query

                string oldDefaultParserField = qp.Field;

                try
                {
                    //temporarily set the QueryParser to be parsing the default field for this phrase e.g author:"fred* smith"
                    qp.m_field = this.field;
                    contents   = qp.Parse(phrasedQueryStringContents);
                }
                finally
                {
                    qp.m_field = oldDefaultParserField;
                }
            }
            // Called by ComplexPhraseQueryParser for each phrase after the main
            // parse
            // thread is through
            protected internal void ParsePhraseElements(ComplexPhraseQueryParser qp)
            {
                // TODO ensure that field-sensitivity is preserved ie the query
                // string below is parsed as
                // field+":("+phrasedQueryStringContents+")"
                // but this will need code in rewrite to unwrap the first layer of
                // boolean query

                string oldDefaultParserField = qp.Field;
                try
                {
                    //temporarily set the QueryParser to be parsing the default field for this phrase e.g author:"fred* smith"
                    qp.field = this.field;
                    contents = qp.Parse(phrasedQueryStringContents);
                }
                finally
                {
                    qp.field = oldDefaultParserField;
                }
            }
        private void CheckMatches(string qString, string expectedVals)
        {
            ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);
            qp.InOrder = inOrder;
            qp.FuzzyPrefixLength = 1; // usually a good idea

            Query q = qp.Parse(qString);

            HashSet<string> expecteds = new HashSet<string>();
            string[] vals = expectedVals.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < vals.Length; i++)
            {
                if (vals[i].Length > 0)
                    expecteds.Add(vals[i]);
            }

            TopDocs td = searcher.Search(q, 10);
            ScoreDoc[] sd = td.ScoreDocs;
            for (int i = 0; i < sd.Length; i++)
            {
                Document doc = searcher.Doc(sd[i].Doc);
                string id = doc.Get("id");
                assertTrue(qString + "matched doc#" + id + " not expected", expecteds
                    .Contains(id));
                expecteds.Remove(id);
            }

            assertEquals(qString + " missing some matches ", 0, expecteds.Count);
        }
 private void CheckBadQuery(String qString)
 {
     ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);
     qp.InOrder = inOrder;
     Exception expected = null;
     try
     {
         qp.Parse(qString);
     }
     catch (Exception e)
     {
         expected = e;
     }
     assertNotNull("Expected parse error in " + qString, expected);
 }
        public virtual void TestHashcodeEquals()
        {
            ComplexPhraseQueryParser qp = new ComplexPhraseQueryParser(TEST_VERSION_CURRENT, defaultFieldName, analyzer);
            qp.InOrder = true;
            qp.FuzzyPrefixLength = 1;

            String qString = "\"aaa* bbb*\"";

            Query q = qp.Parse(qString);
            Query q2 = qp.Parse(qString);

            assertEquals(q.GetHashCode(), q2.GetHashCode());
            assertEquals(q, q2);

            qp.InOrder = (false); // SOLR-6011

            q2 = qp.Parse(qString);

            // although the general contract of hashCode can't guarantee different values, if we only change one thing
            // about a single query, it normally should result in a different value (and will with the current
            // implementation in ComplexPhraseQuery)
            assertTrue(q.GetHashCode() != q2.GetHashCode());
            assertTrue(!q.equals(q2));
            assertTrue(!q2.equals(q));
        }