Ejemplo n.º 1
0
        public IEnumerable <Document> Search(string stringQuery)
        {
            var queryExtractore = new BasicBoolQueryExtractor(stringQuery, "docText");
            var query           = queryExtractore.ExtractQuery();
            var searchResult    = index.RunSearchQuery(query);
            var resultDocuments = ConvertToDocument((IEnumerable <TextDocument>)searchResult);

            return(resultDocuments);
        }
        public void ExtractBoolQueryTestSingleMust()
        {
            var expectedResult =
                "{\"bool\":" +
                "{\"must\":[" +
                "{\"match\":{\"" + fieldName + "\":{\"query\":\"test\"}}}" +
                "]}" +
                "}";
            var queryExtractore = new BasicBoolQueryExtractor("test", fieldName);
            var query           = queryExtractore.ExtractQuery();
            var client          = new ElasticClient();
            var testResult      = client.RequestResponseSerializer.SerializeToString <QueryContainer>(query);

            Assert.Equal(expectedResult, testResult);
        }
        private void SearchingRoutine()
        {
            var doNotExit = "";

            do
            {
                var userQuery = "";
                do
                {
                    Console.WriteLine("Write your search query( '+' before filter means 'or', '-' before filter means 'not' and none of this signs before filter means 'and' ) or 'e' to exit:");
                    userQuery = Console.ReadLine();
                } while (string.IsNullOrWhiteSpace(userQuery));
                if (userQuery == "e")
                {
                    return;
                }
                var queryExtractore = new BasicBoolQueryExtractor(userQuery, "docText");
                var query           = queryExtractore.ExtractQuery();
                var searchResult    = index.RunSearchQuery(query);
                ShowSearchResult(searchResult);
                Console.WriteLine("Do you like to continue searching?( y / anything else ):");
                doNotExit = Console.ReadLine();
            } while (doNotExit == "y");
        }