本文整理汇总了C#中Lucene.Net.Analysis.Standard.StandardAnalyzer类的典型用法代码示例。如果您正苦于以下问题:C# StandardAnalyzer类的具体用法?C# StandardAnalyzer怎么用?C# StandardAnalyzer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StandardAnalyzer类属于Lucene.Net.Analysis.Standard命名空间,在下文中一共展示了StandardAnalyzer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildQuery
public static Query BuildQuery(string query)
{
var untokenizedMatches = untokenizedQuery.Matches(query);
var rangeMatches = rangeQuery.Matches(query);
var standardAnalyzer = new StandardAnalyzer(Version.LUCENE_29);
try
{
if (untokenizedMatches.Count == 0 && rangeMatches.Count == 0)
return new QueryParser(Version.LUCENE_29, "", standardAnalyzer).Parse(query);
var sb = new StringBuilder(query);
var booleanQuery = new BooleanQuery();
AddUntokenizedTerms(untokenizedMatches, booleanQuery, sb, query);
AddRangeTerms(rangeMatches, booleanQuery, sb, query);
var remaining = sb.ToString();
remaining = hangingConditionAtStart.Replace(remaining, "");
remaining = hangingConditionAtEnd.Replace(remaining, "");
remaining = remaining.Trim();
if (remaining.Length > 0)
{
booleanQuery.Add(new QueryParser(Version.LUCENE_29, "", standardAnalyzer).Parse(remaining), BooleanClause.Occur.SHOULD);
}
return booleanQuery;
}
finally
{
standardAnalyzer.Close();
}
}
示例2: _search
private static IEnumerable<CustomerId> _search(string searchQuery)
{
// validation
if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<CustomerId>();
// set up lucene searcher
using (var searcher = new IndexSearcher(_directory, false))
{
var hits_limit = 1000;
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
{
//var query = new TermQuery(new Term("CustomerName", searchQuery));
var query = new BooleanQuery();
query.Add(new TermQuery(new Term("CustomerName", searchQuery)), Occur.MUST);
var hits = searcher.Search(query, hits_limit).ScoreDocs;
var results = _mapLuceneToDataList(hits, searcher);
analyzer.Close();
searcher.Dispose();
return results;
}
}
}
示例3: CreateIndex
public static void CreateIndex() {
try
{
var cloudAccount = Azure.GetStorageAccount();
using (var cacheDirectory = new RAMDirectory())
{
using (var azureDirectory = new AzureDirectory(cloudAccount, Azure.StorageContainerName, cacheDirectory))
{
using (Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
{
using (var indexWriter = new IndexWriter(azureDirectory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED))
{
AddDocuments(indexWriter);
indexWriter.Commit();
}
}
}
}
}
catch (StorageException ex)
{
Trace.TraceError(ex.Message);
}
}
示例4: searchLucene
public Data searchLucene(Data data)
{
Account_lg account = new Account_lg();
List<string> item = new List<string>();
Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo("C:\\Visual Studio 2010\\Transaction" + "\\LuceneIndex"));
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
IndexReader reader = IndexReader.Open(directory, true);
IndexSearcher searcher = new IndexSearcher(reader);
MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, new string[] { "name", "username" }, analyzer); //search for multifield
Query query = parser.Parse((data.getString("search")) + "*"); //cant search blank text with wildcard as first character
TopScoreDocCollector collector = TopScoreDocCollector.Create(1000, true);
searcher.Search(query, collector);
ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
int count = hits.Length;
for (int i = 0; i < count; i++)
{
int docId = hits[i].Doc;
float score = hits[i].Score;
Document doc = searcher.Doc(docId);
string id = doc.Get("id");
item.Add(id);
}
Data list = account.selectUser(data, item.ToArray());
reader.Dispose();
searcher.Dispose();
return list;
}
示例5: PerformExplain
/// <summary>
/// Performs the explanation.
/// </summary>
/// <param name="luceneVersion">The lucene version.</param>
/// <param name="fsDirectory">The fs directory.</param>
/// <param name="searchQuery">The search query.</param>
/// <param name="resultId">The result identifier.</param>
/// <returns></returns>
protected virtual string PerformExplain(Version luceneVersion, FSDirectory fsDirectory, string searchQuery, int resultId)
{
/*
* The obvious problem here is that we're not using the exact same search as the real one.
*/
var explanation = string.Empty;
using (var indexSearcher = new IndexSearcher(fsDirectory, false))
{
var analyzer = new StandardAnalyzer(luceneVersion);
var queryParser = new MultiFieldQueryParser(luceneVersion, new[] { "Id".ToLowerInvariant() }, analyzer)
{
DefaultOperator = QueryParser.Operator.AND
};
var query = this.searchQueryParser.ParseQuery(searchQuery, queryParser);
explanation = indexSearcher.Explain(query, resultId).ToHtml();
analyzer.Close();
}
return explanation;
}
示例6: ParseQuery
private static Query ParseQuery(string searchTerm)
{
var fields = new Dictionary<string, float> { { "Id", 1.2f }, { "Title", 1.0f }, { "Tags", 1.0f}, { "Description", 0.8f }, { "Author", 0.6f } };
var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
searchTerm = QueryParser.Escape(searchTerm).ToLowerInvariant();
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields.Keys.ToArray(), analyzer, fields);
var conjuctionQuery = new BooleanQuery();
conjuctionQuery.SetBoost(1.5f);
var disjunctionQuery = new BooleanQuery();
var wildCardQuery = new BooleanQuery();
wildCardQuery.SetBoost(0.7f);
var exactIdQuery = new TermQuery(new Term("Id-Exact", searchTerm));
exactIdQuery.SetBoost(2.5f);
foreach(var term in searchTerm.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
{
conjuctionQuery.Add(queryParser.Parse(term), BooleanClause.Occur.MUST);
disjunctionQuery.Add(queryParser.Parse(term), BooleanClause.Occur.SHOULD);
foreach (var field in fields)
{
var wildCardTermQuery = new WildcardQuery(new Term(field.Key, term + "*"));
wildCardTermQuery.SetBoost(0.7f * field.Value);
wildCardQuery.Add(wildCardTermQuery, BooleanClause.Occur.SHOULD);
}
}
return conjuctionQuery.Combine(new Query[] { exactIdQuery, conjuctionQuery, disjunctionQuery, wildCardQuery });
}
示例7: CreateIndex
public void CreateIndex(List<ISearchEntity> CreateEntities)
{
Analyzer analyzer = new StandardAnalyzer();
IndexWriter writer = new IndexWriter(ConfigElement.IndexDirectory, analyzer, true);
//第三个参数:是否重新创建索引,True 一律清空 重新建立 False 原有基础上增量添加索引
foreach (ISearchEntity IndexEntity in CreateEntities)
{
NewsModel news = (NewsModel)IndexEntity;
Document doc = new Document();
doc.Add(new Field("newsid", Convert.ToString(news.EntityIdentity), Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.Add(new Field("title", Convert.ToString(news.Title), Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.Add(new Field("content", Convert.ToString(news.Content), Field.Store.YES, Field.Index.TOKENIZED));
doc.Add(new Field("keywords", Convert.ToString(news.Keywords), Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.Add(new Field("catepath", Convert.ToString(news.CategoryPath), Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.Add(new Field("createtime", Convert.ToString(news.CreateTime), Field.Store.YES, Field.Index.UN_TOKENIZED));
writer.AddDocument(doc);
Console.WriteLine("created index for {0}:{1}", news.EntityIdentity, news.Title);
}
writer.Optimize();
writer.Close();
}
示例8: button2_Click
private void button2_Click(object sender, EventArgs e)
{
String field = "content";
IndexReader reader = IndexReader.Open(FSDirectory.Open(new DirectoryInfo(INDEX_DIR.FullName)), true);
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, field, analyzer);
Query query = parser.Parse(textBox1.Text.Trim());
TopScoreDocCollector collector = TopScoreDocCollector.Create(searcher.MaxDoc, false);
searcher.Search(query, collector);
ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
MessageBox.Show(this, "共 " + collector.TotalHits.ToString() + " 条记录");
//ltrResult.Text = "共 " + collector.GetTotalHits().ToString() + " 条记录<br>";
//for (Int32 i = 0; i < collector.GetTotalHits(); i++)
//{
// ltrResult.Text += "doc=" + hits[i].doc + " score=" + hits[i].score + "<br>";
// Document doc = searcher.Doc(hits[i].doc);
// ltrResult.Text += "Path:" + doc.Get("path") + "<br>";
//}
reader.Dispose();
}
示例9: LuceneHighlightHelper
private LuceneHighlightHelper()
{
Separator = "...";
MaxNumHighlights = 5;
HighlightAnalyzer = new StandardAnalyzer(_luceneVersion);
HighlightFormatter = new SimpleHTMLFormatter("", " ");
}
示例10: 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[] { "title", "content", "keywords" }, analyzer);
Query queryName = parserName.Parse(searchInfo.QueryString);
Hits hits = searcher.Search(queryName);
List<ISearchEntity> ResultList = new List<ISearchEntity>();
for (int i = 0; i < hits.Length(); i++)
{
Document doc = hits.Doc(i);
ResultList.Add((ISearchEntity)new NewsModel()
{
EntityIdentity = Convert.ToInt32(doc.Get("newsid")),
Title = Convert.ToString(doc.Get("title")),
Content = Convert.ToString(doc.Get("content")),
Keywords = doc.Get("keywords")
});
}
searcher.Close();
MatchCount = hits.Length();
return ResultList;
}
示例11: Engine
public Engine()
{
var directory = new RAMDirectory();
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
using (var indexWriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED))
{
for (int i = 0; i < 10000; i++)
{
Console.Write(".");
var document = new Document();
document.Add(new Field("Id", i.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("Name", "Name" + i.ToString(), Field.Store.YES, Field.Index.ANALYZED));
indexWriter.AddDocument(document);
}
}
Console.ReadKey();
var queryParser = new QueryParser(Version.LUCENE_30, "Name", analyzer);
var query = queryParser.Parse("Name37~");
IndexReader indexReader = IndexReader.Open(directory, true);
var searcher = new IndexSearcher(indexReader);
TopDocs resultDocs = searcher.Search(query, indexReader.MaxDoc);
}
示例12: button1_Click
private void button1_Click(object sender, EventArgs e)
{
Directory index = new RAMDirectory();
StandardAnalyzer analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
IndexWriter w = new IndexWriter(index, analyzer);
addDoc(w, "Lucene in Action");
addDoc(w, "Lucene for Dummies");
addDoc(w, "Managing Gigabytes");
addDoc(w, "The Art of Computer Science");
w.Close();
String querystr = "Lucene in Action";
Query q = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "title", analyzer).Parse(querystr);
//q.Parse();
int hitsPerPage = 10;
IndexReader reader = IndexReader.Open(index,true);
IndexSearcher searcher = new IndexSearcher(reader);
TopScoreDocCollector collector = TopScoreDocCollector.Create(hitsPerPage, true);
searcher.Search(q, collector);
ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
System.Console.WriteLine("Found {0} Hits", hits.Length);
foreach (var item in hits)
{
int docId = item.Doc;
Document d = searcher.Doc(docId);
System.Console.WriteLine(d.Get("title") + " " + item.Score);
}
}
示例13: HelloWorldTest
public void HelloWorldTest()
{
Directory directory = new RAMDirectory();
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29);
IndexWriter writer = new IndexWriter(directory,
analyzer,
IndexWriter.MaxFieldLength.UNLIMITED);
Document doc = new Document();
doc.Add(new Field("id", "1", Field.Store.YES, Field.Index.NO));
doc.Add(new Field("postBody", "sample test", Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
writer.Optimize();
writer.Commit();
writer.Close();
QueryParser parser = new QueryParser(Version.LUCENE_29, "postBody", analyzer);
Query query = parser.Parse("sample test");
//Setup searcher
IndexSearcher searcher = new IndexSearcher(directory, true);
//Do the search
var hits = searcher.Search(query, null, 10);
for (int i = 0; i < hits.TotalHits; i++)
{
var doc1 = hits.ScoreDocs[i];
}
searcher.Close();
directory.Close();
}
示例14: GetAllMoviesWith
public void GetAllMoviesWith(string textSearch, int maxCount, out List<string> movies, out List<string> reviews, IList<string> filters = null)
{
reviews = new List<string>();
movies = new List<string>();
try
{
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var query = ParseQuery(textSearch, filters, analyzer);
var hits = _searcher.Search(query, 10);
if (hits == null)
{
Trace.TraceWarning("Search query {0} didn't generate any results", textSearch);
return;
}
else
{
Trace.TraceInformation("Results for search query {0} : hits {1} max score {2} score docs {3}", textSearch, hits.TotalHits, hits.MaxScore, hits.ScoreDocs);
foreach (var doc in hits.ScoreDocs)
{
GetIdsFromSearchQueries(_searcher.Doc(doc.Doc), movies, reviews);
}
}
}
catch (Exception err)
{
Trace.TraceError("Get all movies failed with exception {0}", err);
throw;
}
}
示例15: Search
IEnumerable<string> Search(string textToFind)
{
var reader = IndexReader.Open(_ramDirectory, true);
var searcher = new IndexSearcher(reader);
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
var parser = new MultiFieldQueryParser(Version.LUCENE_29, _searchFields, analyzer);
var query = parser.Parse(textToFind);
var collector = TopScoreDocCollector.create(100, true);
searcher.Search(query, collector);
var hits = collector.TopDocs().scoreDocs;
var foundKeys = new List<string>();
foreach (ScoreDoc scoreDoc in hits)
{
var document = searcher.Doc(scoreDoc.doc);
var key = document.Get(_keyField);
if (key != null && !foundKeys.Contains(key))
{
foundKeys.Add(key);
}
}
reader.Close();
searcher.Close();
analyzer.Close();
return foundKeys;
}