本文整理汇总了C#中Lucene.Net.QueryParsers.QueryParser类的典型用法代码示例。如果您正苦于以下问题:C# QueryParser类的具体用法?C# QueryParser怎么用?C# QueryParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryParser类属于Lucene.Net.QueryParsers命名空间,在下文中一共展示了QueryParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Execute
public static ICollection<SearchResult> Execute(string query)
{
ICollection<SearchResult> searchResults = new List<SearchResult>();
string directoryPath = AppDomain.CurrentDomain.BaseDirectory + @"\App_Data\LuceneIndexes";
var directory = FSDirectory.Open(directoryPath);
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "SearchBody", analyzer);
Query searchQuery = parser.Parse(query + "*");
IndexSearcher searcher = new IndexSearcher(directory);
TopDocs hits = searcher.Search(searchQuery, 200);
int results = hits.ScoreDocs.Length;
for (int i = 0; i < results; i++)
{
Document doc = searcher.Doc(hits.ScoreDocs[i].Doc);
var searchResult = new SearchResult();
searchResult.EntityId = int.Parse(doc.Get("EntityId"));
searchResult.EntityTypeName = doc.Get("EntityTypeName");
searchResult.SearchTitle = doc.Get("SearchTitle");
searchResult.SearchBody = doc.Get("SearchBody");
searchResults.Add(searchResult);
}
searcher.Dispose();
directory.Dispose();
return searchResults;
}
开发者ID:szwork2013,项目名称:BoiPlt,代码行数:29,代码来源:FullTextSearch.cs
示例2: ResultTransformToDelimString
public void ResultTransformToDelimString()
{
IFullTextSession s = Search.CreateFullTextSession(this.OpenSession());
this.PrepEmployeeIndex(s);
s.Clear();
ITransaction tx = s.BeginTransaction();
QueryParser parser = new QueryParser("Dept", new StandardAnalyzer());
Query query = parser.Parse("Dept:ITech");
IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Employee));
hibQuery.SetProjection(
"Id",
"Lastname",
"Dept",
ProjectionConstants.THIS,
ProjectionConstants.SCORE,
ProjectionConstants.BOOST,
ProjectionConstants.ID);
hibQuery.SetResultTransformer(new ProjectionToDelimStringResultTransformer());
IList result = hibQuery.List();
Assert.IsTrue(((string)result[0]).StartsWith("1000, Griffin, ITech"), "incorrect transformation");
Assert.IsTrue(((string)result[1]).StartsWith("1002, Jimenez, ITech"), "incorrect transformation");
// cleanup
s.Delete("from System.Object");
tx.Commit();
s.Close();
}
开发者ID:kstenson,项目名称:NHibernate.Search,代码行数:30,代码来源:ProjectionQueryTest.cs
示例3: Query
public Task<List<TestDocument>> Query(string q)
{
QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "text", Analyzer);
Query query = parser.Parse(q);
IndexSearcher searcher = new IndexSearcher(Index, true);
//Do the search
TopDocs docs = searcher.Search(query, 10);
int results = docs.TotalHits;
List<TestDocument> ret = new List<TestDocument>();
for (int i = 0; i < results; i++)
{
ScoreDoc d = docs.ScoreDocs[i];
float score = d.Score;
Document idoc = searcher.Doc(d.Doc);
ret.Add(new TestDocument()
{
Id = Convert.ToInt32(idoc.GetField("id").StringValue),
Text = idoc.GetField("text").StringValue
});
}
searcher.Dispose();
return Task.FromResult(ret);
}
开发者ID:adhurwit,项目名称:SearchFabric,代码行数:25,代码来源:SearchFabricIndex.cs
示例4: Main
public static void Main(string[] args)
{
BasicConfigurator.Configure();
//using (var reader = new MsmqLogReader(new Uri("msmq://localhost/test_queue2")))
//{
// reader.Start();
// Console.ReadLine();
//}
var searcher = new IndexSearcher("messages");
var parser = new QueryParser("", new StandardAnalyzer());
//var query = parser.Parse("MessageId:\"b5005080-800c-43c3-a20b-16db773d7663\" AND MessageId:2307015");
var query = parser.Parse("Timestamp:[\"2008-12-16T08:14:53.9749900\" TO \"2008-12-16T08:14:53.6343650\"]");
var hits = searcher.Search(query);
for (int i = 0; i < hits.Length(); i++)
{
var doc = hits.Doc(i);
Console.WriteLine();
foreach (Fieldable field in doc.GetFields())
{
Console.WriteLine("{0}: {1}", field.Name(), field.StringValue());
}
Console.WriteLine();
}
}
开发者ID:brumschlag,项目名称:rhino-tools,代码行数:27,代码来源:Program.cs
示例5: PerformAmountSearch
public void PerformAmountSearch(string strQuery, out string[] datesArray, out int[] amountsArray)
{
List<Document> tweets = new List<Document>();
List<string> dates = new List<string>();
List<int> amounts = new List<int>();
int amount = 0;
Query query = new QueryParser("text", an).Parse(strQuery);
Hits results = searcher.Search(query,Sort.INDEXORDER);
for (int i = 0; i < results.Length(); i++)
{
Document doc = results.Doc(i);
string date = DateTime.Parse(doc.Get("created")).Date.ToString();
if (!dates.Contains(date))
{
if (dates.Count > 0)
{
amounts.Add(amount);
}
amount = 0;
dates.Add(date);
}
amount++;
}
amounts.Add(amount);
datesArray = dates.ToArray();
amountsArray = amounts.ToArray();
}
开发者ID:peac3maker,项目名称:TwitterSentimentAnalysis,代码行数:27,代码来源:TwitterFeedSearch.cs
示例6: SearchBIMXchange
public static LuceneResult SearchBIMXchange(string field, string key, int pageSize, int pageNumber)
{
const string luceneIndexPath = "C:\\LuceneIndex";
var directory = FSDirectory.Open(new DirectoryInfo(luceneIndexPath));
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
var parser = new QueryParser(Version.LUCENE_29, field, analyzer);
var query = parser.Parse(String.Format("{0}*", key));
var searcher = new IndexSearcher(directory, true);
var topDocs = searcher.Search(query, 1000000);
var docs = new List<Document>();
var start = (pageNumber-1)*pageSize;
for (var i = start; i < start + pageSize && i < topDocs.TotalHits; i++)
{
var scoreDoc = topDocs.ScoreDocs[i];
var docId = scoreDoc.doc;
var doc = searcher.Doc(docId);
docs.Add(doc);
}
searcher.Close();
directory.Close();
var result = new LuceneResult {Results = docs, TotalCount = topDocs.TotalHits};
return result;
}
开发者ID:joelkarr,项目名称:ENGworks,代码行数:30,代码来源:Search.cs
示例7: Search
public SearchResult[] Search(string searchString)
{
Analyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Version.LUCENE_29);
QueryParser parser = new QueryParser(Version.LUCENE_29, "Content", analyzer);
var query = parser.Parse(searchString);
Searcher searcher = new IndexSearcher(Lucene.Net.Index.IndexReader.Open(directory, true));
TopScoreDocCollector collector = TopScoreDocCollector.Create(100, true);
searcher.Search(query, collector);
var hits = collector.TopDocs().ScoreDocs;
List<SearchResult> results = new List<SearchResult>();
for (int i = 0; i < hits.Length; i++)
{
int docId = hits[i].Doc;
float score = hits[i].Score;
Lucene.Net.Documents.Document doc = searcher.Doc(docId);
results.Add(new SearchResult
{
BookId = Guid.Parse(doc.Get("BookId")),
Score = score
});
}
return results.ToArray();
}
开发者ID:gedgei,项目名称:BookDbSharp,代码行数:33,代码来源:BookSearchService.cs
示例8: btnExecuteSearch_Click
private void btnExecuteSearch_Click(object sender, EventArgs e)
{
Directory indexDirectory = FSDirectory.Open(new System.IO.DirectoryInfo(tempPath));
IndexSearcher searcher = new IndexSearcher(indexDirectory, true); // read-only=true
// TODO: QueryParser support for Hebrew terms (most concerning issue is with acronyms - mid-word quotes)
QueryParser qp = new QueryParser("content", analyzer);
qp.SetDefaultOperator(QueryParser.Operator.AND);
Query query = qp.Parse(txbSearchQuery.Text);
ScoreDoc[] hits = searcher.Search(query, null, 1000).scoreDocs;
// Iterate through the results:
BindingList<SearchResult> l = new BindingList<SearchResult>();
for (int i = 0; i < hits.Length; i++)
{
Document hitDoc = searcher.Doc(hits[i].doc);
SearchResult sr = new SearchResult(hitDoc.GetField("title").StringValue(),
hitDoc.GetField("path").StringValue(), hits[i].score);
l.Add(sr);
}
searcher.Close();
indexDirectory.Close();
dgvResults.DataSource = l;
}
开发者ID:igaler,项目名称:SlovaMorph,代码行数:27,代码来源:MainForm.cs
示例9: 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);
}
}
开发者ID:samfisher83,项目名称:lucene,代码行数:34,代码来源:Form1.cs
示例10: 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();
}
开发者ID:oleksii-mdr,项目名称:nTextNetwork,代码行数:32,代码来源:HelloWorldLuceneTest.cs
示例11: LuceneSearchDeps
internal LuceneSearchDeps(SearcherManager searcherManager, QueryParser parser, IMetaDataResolver resolver, IQueue queue)
{
this.SearcherManager = searcherManager;
this.Parser = parser;
this.Resolver = resolver;
this.Queue = queue;
}
开发者ID:daszat,项目名称:zetbox,代码行数:7,代码来源:Module.cs
示例12: 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);
}
开发者ID:trulstveoy,项目名称:Sandbox,代码行数:27,代码来源:Engine.cs
示例13: ClassBridge
public void ClassBridge()
{
ISession s = this.OpenSession();
ITransaction tx = s.BeginTransaction();
s.Save(this.getDept1());
s.Save(this.getDept2());
s.Save(this.getDept3());
s.Flush();
tx.Commit();
tx = s.BeginTransaction();
IFullTextSession session = Search.CreateFullTextSession(s);
// The branchnetwork field is the concatenation of both
// the branch field and the network field of the Department
// class. This is in the Lucene document but not in the
// Department entity itself.
QueryParser parser = new QueryParser("branchnetwork", new SimpleAnalyzer());
Query query = parser.Parse("branchnetwork:layton 2B");
IFullTextQuery hibQuery = session.CreateFullTextQuery(query, typeof(Department));
IList result = hibQuery.List();
Assert.IsNotNull(result);
Assert.AreEqual("2B", ((Department)result[0]).Network, "incorrect entity returned, wrong network");
Assert.AreEqual("Layton", ((Department)result[0]).Branch, "incorrect entity returned, wrong branch");
Assert.AreEqual(1, result.Count, "incorrect number of results returned");
// Partial match.
query = parser.Parse("branchnetwork:3c");
hibQuery = session.CreateFullTextQuery(query, typeof(Department));
result = hibQuery.List();
Assert.IsNotNull(result);
Assert.AreEqual("3C", ((Department)result[0]).Network, "incorrect entity returned, wrong network");
Assert.AreEqual("West Valley", ((Department)result[0]).Branch, "incorrect entity returned, wrong branch");
Assert.AreEqual(1, result.Count, "incorrect number of results returned");
// No data cross-ups .
query = parser.Parse("branchnetwork:Kent Lewin");
hibQuery = session.CreateFullTextQuery(query, typeof(Department));
result = hibQuery.List();
Assert.IsNotNull(result);
Assert.IsTrue(result.Count == 0, "problem with field cross-ups");
// Non-ClassBridge field.
parser = new QueryParser("BranchHead", new SimpleAnalyzer());
query = parser.Parse("BranchHead:Kent Lewin");
hibQuery = session.CreateFullTextQuery(query, typeof(Department));
result = hibQuery.List();
Assert.IsNotNull(result);
Assert.IsTrue(result.Count == 1, "incorrect entity returned, wrong branch head");
Assert.AreEqual("Kent Lewin", ((Department)result[0]).BranchHead, "incorrect entity returned");
// Cleanup
foreach (object element in s.CreateQuery("from " + typeof(Department).FullName).List())
{
s.Delete(element);
}
tx.Commit();
s.Close();
}
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:60,代码来源:ClassBridgeTest.cs
示例14: TestBasicQueryParser
public void TestBasicQueryParser()
{
var query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "description", new SimpleAnalyzer())
.Parse("partnum:Q36 AND SPACE");
Assert.AreEqual("+partnum:q +description:space", query.ToString(), "note Q36 -> q");
Assert.AreEqual(0, searcher.Search(query, 10).ScoreDocs.Length, "doc not found :(");
}
开发者ID:diegocaxito,项目名称:LuceneTest,代码行数:7,代码来源:KeywordAnalyzerTest.cs
示例15: Find
public SearchResults Find(string terms)
{
Directory directory = FSDirectory.GetDirectory("./index",false);
// Now search the index:
var isearcher = new IndexSearcher(directory);
// Parse a simple query that searches for "text":
//Query query = QueryParser.Parse("text", "fieldname", analyzer);
var qp = new QueryParser("description", _analyzer);
Query query = qp.Parse(terms);
Hits hits = isearcher.Search(query);
var sr = new SearchResults();
// Iterate through the results:
for (int i = 0; i < hits.Length(); i++)
{
Document hitDoc = hits.Doc(i);
sr.Add(new Result() { Name = hitDoc.Get("name"), Description = hitDoc.Get("description") });
}
isearcher.Close();
directory.Close();
return sr;
}
开发者ID:drusellers,项目名称:biblioteca,代码行数:26,代码来源:LuceneSearch.cs
示例16: Search
public IEnumerable<Hit> Search(string query, int maxResults)
{
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
QueryParser qp = new QueryParser(
Lucene.Net.Util.Version.LUCENE_29,
"contents",
analyzer
);
Query q = qp.Parse(query);
TopDocs top = searcher.Search(q, maxResults);
List<Hit> result = new List<Hit>(top.totalHits);
for (int index = 0; index < top.totalHits; index++)
{
var doc = searcher.Doc(top.scoreDocs[index].doc);
string contents = doc.Get("contents");
var scorer = new QueryScorer(q, searcher.GetIndexReader(), "contents");
var highlighter = new Highlighter(scorer);
result.Add(new Hit()
{
Relevance = top.scoreDocs[index].score,
Title = doc.Get("title"),
Url = doc.Get("path"),
Excerpt = highlighter.GetBestFragment(analyzer, "contents", contents)
});
}
return result;
}
开发者ID:justinrobinson,项目名称:totalrecall,代码行数:33,代码来源:SearchEngine.cs
示例17: Search
public ISearchResult Search(string query)
{
var timer = new Stopwatch();
timer.Start();
var directory = FSDirectory.Open(new DirectoryInfo(path));
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
var searcher = new IndexSearcher(directory, true);
var queryParser = new QueryParser(Version.LUCENE_29, "text", analyzer);
var result = searcher.Search(queryParser.Parse(query), 20);
var docs = (from scoreDoc in result.scoreDocs
let doc = searcher.Doc(scoreDoc.doc)
let fields = new Dictionary<string, string> { { "title", doc.Get("title") }, { "text", doc.Get("text") } }
select new LuceneDocument { Id = scoreDoc.doc.ToString(), Fields = fields }).ToList();
var ret = new SearchResult { Query = query, Total = result.totalHits, Documents = docs, Source = Name };
searcher.Close();
directory.Close();
timer.Stop();
ret.Duration = (decimal) timer.Elapsed.TotalSeconds;
return ret;
}
开发者ID:billings-dot-net-users-group,项目名称:search-demo,代码行数:27,代码来源:LuceneIndex.cs
示例18: Search
public Task<SearchResultCollection> Search(string search)
{
return System.Threading.Tasks.Task.Run(() =>
{
var src = new SearchResultCollection();
if (string.IsNullOrWhiteSpace(search)) return src;
try
{
var parser = new QueryParser(Version.LUCENE_30,"All", analyzer);
Query q = new TermQuery(new Term("All", search));
using (var indexSearcher = new IndexSearcher(directory, true))
{
Query query = parser.Parse(search);
TopDocs result = indexSearcher.Search(query, 50);
foreach (ScoreDoc h in result.ScoreDocs)
{
Document doc = indexSearcher.Doc(h.Doc);
string id = doc.Get("id");
BaseContent value;
if (LookupTable.TryGetValue(id, out value)) src.Add(new SearchResult {Relevance = h.Score, Content = value});
}
}
}
catch (Exception e)
{
Logger.Log("DataServer","Error lucene search",e.Message,Logger.Level.Error);
}
return src;
});
}
开发者ID:TNOCS,项目名称:csTouch,代码行数:34,代码来源:LuceneSearch.cs
示例19: ObjectNotFound
public void ObjectNotFound()
{
ISession sess = OpenSession();
ITransaction tx = sess.BeginTransaction();
Author author = new Author();
author.Name = "Moo Cow";
sess.Persist(author);
tx.Commit();
sess.Clear();
IDbCommand statement = sess.Connection.CreateCommand();
statement.CommandText = "DELETE FROM Author";
statement.ExecuteNonQuery();
IFullTextSession s = Search.CreateFullTextSession(sess);
tx = s.BeginTransaction();
QueryParser parser = new QueryParser("title", new KeywordAnalyzer());
Lucene.Net.Search.Query query = parser.Parse("name:moo");
IFullTextQuery hibQuery = s.CreateFullTextQuery(query, typeof(Author), typeof(Music));
IList result = hibQuery.List();
Assert.AreEqual(0, result.Count, "Should have returned no author");
foreach (object o in result)
{
s.Delete(o);
}
tx.Commit();
s.Close();
}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:31,代码来源:ObjectLoaderTest.cs
示例20: getNotesMatchingTitle
public ArrayList getNotesMatchingTitle(string search)
{
ArrayList snotes = new ArrayList ();
try {
QueryParser parser = new QueryParser ("title", analyzer);
string lucsearch = search + "*^4" + " content:" + search + "*";
Query query = parser.Parse (lucsearch);
IndexSearcher searcher = new IndexSearcher (lucIdx);
Hits hits = searcher.Search (query);
int results = hits.Length ();
Console.WriteLine ("Found {0} results", results);
for (int i = 0; i < results; i++) {
Document doc = hits.Doc (i);
//float score = hits.Score (i);
snotes.Add (new Note (doc.Get ("title"), doc.Get ("lastmod")));
}
} catch (Exception e) {
Console.WriteLine ("ERROR Search: " + e.Message);
}
return snotes;
}
开发者ID:mzehrer,项目名称:monovel,代码行数:26,代码来源:FilesystemNotesStore.cs
注:本文中的Lucene.Net.QueryParsers.QueryParser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论