本文整理汇总了C#中Lucene.Net.Search.WildcardQuery类的典型用法代码示例。如果您正苦于以下问题:C# WildcardQuery类的具体用法?C# WildcardQuery怎么用?C# WildcardQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WildcardQuery类属于Lucene.Net.Search命名空间,在下文中一共展示了WildcardQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AddQuery
/// <summary>
/// Adds the query.
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="query">The query.</param>
/// <param name="filter">The filter.</param>
protected void AddQuery(string fieldName, BooleanQuery query, StringCollection filter)
{
fieldName = fieldName.ToLower();
if (filter.Count > 0)
{
if (filter.Count != 1)
{
var booleanQuery = new BooleanQuery();
var containsFilter = false;
foreach (var index in filter)
{
if (String.IsNullOrEmpty(index))
{
continue;
}
var nodeQuery = new WildcardQuery(new Term(fieldName, index));
booleanQuery.Add(nodeQuery, Occur.SHOULD);
containsFilter = true;
}
if (containsFilter)
{
query.Add(booleanQuery, Occur.MUST);
}
}
else
{
if (!String.IsNullOrEmpty(filter[0]))
{
this.AddQuery(fieldName, query, filter[0].ToLower());
}
}
}
}
开发者ID:adwardliu,项目名称:vc-community,代码行数:40,代码来源:BaseSearchQueryBuilder.cs
示例2: FindSuggestionsBySubstring
/// <summary>
/// Returns a collection of all suggestions that match the given searchTerm.
/// A match means search term appears anywhere in the product code or category name.
///
/// If the searchTerm is null or empty, or doesn't match any categories, than an empty list is returned.
/// The suggestions will be returned in the correct order.
/// </summary>
/// <param name="searchTerm"></param>
/// <returns></returns>
public IEnumerable<ISuggestion> FindSuggestionsBySubstring(string searchTerm)
{
if (string.IsNullOrEmpty(searchTerm))
{
return new List<CategorySuggestion>();
}
// The product codes and category names have been stored in upper case. So need to convert search term to upper case as well.
string searchTermUc = LuceneEscape(searchTerm.ToUpper());
Query query1 = new WildcardQuery(new Term("UcName", "*" + searchTermUc + "*"));
// Get the searcher. Access _searcher only once while doing a search. Another request running
// LoadProductStore could change this property. By accessing once, you are sure your searcher stays the same.
var searcher = _searcher;
// Actual search
TopDocs hits = searcher.Search(query1, searcher.MaxDoc);
// Return results. ScoreDocs is sorted by relevancy, but we want alphabetic sorting, and category suggestions first.
IEnumerable<ISuggestion> sortedResults = hits.ScoreDocs
.Select(d =>
{
var doc = searcher.Doc(d.Doc);
return DocToSuggestion(doc);
})
.OrderBy(s=>(s is CategorySuggestion ? 0 : 1))
.ThenBy(s=>s.SortedName);
return sortedResults;
}
开发者ID:stephengodbold,项目名称:searchpdproj,代码行数:41,代码来源:SuggestionSearcher.cs
示例3: TestAsterisk
public virtual void TestAsterisk()
{
RAMDirectory indexStore = GetIndexStore("body", new System.String[]{"metal", "metals"});
IndexSearcher searcher = new IndexSearcher(indexStore);
Query query1 = new TermQuery(new Term("body", "metal"));
Query query2 = new WildcardQuery(new Term("body", "metal*"));
Query query3 = new WildcardQuery(new Term("body", "m*tal"));
Query query4 = new WildcardQuery(new Term("body", "m*tal*"));
Query query5 = new WildcardQuery(new Term("body", "m*tals"));
BooleanQuery query6 = new BooleanQuery();
query6.Add(query5, false, false);
BooleanQuery query7 = new BooleanQuery();
query7.Add(query3, false, false);
query7.Add(query5, false, false);
// Queries do not automatically lower-case search terms:
Query query8 = new WildcardQuery(new Term("body", "M*tal*"));
AssertMatches(searcher, query1, 1);
AssertMatches(searcher, query2, 2);
AssertMatches(searcher, query3, 1);
AssertMatches(searcher, query4, 2);
AssertMatches(searcher, query5, 1);
AssertMatches(searcher, query6, 1);
AssertMatches(searcher, query7, 2);
AssertMatches(searcher, query8, 0);
}
开发者ID:emtees,项目名称:old-code,代码行数:29,代码来源:TestWildcard.cs
示例4: TestAsterisk
public virtual void TestAsterisk()
{
Directory indexStore = GetIndexStore("body", new string[] { "metal", "metals" });
IndexReader reader = DirectoryReader.Open(indexStore);
IndexSearcher searcher = NewSearcher(reader);
Query query1 = new TermQuery(new Term("body", "metal"));
Query query2 = new WildcardQuery(new Term("body", "metal*"));
Query query3 = new WildcardQuery(new Term("body", "m*tal"));
Query query4 = new WildcardQuery(new Term("body", "m*tal*"));
Query query5 = new WildcardQuery(new Term("body", "m*tals"));
BooleanQuery query6 = new BooleanQuery();
query6.Add(query5, BooleanClause.Occur.SHOULD);
BooleanQuery query7 = new BooleanQuery();
query7.Add(query3, BooleanClause.Occur.SHOULD);
query7.Add(query5, BooleanClause.Occur.SHOULD);
// Queries do not automatically lower-case search terms:
Query query8 = new WildcardQuery(new Term("body", "M*tal*"));
AssertMatches(searcher, query1, 1);
AssertMatches(searcher, query2, 2);
AssertMatches(searcher, query3, 1);
AssertMatches(searcher, query4, 2);
AssertMatches(searcher, query5, 1);
AssertMatches(searcher, query6, 1);
AssertMatches(searcher, query7, 2);
AssertMatches(searcher, query8, 0);
AssertMatches(searcher, new WildcardQuery(new Term("body", "*tall")), 0);
AssertMatches(searcher, new WildcardQuery(new Term("body", "*tal")), 1);
AssertMatches(searcher, new WildcardQuery(new Term("body", "*tal*")), 2);
reader.Dispose();
indexStore.Dispose();
}
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:35,代码来源:TestWildcard.cs
示例5: TestTermWithoutWildcard
public virtual void TestTermWithoutWildcard()
{
RAMDirectory indexStore = GetIndexStore("field", new System.String[] {"nowildcard", "nowildcardx"});
IndexSearcher searcher = new IndexSearcher(indexStore, true);
MultiTermQuery wq = new WildcardQuery(new Term("field", "nowildcard"));
AssertMatches(searcher, wq, 1);
wq.RewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE;
wq.Boost = 0.1f;
Query q = searcher.Rewrite(wq);
Assert.IsTrue(q is TermQuery);
Assert.AreEqual(q.Boost, wq.Boost);
wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
wq.Boost = 0.2f;
q = searcher.Rewrite(wq);
Assert.True(q is ConstantScoreQuery);
Assert.AreEqual(q.Boost, wq.Boost);
wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
wq.Boost = 0.3F;
q = searcher.Rewrite(wq);
Assert.True(q is ConstantScoreQuery);
Assert.AreEqual(q.Boost, wq.Boost);
wq.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE;
wq.Boost = 0.4F;
q = searcher.Rewrite(wq);
Assert.True(q is ConstantScoreQuery);
Assert.AreEqual(q.Boost, wq.Boost);
}
开发者ID:raol,项目名称:lucene.net,代码行数:32,代码来源:TestWildcard.cs
示例6: TestTermWithoutWildcard
public virtual void TestTermWithoutWildcard()
{
Directory indexStore = GetIndexStore("field", new string[] { "nowildcard", "nowildcardx" });
IndexReader reader = DirectoryReader.Open(indexStore);
IndexSearcher searcher = NewSearcher(reader);
MultiTermQuery wq = new WildcardQuery(new Term("field", "nowildcard"));
AssertMatches(searcher, wq, 1);
wq.SetRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
wq.Boost = 0.1F;
Query q = searcher.Rewrite(wq);
Assert.IsTrue(q is TermQuery);
Assert.AreEqual(q.Boost, wq.Boost, 0);
wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
wq.Boost = 0.2F;
q = searcher.Rewrite(wq);
Assert.IsTrue(q is ConstantScoreQuery);
Assert.AreEqual(q.Boost, wq.Boost, 0.1);
wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
wq.Boost = 0.3F;
q = searcher.Rewrite(wq);
Assert.IsTrue(q is ConstantScoreQuery);
Assert.AreEqual(q.Boost, wq.Boost, 0.1);
wq.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
wq.Boost = 0.4F;
q = searcher.Rewrite(wq);
Assert.IsTrue(q is ConstantScoreQuery);
Assert.AreEqual(q.Boost, wq.Boost, 0.1);
reader.Dispose();
indexStore.Dispose();
}
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:35,代码来源:TestWildcard.cs
示例7: VisitWildcardQuery
public override Query VisitWildcardQuery(WildcardQuery wildcardq)
{
_dump.Append("WildcardQ(");
var q = base.VisitWildcardQuery(wildcardq);
_dump.Append(BoostToString(q));
_dump.Append(")");
return q;
}
开发者ID:jhuntsman,项目名称:FlexNet,代码行数:8,代码来源:DumpVisitor.cs
示例8: TestTermWithoutWildcard
public virtual void TestTermWithoutWildcard()
{
RAMDirectory indexStore = GetIndexStore("field", new System.String[]{"nowildcard", "nowildcardx"});
IndexSearcher searcher = new IndexSearcher(indexStore);
Query wq = new WildcardQuery(new Term("field", "nowildcard"));
AssertMatches(searcher, wq, 1);
wq = searcher.Rewrite(wq);
Assert.IsTrue(wq is TermQuery);
}
开发者ID:Mpdreamz,项目名称:lucene.net,代码行数:11,代码来源:TestWildcard.cs
示例9: BuildQuery
protected override ParameterizedSql BuildQuery(WildcardQuery wildcardQuery)
{
var termText = EscapeForSql(wildcardQuery.Term.Text);
// termText = termText.Replace("*", "%");
termText = termText.Replace("?", "_");
var userVariables = new Dictionary<string, string> {{"field1", "\"" + termText + "\""}};
var sql = "CONTAINS(" + FieldPlaceholder + ", @field1)";
return new ParameterizedSql(sql, userVariables);
}
开发者ID:tomvonclef,项目名称:LuceneQueryToSql,代码行数:11,代码来源:SqlServerFullTextQueryBuilder.cs
示例10: BuildQuery
protected override ParameterizedSql BuildQuery(WildcardQuery wildcardQuery)
{
var termText = EscapeForSql(wildcardQuery.Term.Text);
termText = termText.Replace("*", "%");
termText = termText.Replace("?", "_");
var userVariables = new Dictionary<string, string> {{"field1", termText}};
var sql = FieldPlaceholder + " LIKE '%' + @field1 + '%'";
return new ParameterizedSql(sql, userVariables);
}
开发者ID:tomvonclef,项目名称:LuceneQueryToSql,代码行数:11,代码来源:SqlServerQueryBuilder.cs
示例11: GetTextQuery
protected static BooleanQuery GetTextQuery(SearchUserInput searchUserInput, params string[] fieldNames)
{
var masterQuery = new BooleanQuery();
foreach (string queryTerm in searchUserInput.Terms)
{
foreach (string fieldName in fieldNames)
{
var query = new WildcardQuery(new Term(fieldName, queryTerm));
masterQuery.Add(query, searchUserInput.BooleanCombinationLogic);
}
}
return masterQuery;
}
开发者ID:PublicHealthEngland,项目名称:fingertips-open,代码行数:13,代码来源:SearchEngine.cs
示例12: GetPlaceNameQuery
protected static BooleanQuery GetPlaceNameQuery(SearchUserInput searchUserInput, int parentAreaTypeId)
{
var masterQuery = new BooleanQuery();
foreach (string queryTerm in searchUserInput.Terms)
{
var query = new WildcardQuery(new Term(FieldNames.PlaceName, queryTerm));
masterQuery.Add(query, searchUserInput.BooleanCombinationLogic);
}
var parentAreaTypeIdQuery = new WildcardQuery(new Term("Parent_Area_Code_" + parentAreaTypeId, "x"));
masterQuery.Add(parentAreaTypeIdQuery, BooleanClause.Occur.MUST_NOT);
return masterQuery;
}
开发者ID:PublicHealthEngland,项目名称:fingertips-open,代码行数:14,代码来源:GeographicalSearch.cs
示例13: Build
public virtual Query Build(IQueryNode queryNode)
{
WildcardQueryNode wildcardNode = (WildcardQueryNode)queryNode;
WildcardQuery q = new WildcardQuery(new Term(wildcardNode.GetFieldAsString(),
wildcardNode.GetTextAsString()));
MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod)queryNode.GetTag(MultiTermRewriteMethodProcessor.TAG_ID);
if (method != null)
{
q.SetRewriteMethod(method);
}
return q;
}
开发者ID:apache,项目名称:lucenenet,代码行数:15,代码来源:WildcardQueryNodeBuilder.cs
示例14: TestQuestionmark
public virtual void TestQuestionmark()
{
RAMDirectory indexStore = GetIndexStore("body", new System.String[]{"metal", "metals", "mXtals", "mXtXls"});
IndexSearcher searcher = new IndexSearcher(indexStore);
Query query1 = new WildcardQuery(new Term("body", "m?tal"));
Query query2 = new WildcardQuery(new Term("body", "metal?"));
Query query3 = new WildcardQuery(new Term("body", "metals?"));
Query query4 = new WildcardQuery(new Term("body", "m?t?ls"));
Query query5 = new WildcardQuery(new Term("body", "M?t?ls"));
AssertMatches(searcher, query1, 1);
AssertMatches(searcher, query2, 2);
AssertMatches(searcher, query3, 1);
AssertMatches(searcher, query4, 3);
AssertMatches(searcher, query5, 0);
}
开发者ID:emtees,项目名称:old-code,代码行数:16,代码来源:TestWildcard.cs
示例15: GetHint
public ActionResult GetHint(string term)
{
if (!string.IsNullOrEmpty(term))
{
var seacher = new Seacher(dataFolder);
WildcardQuery nameQuery = new WildcardQuery(new Term("Name", "*" + term + "*"));
var Result = seacher.Search(nameQuery, 5);
Result.SearchResultItems.OrderBy(x => x.Type);
if (Result.SearchResultItems.Count > 0)
{
Result.SearchResultItems.OrderBy(x => x.Type);
return Json(Result.SearchResultItems);
}
}
return new JsonResult
{
Data = new { OK = false }
};
}
开发者ID:ASbeletsky,项目名称:Cinema3D,代码行数:19,代码来源:SearchController.cs
示例16: TestEquals
public virtual void TestEquals()
{
WildcardQuery wq1 = new WildcardQuery(new Term("field", "b*a"));
WildcardQuery wq2 = new WildcardQuery(new Term("field", "b*a"));
WildcardQuery wq3 = new WildcardQuery(new Term("field", "b*a"));
// reflexive?
Assert.AreEqual(wq1, wq2);
Assert.AreEqual(wq2, wq1);
// transitive?
Assert.AreEqual(wq2, wq3);
Assert.AreEqual(wq1, wq3);
Assert.IsFalse(wq1.Equals(null));
FuzzyQuery fq = new FuzzyQuery(new Term("field", "b*a"));
Assert.IsFalse(wq1.Equals(fq));
Assert.IsFalse(fq.Equals(wq1));
}
开发者ID:raol,项目名称:lucene.net,代码行数:20,代码来源:TestWildcard.cs
示例17: GetSearchResult
public override List<ISearchEntity> GetSearchResult(out int MatchCount)
{
Analyzer analyzer = new StandardAnalyzer();
IndexSearcher searcher = new IndexSearcher(searchInfo.ConfigElement.IndexDirectory);
MultiFieldQueryParser parserName = new MultiFieldQueryParser(new string[] { "productname", "keywords", "description" }, analyzer);
Query queryName = parserName.Parse(searchInfo.QueryString);
Query queryCategory = new WildcardQuery(new Term("catepath", "*" + searchInfo.Category + "*"));
BooleanQuery bQuery = new BooleanQuery();
bQuery.Add(queryName, BooleanClause.Occur.MUST);
if (searchInfo.Category != 0) bQuery.Add(queryCategory, BooleanClause.Occur.MUST);
Hits hits = searcher.Search(bQuery, GetSort());
List<ISearchEntity> ResultList = new List<ISearchEntity>();
for (int i = 0; i < hits.Length(); i++)
{
Document doc = hits.Doc(i);
ResultList.Add((ISearchEntity)new ProductModel()
{
EntityIdentity = Convert.ToInt32(doc.Get("productid")),
ProductName = doc.Get("productname"),
CategoryID = Convert.ToInt32(doc.Get("cateid")),
CategoryPath = doc.Get("catepath"),
Keywords = doc.Get("keywords"),
Description = doc.Get("description"),
Price = Convert.ToDecimal(doc.Get("price")),
CreateTime = Convert.ToDateTime(doc.Get("createtime")),
UpdateTime = Convert.ToDateTime(doc.Get("updatetime")),
ProductImage = Convert.ToString(doc.Get("mainimage"))
});
}
searcher.Close();
MatchCount = hits.Length();
return ResultList;
}
开发者ID:ViniciusConsultor,项目名称:noname-netshop,代码行数:41,代码来源:ProductSearcher.cs
示例18: DeleteAll
public virtual void DeleteAll()
{
var directory = FSDirectory.Open(new DirectoryInfo(LucenePath), new NativeFSLockFactory());
//IndexReader:对索引库进行读取的类
var isExist = IndexReader.IndexExists(directory);//是否存在索引库文件夹以及索引库特征文件
if (isExist)
{
//如果索引目录被锁定(比如索引过程中程序异常退出或另一进程在操作索引库),则解锁
if (IndexWriter.IsLocked(directory))
{
IndexWriter.Unlock(directory);
}
}
//创建向索引库写操作对象 IndexWriter(索引目录,指定使用盘古分词进行切词,最大写入长度限制)
//补充:使用IndexWriter打开directory时会自动对索引库文件上锁
var writer = new IndexWriter(directory, new PanGuAnalyzer(), !isExist, IndexWriter.MaxFieldLength.UNLIMITED);
Query query = new WildcardQuery(new Term("title", "*"));
writer.DeleteDocuments(query);
writer.Close();//会自动解锁
directory.Close(); //不要忘了Close,否则索引结果搜不到
}
开发者ID:bigboy53,项目名称:BoredNew,代码行数:22,代码来源:BaseLucene.cs
示例19: TestWildcards
public void TestWildcards()
{
using (var directory = new RAMDirectory())
{
IndexSingleFieldDocs(directory, new[] {
new Field("contents", "wild", Field.Store.YES, Field.Index.ANALYZED),
new Field("contents", "child", Field.Store.YES, Field.Index.ANALYZED),
new Field("contents", "mild", Field.Store.YES, Field.Index.ANALYZED),
new Field("contents", "mildew", Field.Store.YES, Field.Index.ANALYZED)
});
using (var indexSearcher = new IndexSearcher(directory))
{
var query = new WildcardQuery(new Term("contents", "?ild*"));
var topDocs = indexSearcher.Search(query, 10);
Assert.Equal(3, topDocs.TotalHits); // "child no match"
Assert.Equal(topDocs.ScoreDocs[0].Score, topDocs.ScoreDocs[1].Score, 1); // "score the same"
Assert.Equal(topDocs.ScoreDocs[1].Score, topDocs.ScoreDocs[2].Score, 1); // "score the same"
}
}
}
开发者ID:joshball,项目名称:Lucene.In.Action.NET,代码行数:22,代码来源:QueryParserTest.cs
示例20: Main
static void Main(string[] args)
{
SearchSection Config = (SearchSection)ConfigurationManager.GetSection("searches");
string action = Console.ReadLine();
if (action != String.Empty)
{
Analyzer analyzer = new StandardAnalyzer();
IndexSearcher searcher = new IndexSearcher(Config.Searches["product"].IndexDirectory);
MultiFieldQueryParser parserName = new MultiFieldQueryParser(new string[] { "productname", "keywords", "description" }, analyzer);
Query queryName = parserName.Parse("三星");
Query queryCategory = new WildcardQuery(new Term("catepath", "*82*"));
//Query queryCategory = parserCategory.Parse("82");
BooleanQuery bQuery = new BooleanQuery();
bQuery.Add(queryName, BooleanClause.Occur.MUST);
bQuery.Add(queryCategory, BooleanClause.Occur.MUST);
Hits hits = searcher.Search(bQuery);
for (int i = 0; i < hits.Length(); i++)
{
Document d = hits.Doc(i);
Console.WriteLine(d.Get("productname"));
}
}
else
{
DataProcessor.Process("product");
Console.Read();
}
}
开发者ID:ViniciusConsultor,项目名称:noname-netshop,代码行数:36,代码来源:Program.cs
注:本文中的Lucene.Net.Search.WildcardQuery类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论