Beispiel #1
0
        public List <ResultData> Search(SingleFieldSearchViewModel sfsViewModel)
        {
            var    results    = new List <ResultData>();
            string fieldName  = sfsViewModel.FieldName.Trim();
            string fieldValue = sfsViewModel.FieldValue.Trim();

            QueryType   queryType = (QueryType)Enum.Parse(typeof(QueryType), sfsViewModel.QueryType);
            IndexerType type      = AnalyzerService.GetIndexerType(sfsViewModel.Language);

            try
            {
                Query query = QueryBuilder.BuildQuery(type, queryType, fieldName, fieldValue);
                InformationRetriever informationRetriever = new InformationRetriever(type, RAW_DIR_PATH, INDEX_DIR_PATH);

                var queriedHighlights = new List <string>()
                {
                    fieldName
                };

                results = informationRetriever.RetrieveEBooks(type, query, queriedHighlights, Sort.INDEXORDER);

                if (results.Count != 0)
                {
                    MapLanguageAndCategory(results);
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(results);
        }
Beispiel #2
0
        public List <ResultData> Search(MultiFieldSearchViewModel mfsViewModel)
        {
            var         results            = new List <ResultData>();
            var         requiredHighlights = new List <string>();
            var         booleanQuery       = new BooleanQuery();
            IndexerType type = AnalyzerService.GetIndexerType(mfsViewModel.Language);

            InformationRetriever informationRetriever = new InformationRetriever(type, RAW_DIR_PATH, INDEX_DIR_PATH);

            QueryType     queryType     = (QueryType)Enum.Parse(typeof(QueryType), mfsViewModel.QueryType);
            QueryOperator queryOperator = (QueryOperator)Enum.Parse(typeof(QueryOperator), mfsViewModel.QueryOperator);
            Occur         occur         = queryOperator.Equals(QueryOperator.AND)
                ? Occur.MUST
                : Occur.SHOULD;

            try
            {
                if (!string.IsNullOrEmpty(mfsViewModel.Title))
                {
                    requiredHighlights.Add("Title");
                    booleanQuery.Add(QueryBuilder.BuildQuery(type, queryType, "Title", mfsViewModel.Title.Trim()), occur);
                }

                if (!string.IsNullOrEmpty(mfsViewModel.Author))
                {
                    requiredHighlights.Add("Author");
                    booleanQuery.Add(QueryBuilder.BuildQuery(type, queryType, "Author", mfsViewModel.Author.Trim()), occur);
                }

                if (!string.IsNullOrEmpty(mfsViewModel.Keywords))
                {
                    requiredHighlights.Add("Keyword");
                    List <Query> queries = BuildQueriesForKeywords(type, queryType, occur, mfsViewModel.Keywords);
                    queries.ForEach(x => booleanQuery.Add(x, occur));
                }

                if (!string.IsNullOrEmpty(mfsViewModel.Content))
                {
                    requiredHighlights.Add("Content");
                    booleanQuery.Add(QueryBuilder.BuildQuery(type, queryType, "Content", mfsViewModel.Content.Trim()), occur);
                }

                if (!string.IsNullOrEmpty(mfsViewModel.Language))
                {
                    requiredHighlights.Add("Language");
                    booleanQuery.Add(QueryBuilder.BuildQuery(type, queryType, "Language", mfsViewModel.Language.Trim()), occur);
                }

                results = informationRetriever.RetrieveEBooks(type, booleanQuery, requiredHighlights, Sort.INDEXORDER);
            }
            catch (Exception e)
            {
                results = null;
            }

            return(results);
        }