public void Then_Assigns_Properties( SearchableStandard searchableStandard, float score) { var document = new Document(); foreach (var field in searchableStandard.GetFields()) { document.Add(field); } var result = new StandardSearchResult(document, score); result.StandardUId.Should().Be(document.GetField(nameof(StandardSearchResult.StandardUId)).GetStringValue()); result.Score.Should().Be(score); }
public void Then_Indexes_Nulls_To_Empty_String(string standardUId) { var source = new Standard { StandardUId = standardUId }; var expectedFields = new List <Field> { new StringField(nameof(SearchableStandard.StandardUId), source.StandardUId, Field.Store.YES), // phrase new TextField(SearchableStandard.TitlePhrase, "", Field.Store.NO) { Boost = 1000f }, new TextField(SearchableStandard.TypicalJobTitlesPhrase, "", Field.Store.NO) { Boost = 500f }, new TextField(SearchableStandard.KeywordsPhrase, "", Field.Store.NO) { Boost = 100f }, // term new TextField(SearchableStandard.TitleTerm, "", Field.Store.NO) { Boost = 40f }, new TextField(SearchableStandard.TypicalJobTitlesTerm, "", Field.Store.NO) { Boost = 20f }, new TextField(SearchableStandard.KeywordsTerm, "", Field.Store.NO), // soundex new TextField(SearchableStandard.TitleNGram, "", Field.Store.NO) { Boost = 10f } }; var searchable = new SearchableStandard(source); var fields = searchable.GetFields().ToList(); fields.Should().BeEquivalentTo(expectedFields); }
public void Build() { var standardAnalyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48); var pipeAnalyzer = new PipeAnalyzer(); var ngramAnalyzer = new EdgeNGramAnalyzer(); var fieldAnalyzers = new Dictionary <string, Analyzer> { //phrase { SearchableStandard.TitlePhrase, pipeAnalyzer }, { SearchableStandard.TypicalJobTitlesPhrase, pipeAnalyzer }, { SearchableStandard.KeywordsPhrase, pipeAnalyzer }, //term { SearchableStandard.TitleTerm, standardAnalyzer }, { SearchableStandard.TypicalJobTitlesTerm, standardAnalyzer }, { SearchableStandard.KeywordsTerm, standardAnalyzer }, //ngram { SearchableStandard.TitleNGram, ngramAnalyzer } }; var perFieldAnalyzerWrapper = new PerFieldAnalyzerWrapper(standardAnalyzer, fieldAnalyzers); var config = new IndexWriterConfig(LuceneVersion.LUCENE_48, perFieldAnalyzerWrapper); var directory = _directoryFactory.GetDirectory(); using (var writer = new IndexWriter(directory, config)) { writer.DeleteAll(); writer.Commit(); foreach (var standard in _coursesDataContext.Standards) { var doc = new Document(); var searchable = new SearchableStandard(standard); foreach (var indexableField in searchable.GetFields()) { doc.Add(indexableField); } writer.AddDocument(doc); writer.Commit(); } } }
public void Then_Indexes_Fields(Standard source) { var expectedFields = new List <Field> { new StringField(nameof(SearchableStandard.StandardUId), source.StandardUId, Field.Store.YES), // phrase new TextField(SearchableStandard.TitlePhrase, source.Title, Field.Store.NO) { Boost = 1000f }, new TextField(SearchableStandard.TypicalJobTitlesPhrase, source.TypicalJobTitles, Field.Store.NO) { Boost = 500f }, new TextField(SearchableStandard.KeywordsPhrase, source.Keywords, Field.Store.NO) { Boost = 100f }, // term new TextField(SearchableStandard.TitleTerm, source.Title, Field.Store.NO) { Boost = 40f }, new TextField(SearchableStandard.TypicalJobTitlesTerm, source.TypicalJobTitles, Field.Store.NO) { Boost = 20f }, new TextField(SearchableStandard.KeywordsTerm, source.Keywords, Field.Store.NO), // ngram new TextField(SearchableStandard.TitleNGram, source.Title, Field.Store.NO) { Boost = 10f }, }; var searchable = new SearchableStandard(source); var fields = searchable.GetFields().ToList(); fields.Should().BeEquivalentTo(expectedFields); }