Пример #1
0
        public GroupedParseResult Parse(String query, Int32 languageId)
        {
            logger.LogQuery(query, languageId);

            string rest;
            List<ParseToken> parseRes = queryParser.Parse(query, languageId, out rest);

            GroupedParseResult res = new GroupedParseResult();

            StringBuilder sb = new StringBuilder();
            sb.Append(rest).Append(" ");

            foreach (ParseToken token in parseRes)
            {
                Word word = words[token.termId];
                int otid = word.termTypeId;

                Console.WriteLine(token.text + " " + word.title + " " + otid);

                if (otid <= 7)
                {
                    if (geoSimilarity.ContainsUID(word.geoplaceId)) res.geoTokens.Add(token);
                    else sb.Append(token.text).Append(" ");
                }
                else if (otid == 12) res.accTokens.Add(token);
                else if (otid == 13) res.capacityTokens.Add(token);
                else if (otid == 14) res.priceTokens.Add(token);
                else if (otid == 15) res.dateTokens.Add(token);
                else sb.Append(token.text).Append(" ");
            }

            Console.WriteLine("\nAccommodation:");
            foreach (ParseToken t in res.accTokens) Console.WriteLine(" " + t.termId + " | " + t.text);

            Console.WriteLine("\nGeo:");
            foreach (ParseToken t in res.geoTokens) Console.WriteLine(" " + t.termId + " | " + t.text);

            Console.WriteLine("Price:");
            foreach (ParseToken t in res.priceTokens) Console.WriteLine(" " + t.termId + " | " + t.text);

            Console.WriteLine("Capacity:");
            foreach (ParseToken t in res.capacityTokens) Console.WriteLine(" " + t.termId + " | " + t.text);

            Console.WriteLine("Date:");
            foreach (ParseToken t in res.dateTokens) Console.WriteLine(" " + t.termId + " | " + t.text);

            Console.WriteLine("Rest: ");
            Console.WriteLine(" " + sb.ToString() + "\n");

            res.rest = sb.ToString().Trim();

            return res;
        }
Пример #2
0
 public SearchResult(String q, Int32 l, List<Int32> i, GroupedParseResult p, int n)
 {
     query = q;
     languageId = l;
     advertIds = i;
     parseRes = p;
     numRes = n;
 }
Пример #3
0
        public List<AdvertScore> SearchParsed(GroupedParseResult parsedResults, int languageId)
        {
            List<AdvertScore> scores = new List<AdvertScore>();

            textSimilarity.ProcessQuery(parsedResults.rest, languageId);

            foreach (Advert ad in advertList.GetAllAdverts().Values)
            {
                if (ad.languageId != languageId) continue;

                AdvertScore score = new AdvertScore();
                score.advertId = ad.id;

                // 1. Text search.
                score.textScore = textSimilarity.GetScore(ad.id);

                // 2. Geo.
                score.geoScore = CalculateGeoScore(ad, parsedResults.geoTokens);

                // 3. Price.
                score.priceScore = priceSimilarity.CalculateScore(ad, parsedResults.priceTokens);

                // 4. Capacity.
                score.capacityScore = capacitySimilarity.CalculateScore(ad, parsedResults.capacityTokens);

                // 5. Date.
                score.dateScore = dateSimilarity.CalculateScore(ad, parsedResults.dateTokens);

                // 6. Accommodation.
                score.accScore = accSimilarity.CalculateScore(ad, parsedResults.accTokens);

                if (score.TotalScore() < 1) continue;
                ad.score = score;

                scores.Add(score);
            }

            scores.Sort();
            scores.Reverse();

            return scores;
        }