/// <summary> /// Bypasses the Examine stuff to execute a lucene query directly on the given index. /// </summary> /// <param name="indexer">The name of the indexer to search on</param> /// <param name="luceneQuery">normal lucene query</param> /// <param name="maxResults">max results to return</param> /// <param name="highlightOpenTag">Opening tag for highlighted search terms in the result</param> /// <param name="highlightCloseTag">Closing tag for highlighted search terms in the result</param> /// <param name="fieldsToHighlightCsv">Comma-separated names of fields to apply highlighting to</param> /// <returns>search results on success or an error element on error</returns> private static XPathNodeIterator DoLuceneSearch(string indexer, string luceneQuery, int maxResults, string highlightOpenTag, string highlightCloseTag, string fieldsToHighlightCsv) { using(var searcher = new LuceneSearcher(indexer)) { try { string[] fieldsToHighlight = String.IsNullOrEmpty(fieldsToHighlightCsv) ? new string[0] : fieldsToHighlightCsv.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); IEnumerable<SearchResult> results = searcher.Search(luceneQuery, maxResults, highlightOpenTag, highlightCloseTag, fieldsToHighlight); return GetResultsAsXml(results); } catch (ParseException) { return new XDocument(new XElement("error", "Invalid lucene query")).CreateNavigator().Select("/*"); } } }
/// <summary> /// Bypasses the Examine stuff to execute a lucene query directly on the given index. /// </summary> /// <param name="indexer">The name of the indexer to search on</param> /// <param name="luceneQuery">normal lucene query</param> /// <param name="maxResults">max results to return</param> /// <param name="highlightOpenTag">Opening tag for highlighted search terms in the result</param> /// <param name="highlightCloseTag">Closing tag for highlighted search terms in the result</param> /// <param name="fieldsToHighlightCsv">Comma-separated names of fields to apply highlighting to</param> /// <returns>search results on success or an error element on error</returns> private static XPathNodeIterator DoLuceneSearch(string indexer, string luceneQuery, int maxResults, string highlightOpenTag, string highlightCloseTag, string fieldsToHighlightCsv) { using (var searcher = new LuceneSearcher(indexer)) { try { string[] fieldsToHighlight = String.IsNullOrEmpty(fieldsToHighlightCsv) ? new string[0] : fieldsToHighlightCsv.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); IEnumerable <SearchResult> results = searcher.Search(luceneQuery, maxResults, highlightOpenTag, highlightCloseTag, fieldsToHighlight); return(GetResultsAsXml(results)); } catch (ParseException) { return(new XDocument(new XElement("error", "Invalid lucene query")).CreateNavigator().Select("/*")); } } }