public static QueryPostfixForm ParseQuery(string query) { Initialize(); _query = query.Trim().ToLower(); QueryPostfixForm form; try { QueryParserNode nodeRoot = ParseExpression(); QueryParserNode newRoot = null; PropagateSectionOpInside(ref newRoot, nodeRoot); if (newRoot == null) { newRoot = nodeRoot; } form = new QueryPostfixForm(); Tree2Postfix(newRoot, form); } catch (Exception) { form = null; } return(form); }
public static Entry[] ProcessQuery(QueryPostfixForm postfixForm, TermIndexAccessor termIndex, bool appendIdMappings) { Stack opStack = new Stack(); Entry[] result = null; Error = ErrorStatus.NoError; MappedInstances.Clear(); if (!appendIdMappings) { Lexemes.Clear(); Stopwords.Clear(); } try { IteratePostfixExpression(postfixForm, termIndex, opStack); //----------------------------------------------------------------- // Now only one Entry[] must remain on the top of the stack. It may // be null if no document correspond to the query //----------------------------------------------------------------- if (opStack.Count != 1) { throw new ApplicationException("QueryParser -- Illegal query statement found"); } if (!(opStack.Peek() is StopwordTerm)) { result = ExtractOperandFromStack(opStack); if (result != null) { Array.Sort(result, new CompareByTfIdf()); } } } catch (Exception exc) { Trace.WriteLine("QueryProcessor -- exception [" + exc.Message + "] occured."); // Exception is raised if the expression was constructed with // the syntactic errors. // Clear the stack and put special marker on the top of it Error = ErrorStatus.IllegalQuerySyntax; result = null; } opStack.Clear(); return(result); }
private static void Tree2Postfix(QueryParserNode root, QueryPostfixForm form) { if (root == null) { return; } if (root.NodeType != QueryParserNode.Type.eoTerm) { foreach (QueryParserNode node in ((OpNode)root).Branches()) { Tree2Postfix(node, form); } } form.Add(root); }
public bool MatchQuery(string query, int resId, int dummy) { #region Preconditions if (resId != _lastDocID) { throw new ArgumentException("MatchQuery (FullTextIndexer) -- Input resource Id does not match internal data"); } #endregion Preconditions bool result = false; if (isValidQuery(query)) { QueryPostfixForm form = QueryParser.ParseQuery(query); if (form != null) { result = MatchProcessor.MatchQuery(form, _tokens); } } return(result); }
public static bool MatchQuery(QueryPostfixForm postfixForm, IntHashTable tokens) { Stack <List <long> > opStack = new Stack <List <long> >(); bool result; try { IteratePostfixExpression(postfixForm, tokens, opStack); if (opStack.Count != 1) { throw new ApplicationException("QueryParser -- Illegal query statement found"); } result = (opStack.Peek() != null); } catch (Exception exc) { Trace.WriteLine("MatchProcessor -- exception [" + exc.Message + "] occured."); result = true; } opStack.Clear(); return(result); }
/// <summary> /// This public method is designed for simplified processing and is used in tests. /// </summary> public Entry[] ProcessQueryInternal(string query) { Entry[] resultEntries = null; if (isValidQuery(query)) { QueryPostfixForm form = QueryParser.ParseQuery(query); resultEntries = QueryProcessor.ProcessQuery(form, TermIndexAccessor); if (resultEntries != null) { ArrayList list = new ArrayList(); foreach (Entry e in resultEntries) { if (IsDocumentPresentInternal(e.DocIndex)) { list.Add(e); } } resultEntries = (list.Count > 0) ? (Entry[])list.ToArray(typeof(Entry)) : null; } } return(resultEntries); }
private QueryResult PerformInitialSearch(string query) { QueryResult qResult = new QueryResult(); // perform search only if input query string is of "reasonable" length if (isValidQuery(query)) { QueryPostfixForm form = QueryParser.ParseQuery(query); if (form != null) { qResult.IsSingularTerm = (form.TermNodesCount == 1); qResult.Result = QueryProcessor.ProcessQuery(form, TermIndexAccessor); if (QueryProcessor.Status == QueryProcessor.ErrorStatus.IllegalSectionName) { qResult.ErrorMessage = "Illegal document section name specified. Please consult help file for valid secion names."; } } else { qResult.ErrorMessage = QueryParser.Error; } } return(qResult); }
public static Entry[] ProcessQuery(QueryPostfixForm postfixForm, TermIndexAccessor termIndex) { return(ProcessQuery(postfixForm, termIndex, false)); }