本文整理汇总了C#中Lucene.Net.QueryParsers.QueryParser.SetAllowLeadingWildcard方法的典型用法代码示例。如果您正苦于以下问题:C# QueryParser.SetAllowLeadingWildcard方法的具体用法?C# QueryParser.SetAllowLeadingWildcard怎么用?C# QueryParser.SetAllowLeadingWildcard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.QueryParsers.QueryParser
的用法示例。
在下文中一共展示了QueryParser.SetAllowLeadingWildcard方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFieldValueClause
internal static void AddFieldValueClause(BooleanQuery query, string fieldName, string fieldValue, QueryOccurance occurance)
{
if (fieldName.IsNullOrEmpty() || fieldValue.IsNullOrEmpty())
{
return;
}
var globalBooleanQuery = new BooleanQuery();
var qp = new QueryParser("__workflow state", ItemBucket.Kernel.Util.IndexSearcher.Index.Analyzer);
qp.SetAllowLeadingWildcard(true);
globalBooleanQuery.Add(qp.Parse(fieldValue), BooleanClause.Occur.MUST);
query.Add(globalBooleanQuery, BooleanClause.Occur.MUST);
}
示例2: SearchService
public SearchService()
{
var tmpluceneIndexDir = LuceneStore.FSDirectory.Open(INDEX_DIR);
luceneIndexDir = new LuceneStore.RAMDirectory(tmpluceneIndexDir);
tmpluceneIndexDir.Close();
analyzer = new StandardAnalyzer(LuceneUtil.Version.LUCENE_29);
reader = IndexReader.Open(luceneIndexDir, true); // only searching, so read-only=true
searcher = new IndexSearcher(reader);
// parser = new QueryParser(LuceneUtil.Version.LUCENE_29, "analized_path", analyzer);
parser = new QueryParser(LuceneUtil.Version.LUCENE_29, "name", analyzer);
parser.SetDefaultOperator(QueryParser.Operator.AND);
parser.SetAllowLeadingWildcard(true);
}
示例3: ApplyFullTextClause
internal static void ApplyFullTextClause(BooleanQuery query, string searchText, string indexName)
{
if (searchText.IsNullOrEmpty())
{
return;
}
var globalBooleanQuery = new BooleanQuery();
var qp = new QueryParser("_content", ItemBucket.Kernel.Util.IndexSearcher.Index.Analyzer);
qp.SetAllowLeadingWildcard(true);
globalBooleanQuery.Add(qp.Parse(searchText), BooleanClause.Occur.SHOULD);
var qp1 = new QueryParser("_name", ItemBucket.Kernel.Util.IndexSearcher.Index.Analyzer);
qp1.SetAllowLeadingWildcard(true);
globalBooleanQuery.Add(qp1.Parse(searchText), BooleanClause.Occur.SHOULD);
query.Add(globalBooleanQuery, BooleanClause.Occur.MUST);
}
示例4: SearchCompact
internal Yield SearchCompact(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
var explain = !context.Uri.GetParam("explain", "false").EqualsInvariantIgnoreCase("false");
var ret = new XDoc("documents");
var q = context.GetParam("q");
var wikiid = context.GetParam("wikiid", "default");
var threshold = context.GetParam("threshhold", _searchScoreThreshhold);
var authPlug = GetAuthPlug(context, request);
Query query;
var instance = GetInstance(wikiid);
using(var profile = _profilerFactory.Start("compact", wikiid)) {
try {
BooleanQuery.SetMaxClauseCount(ushort.MaxValue);
var parser = new QueryParser("content", _defaultAnalyzer);
parser.SetAllowLeadingWildcard(_allowLeadingWildCard);
using(profile.ProfileParse(q)) {
query = parser.Parse(q);
}
} catch(ParseException) {
response.Return(DreamMessage.BadRequest(string.Format("Error parsing search query: {0}", q)));
yield break;
}
ret.Elem("parsedQuery", query.ToString());
IList<LuceneResult> resultSet;
using(profile.ProfileQuery()) {
resultSet = instance.Search(query, null, int.MaxValue, 0, threshold, profile, authPlug);
}
using(profile.ProfilePostProcess(resultSet.Count)) {
foreach(var result in resultSet) {
ConvertToCompactXDoc(ret, result);
}
}
if(explain) {
var beginning = ret[0];
beginning.AddAllBefore(profile.GetProfile());
}
}
response.Return(DreamMessage.Ok(ret));
yield break;
}
示例5: Search
internal Yield Search(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
var explain = !context.Uri.GetParam("explain", "false").EqualsInvariantIgnoreCase("false");
XDoc ret = new XDoc("documents");
string q = context.GetParam("q");
var max = context.GetParam("max", "100");
int limit = int.MaxValue;
int offset = 0;
if(!max.StartsWithInvariantIgnoreCase("all")) {
limit = (int)Math.Min(long.Parse(max), int.MaxValue);
offset = context.GetParam("offset", 0);
}
var authPlug = GetAuthPlug(context, request);
var threshold = context.GetParam("threshhold", _searchScoreThreshhold);
var wikiid = context.GetParam("wikiid", "default");
var sortDesc = false;
SortField sortField = null;
string sortBy = context.GetParam("sortby", "-score");
if(sortBy.StartsWith("-")) {
sortDesc = true;
sortBy = sortBy.Substring(1);
}
switch(sortBy) {
case "title":
sortField = new SortField("title.sort", SortField.STRING, sortDesc);
break;
case "date":
sortField = new SortField("date.edited", SortField.STRING, sortDesc);
break;
case "size":
sortField = new SortField("size", SortField.AUTO, sortDesc);
break;
case "wordcount":
sortField = new SortField("wordcount", SortField.AUTO, sortDesc);
break;
case "user.username":
sortField = new SortField("username", SortField.STRING, sortDesc);
break;
case "user.fullname":
sortField = new SortField("fullname.sort", SortField.STRING, sortDesc);
break;
case "user.date.lastlogin":
sortField = new SortField("date.lastlogin", SortField.STRING, sortDesc);
break;
case "rating.score":
sortField = new SortField("rating.score", SortField.FLOAT, sortDesc);
break;
case "rating.count":
sortField = new SortField("rating.count", SortField.INT, sortDesc);
break;
case "score":
if(!sortDesc) {
sortField = new SortField(SortField.FIELD_SCORE.GetField(), SortField.SCORE, true);
}
break;
}
Query query;
var instance = GetInstance(wikiid);
using(var profile = _profilerFactory.Start("standard", wikiid)) {
try {
BooleanQuery.SetMaxClauseCount(ushort.MaxValue);
var parser = new QueryParser("content", _defaultAnalyzer);
parser.SetAllowLeadingWildcard(_allowLeadingWildCard);
using(profile.ProfileParse(q)) {
query = parser.Parse(q);
}
} catch(ParseException) {
response.Return(DreamMessage.BadRequest(string.Format("Error parsing search query: {0}", q)));
yield break;
}
ret.Elem("parsedQuery", query.ToString());
IList<LuceneResult> resultSet = null;
using(profile.ProfileQuery()) {
resultSet = instance.Search(query, sortField, limit, offset, threshold, profile, authPlug);
}
using(profile.ProfilePostProcess(resultSet.Count)) {
foreach(var result in resultSet) {
ConvertToXDoc(ret, result);
}
}
if(explain) {
var beginning = ret[0];
beginning.AddAllBefore(profile.GetProfile());
}
}
response.Return(DreamMessage.Ok(ret));
yield break;
}
示例6: SearchCompact
internal Yield SearchCompact(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
XDoc ret = new XDoc("documents");
string q = context.GetParam("q");
string wikiid = context.GetParam("wikiid", "default");
var threshold = context.GetParam("threshhold", _searchScoreThreshhold);
Query query;
var instance = GetInstance(wikiid);
try {
BooleanQuery.SetMaxClauseCount(ushort.MaxValue);
var parser = new QueryParser("content", _defaultAnalyzer);
parser.SetAllowLeadingWildcard(_allowLeadingWildCard);
query = parser.Parse(q);
ret.Elem("parsedQuery", query.ToString());
Hits hits = instance.Search(query, null);
for(int i = 0; i < hits.Length(); i++) {
if(hits.Score(i) < threshold) {
// Note (arnec): safe to break, since default sortby is by score
break;
}
ConvertToCompactXDoc(ret, hits.Doc(i), hits.Score(i));
}
response.Return(DreamMessage.Ok(ret));
} catch(ParseException) {
response.Return(DreamMessage.BadRequest(string.Format("Error parsing search query: {0}", q)));
}
yield break;
}
示例7: Search
internal Yield Search(DreamContext context, DreamMessage request, Result<DreamMessage> response) {
XDoc ret = new XDoc("documents");
string q = context.GetParam("q");
var max = context.GetParam("max", "100");
uint? limit = null;
int offset = 0;
if(!max.StartsWithInvariantIgnoreCase("all")) {
limit = uint.Parse(max);
offset = context.GetParam("offset", 0);
}
var threshold = context.GetParam("threshhold", _searchScoreThreshhold);
string wikiid = context.GetParam("wikiid", "default");
bool sortDesc = false;
SortField sortField = null;
string sortBy = context.GetParam("sortby", "-score");
if(sortBy.StartsWith("-")) {
sortDesc = true;
sortBy = sortBy.Substring(1);
}
switch(sortBy) {
case "title":
sortField = new SortField("title.sort", SortField.STRING, sortDesc);
break;
case "date":
sortField = new SortField("date.edited", SortField.STRING, sortDesc);
break;
case "size":
sortField = new SortField("size", SortField.AUTO, sortDesc);
break;
case "wordcount":
sortField = new SortField("wordcount", SortField.AUTO, sortDesc);
break;
case "user.username":
sortField = new SortField("username", SortField.STRING, sortDesc);
break;
case "user.fullname":
sortField = new SortField("fullname.sort", SortField.STRING, sortDesc);
break;
case "user.date.lastlogin":
sortField = new SortField("date.lastlogin", SortField.STRING, sortDesc);
break;
case "rating.score":
sortField = new SortField("rating.score", SortField.FLOAT, sortDesc);
break;
case "rating.count":
sortField = new SortField("rating.count", SortField.INT, sortDesc);
break;
case "score":
if(!sortDesc) {
sortField = new SortField(SortField.FIELD_SCORE.GetField(), SortField.SCORE, true);
}
break;
}
Query query;
var instance = GetInstance(wikiid);
try {
BooleanQuery.SetMaxClauseCount(ushort.MaxValue);
var parser = new QueryParser("content", _defaultAnalyzer);
parser.SetAllowLeadingWildcard(_allowLeadingWildCard);
query = parser.Parse(q);
ret.Elem("parsedQuery", query.ToString());
var sort = sortField == null ? null : new Sort(sortField);
Hits hits = instance.Search(query, sort);
if(!limit.HasValue) {
limit = (uint)hits.Length();
}
for(int i = offset; i < hits.Length() && i < offset + limit; i++) {
if(hits.Score(i) < threshold) {
// Note (arnec): can't break, since a different sortBy than score could have been used
continue;
}
ConvertToXDoc(ret, hits.Doc(i), hits.Score(i));
}
response.Return(DreamMessage.Ok(ret));
} catch(ParseException) {
response.Return(DreamMessage.BadRequest(string.Format("Error parsing search query: {0}", q)));
}
yield break;
}
示例8: CreateQuery
private Query CreateQuery(string field, string term)
{
QueryParser parser = new QueryParser(Version.LUCENE_29, field, Analyzer);
parser.SetFuzzyMinSim(0.70f);
parser.SetFuzzyPrefixLength(3);
parser.SetDefaultOperator(QueryParser.Operator.OR);
parser.SetAllowLeadingWildcard(true);
return parser.Parse(term);
}