Lucene.Net.QueryParsers.QueryParser.Parse C# (CSharp) Method

Parse() public method

Parses a query string, returning a {@link Lucene.Net.Search.Query}.
public Parse ( String query ) : Query
query String the query string to be parsed. ///
return Lucene.Net.Search.Query
        public virtual Query Parse(String query)
        {
            ReInit(new FastCharStream(new StringReader(query)));
            try
            {
                // TopLevelQuery is a Query followed by the end-of-input (EOF)
                Query res = TopLevelQuery(field);
                return res ?? NewBooleanQuery(false);
            }
            catch (ParseException tme)
            {
                // rethrow to include the original query:
                throw new ParseException("Cannot parse '" + query + "': " + tme.Message, tme);
            }
            catch (TokenMgrError tme)
            {
                throw new ParseException("Cannot parse '" + query + "': " + tme.Message, tme);
            }
            catch (BooleanQuery.TooManyClauses tmc)
            {
                throw new ParseException("Cannot parse '" + query + "': too many bool clauses", tmc);
            }
        }

Usage Example

Ejemplo n.º 1
0
        public void CustomBridges()
        {
            Cloud cloud = new Cloud();
            cloud.CustomFieldBridge = ("This is divided by 2");
            cloud.CustomStringBridge = ("This is div by 4");
            ISession s = OpenSession();
            ITransaction tx = s.BeginTransaction();
            s.Save(cloud);
            s.Flush();
            tx.Commit();

            tx = s.BeginTransaction();
            IFullTextSession session = Search.CreateFullTextSession(s);
            QueryParser parser = new QueryParser("id", new SimpleAnalyzer());

            Lucene.Net.Search.Query query = parser.Parse("CustomFieldBridge:This AND CustomStringBridge:This");
            IList result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(1, result.Count, "Properties not mapped");

            query = parser.Parse("CustomFieldBridge:by AND CustomStringBridge:is");
            result = session.CreateFullTextQuery(query).List();
            Assert.AreEqual(0, result.Count, "Custom types not taken into account");

            s.Delete(s.Get(typeof(Cloud), cloud.Id));
            tx.Commit();
            s.Close();
        }
All Usage Examples Of Lucene.Net.QueryParsers.QueryParser::Parse