public void ReturnOneResultWhenSearchingByKeyExplicitly() { /* * NOTE: This test uses a manual build-up just as an example. */ // Arrange var config = new SearchServiceConfiguration(Version.LUCENE_30, IndexWriter.MaxFieldLength.UNLIMITED, @"C:\SearchIndex\", "write.lock", 1000); var parser = new SearchQueryParser(); var searchService = new SearchService<Foo, FooSearchData>( config, new SearchIndexClearer(), new SearchIndexOptimizer(), new Searcher<FooSearchData>(parser, new DocumentToFooSearchDataTypeConverter()), new SearchIndexUpdater<Foo, FooSearchData>(new FooSearchDataToDocumentTypeConverter(), new FooToFooSearchDataTypeConverter()), new SearchScoreExplainer(parser)); searchService.ClearIndex(); var entities = new List<Foo> { new Foo{Key = "123", Parrot = "SQUAWK!", Bar = "Cheers"} }; searchService.UpdateIndex(entities); // Act var results = searchService.Search("key:123"); // Assert Assert.That(results.TotalHitCount == 1); }
public void ReturnOneResultWhenSearchingByKeyExplicitly() { /* * NOTE: This test uses a manual build-up just as an example. */ // Arrange var config = new SearchServiceConfiguration(Version.LUCENE_30, IndexWriter.MaxFieldLength.UNLIMITED, @"C:\SearchIndex\", "write.lock", 1000); var parser = new SearchQueryParser(); var searchService = new SearchService <Foo, FooSearchData>( config, new SearchIndexClearer(), new SearchIndexOptimizer(), new Searcher <FooSearchData>(parser, new DocumentToFooSearchDataTypeConverter()), new SearchIndexUpdater <Foo, FooSearchData>(new FooSearchDataToDocumentTypeConverter(), new FooToFooSearchDataTypeConverter()), new SearchScoreExplainer(parser)); searchService.ClearIndex(); var entities = new List <Foo> { new Foo { Key = "123", Parrot = "SQUAWK!", Bar = "Cheers" } }; searchService.UpdateIndex(entities); // Act var results = searchService.Search("key:123"); // Assert Assert.That(results.TotalHitCount == 1); }
public static SearchType InferResultType(this string query) { if (string.IsNullOrWhiteSpace(query)) { return(SearchType.Unknown); } return(SearchQueryParser.InferSearchType(query.Trim())); }
//--- Constructors --- public SearchBL(IDekiDataSession session, IKeyValueCache cache, string wikiid, XUri apiUri, Plug searchPlug, UserBE user, IInstanceSettings settings, SearchQueryParser parser, Func <bool> adaptiveSearchEnabled, ILog log) { _log = log; _session = session; _cache = cache; _wikiid = wikiid; _apiUri = apiUri; _searchPlug = searchPlug; _user = user; _settings = settings; _parser = parser; _adaptiveSearchEnabled = adaptiveSearchEnabled; }
public void should_parse_free_text_and_fields() { // given string text = "ducks yellow author:chorizo green date:2018 blue"; SearchQueryParser searchQueryParser = CreateParser(); // when ParsedQueryResult queryResult = searchQueryParser.ParseQuery(text); // then queryResult.OriginalText.ShouldBe(text); queryResult.TextWithoutFields.ShouldBe("ducks yellow green blue"); queryResult.Fields.Count().ShouldBe(2); }
public void should_parse_fields_with_quotes() { // given string text = "some text tags:\"make,brexit,great,again\""; SearchQueryParser searchQueryParser = CreateParser(); // when ParsedQueryResult queryResult = searchQueryParser.ParseQuery(text); // then queryResult.OriginalText.ShouldBe(text); queryResult.TextWithoutFields.ShouldBe("some text"); queryResult.Fields.Count().ShouldBe(1); var tagsField = queryResult.Fields.First(x => x.Name == "tags"); tagsField.ShouldNotBeNull(); tagsField.Value.ShouldBe("\"make,brexit,great,again\""); }
public void should_parse_multiple_fields() { // given string text = "author:donald date:now title:headache some text"; SearchQueryParser searchQueryParser = CreateParser(); // when ParsedQueryResult queryResult = searchQueryParser.ParseQuery(text); // then queryResult.OriginalText.ShouldBe(text); queryResult.TextWithoutFields.ShouldBe("some text"); queryResult.Fields.Count().ShouldBe(3); var tagsField = queryResult.Fields.First(x => x.Name == "title"); tagsField.ShouldNotBeNull(); tagsField.Value.ShouldBe("headache"); }
public async Task <IEnumerable <SearchablePage> > Find(string query) { var p = new SearchQueryParser(); ParsedQueryResult queryResult = p.ParseQuery(query); using (var session = _documentStore.QuerySession()) { var martenQuery = session.Query <SearchablePage>().Where(x => true); if (!string.IsNullOrEmpty(queryResult.TextWithoutFields)) { martenQuery = martenQuery.Where(x => x.PlainTextSearch(queryResult.TextWithoutFields)); } string title = queryResult.GetFieldValue("title"); if (!string.IsNullOrEmpty(title)) { martenQuery = martenQuery.Where(x => x.Title.PlainTextSearch(title)); } string tags = queryResult.GetFieldValue("tags"); if (!string.IsNullOrEmpty(tags)) { martenQuery = martenQuery.Where(x => x.PlainTextSearch(tags)); } string pageId = queryResult.GetFieldValue("pageId"); if (!string.IsNullOrEmpty(pageId)) { martenQuery = martenQuery.Where(x => x.PageId.PlainTextSearch(pageId)); } string author = queryResult.GetFieldValue("author"); if (!string.IsNullOrEmpty(pageId)) { martenQuery = martenQuery.Where(x => x.Author.PlainTextSearch(author)); } return(await martenQuery.ToListAsync()); } }
static void Main(string[] args) { var laptops = DataParser.ParseLaptopJson("../../../goods_data.json"); var dataStorage = new DataStorage(); dataStorage.SetLaptops(laptops); var searchParser = new SearchQueryParser(); var searcher = new Searcher(searchParser, dataStorage); while (true) { Console.WriteLine("type your query"); var entered = Console.ReadLine(); if (entered == "exit") { break; } else { var result = searcher.Search(entered); if (string.IsNullOrWhiteSpace(result.Error)) { if (result.Laptops.Count > 0) { Console.WriteLine("your result: "); PrintResult(result.Laptops); } else { Console.WriteLine("nothing found"); } } else { Console.WriteLine(result.Error); } } } }
/// <summary> /// The poll to the API to retrieve the data /// </summary> private IEnumerator GetText(string uri) { using (UnityWebRequest www = UnityWebRequest.Get(uri)) { yield return(www.Send()); if (www.isNetworkError || www.isHttpError) { Debug.LogError(www.error); } else { if (DataRecieved == null) { yield break; } // Broadcast results SearchQueryParser parser = new SearchQueryParser(www.downloadHandler.text, false); DataRecieved(parser); } } }
public InternalSearchService() { _parser = new SearchQueryParser(); _searchers.Add(new DbQuestionSearchStrategy()); _searchers.Add(new DbTopicSearchStrategy()); }
public SearchQueryParserTest(SearchQueryParserTestFixture fixture) { parser = fixture.Parser; }
public SearchQueryParserTestFixture() { Parser = new SearchQueryParser(GetService <ILogger <SearchQueryParser> >()); }
private void OnDataRecieved(SearchQueryParser parser) { result = parser; UpdateList(); manager.DataRecieved -= OnDataRecieved; }
public Searcher(SearchQueryParser searchParser, DataStorage dataStorage) { _searchParser = searchParser; _dataStorage = dataStorage; }