Note that there are some explanatory texts on larger screens.

plurals
  1. POLucene .NET search results
    primarykey
    data
    text
    <p>I'm using this code to index:</p> <pre><code>public void IndexEmployees(IEnumerable&lt;Employee&gt; employees) { var indexPath = GetIndexPath(); var directory = FSDirectory.Open(indexPath); var indexWriter = new IndexWriter(directory, new StandardAnalyzer(Version.LUCENE_29), true, IndexWriter.MaxFieldLength.UNLIMITED); foreach (var employee in employees) { var document = new Document(); document.Add(new Field("EmployeeId", employee.EmployeeId.ToString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); document.Add(new Field("Name", employee.FirstName + " " + employee.LastName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO)); document.Add(new Field("OfficeName", employee.OfficeName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO)); document.Add(new Field("CompetenceRatings", string.Join(" ", employee.CompetenceRatings.Select(cr =&gt; cr.Name)), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO)); indexWriter.AddDocument(document); } indexWriter.Optimize(); indexWriter.Close(); var indexReader = IndexReader.Open(directory, true); var spell = new SpellChecker.Net.Search.Spell.SpellChecker(directory); spell.ClearIndex(); spell.IndexDictionary(new LuceneDictionary(indexReader, "Name")); spell.IndexDictionary(new LuceneDictionary(indexReader, "OfficeName")); spell.IndexDictionary(new LuceneDictionary(indexReader, "CompetenceRatings")); } public DirectoryInfo GetIndexPath() { return new DirectoryInfo(HttpContext.Current.Server.MapPath("/App_Data/EmployeeIndex/")); } </code></pre> <p>And this code to find results (as well as suggestions):</p> <pre><code>public SearchResult Search(DirectoryInfo indexPath, string[] searchFields, string searchQuery) { var directory = FSDirectory.Open(indexPath); var standardAnalyzer = new StandardAnalyzer(Version.LUCENE_29); var indexReader = IndexReader.Open(directory, true); var indexSearcher = new IndexSearcher(indexReader); var parser = new MultiFieldQueryParser(Version.LUCENE_29, searchFields, standardAnalyzer); //parser.SetDefaultOperator(QueryParser.Operator.OR); var query = parser.Parse(searchQuery); var hits = indexSearcher.Search(query, null, 5000); return new SearchResult { Suggestions = FindSuggestions(indexPath, searchQuery), LuceneDocuments = hits .scoreDocs .Select(scoreDoc =&gt; indexSearcher.Doc(scoreDoc.doc)) .ToArray() }; } public string[] FindSuggestions(DirectoryInfo indexPath, string searchQuery) { var directory = FSDirectory.Open(indexPath); var spell = new SpellChecker.Net.Search.Spell.SpellChecker(directory); var similarWords = spell.SuggestSimilar(searchQuery, 20); return similarWords; } var searchResult = Search(GetIndexPath(), new[] { "Name", "OfficeName", "CompetenceRatings" }, "admin*"); </code></pre> <p>Simple queries like: admin or admin* doesnt give me any results. I know that there is an employee with that name. I want to be able to find James Jameson if I search for James.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload