本文整理汇总了C#中Lucene.Net.QueryParsers.QueryParser.Query方法的典型用法代码示例。如果您正苦于以下问题:C# QueryParser.Query方法的具体用法?C# QueryParser.Query怎么用?C# QueryParser.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.QueryParsers.QueryParser
的用法示例。
在下文中一共展示了QueryParser.Query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetItems
/// <summary>
/// Gets the items from the GetIndexes()
/// </summary>
/// <param name="queryString">
/// The query string.
/// </param>
/// <param name="useQueryParser">
/// if set to <c>true</c> [use query parser].
/// </param>
/// <returns>
/// Returns Query Result
/// </returns>
public QueryResult GetItems(string queryString, bool useQueryParser)
{
// Result object used to pass result and errormessages back to sender.
QueryResult result = new QueryResult();
List<string> indexes = this.GetIndexes();
string[] resultItemIds = null;
foreach (string indexName in indexes)
{
string database = "master";
HighResTimer timer = new HighResTimer(true);
// get the specified index
Sitecore.Search.Index searchIndex = SearchManager.GetIndex(indexName);
// get the database to perform the search in..
Database db = Factory.GetDatabase(database);
SearchHits hits;
try
{
if (useQueryParser)
{
using (IndexSearchContext searchContext = searchIndex.CreateSearchContext())
{
// get a new standard analyser so we can create a query..
Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
QueryParser queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, queryString, analyzer);
Query qry = queryParser.Query("_content");
hits = searchContext.Search(qry, int.MaxValue);
}
}
else
{
using (IndexSearchContext searchContext = searchIndex.CreateSearchContext())
{
// perform the search and get the results back as a Hits list..
hits = searchContext.Search(queryString, int.MaxValue);
}
}
result.Success = true;
resultItemIds = new string[hits.Length];
int i = 0;
foreach (Document document in hits.Documents)
{
string str = document.Get("_docID");
resultItemIds[i++] = str;
}
}
catch (ParseException e)
{
result.ErrorMessage = e.Message;
result.ParseException = e;
result.Success = false;
}
}
result.Result = resultItemIds;
return result;
}