Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 941309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:06:01+00:00 2026-05-15T22:06:01+00:00

I’m developing a very basic web search engine that has several parts. After retrieving

  • 0

I’m developing a very basic web search engine that has several parts. After retrieving results according to a user query, I want to calculate rate of each result and then sort results by calculated rate. Here is my query:

var tmpQuery = (from urls in _context.Urls
                join documents in _context.Documents
                  on urls.UrlId equals documents.DocumentId
                let words = (from words in _context.Words
                             join hits in _context.Hits
                               on words.WordId equals hits.WordId
                             where hits.DocumentId == documents.DocumentId
                             select words.Text)
                select new { urls, documents, words });

var results = (from r in tmpQuery.AsEnumerable()
               where r.urls.ResolvedPath.Contains(breakedQuery, KeywordParts.Url, part) ||
                     r.documents.Title.Contains(breakedQuery, KeywordParts.Title, part) ||
                     r.documents.Keywords.Contains(breakedQuery, KeywordParts.Keywords, part) ||
                     r.documents.Description.Contains(breakedQuery, Description, part) ||
                     r.words.Contains(breakedQuery, KeywordParts.Content, part)

                     select new SearchResult()
                     {
                        UrlId = r.urls.UrlId,
                        Url = r.urls.ResolvedPath,
                        IndexedOn = r.documents.IndexedOn,
                        Title = r.documents.Title,
                        Description = r.documents.Description,
                        Host = new Uri(r.urls.ResolvedPath).Host,
                        Length = r.documents.Length,
                        Rate = 0CalculateRating(breakedQuery, r.urls.ResolvedPath, r.documents.Title, r.documents.Keywords, r.documents.Description, r.words)
                     }).AsEnumerable()
                     .OrderByDescending(result => result.Rate)
                     .Distinct(new SearchResultEqualityComparer());

and rate is calculated by this method:

private int CalculateRating(IEnumerable<string> breakedQuery, string resolvedPath, string title, string keywords, string description, IEnumerable<string> words)
    {
        var baseRate = 0;

        foreach (var query in breakedQuery)
        {
            /*first I'm breaking up user raw query (Microsoft -Apple) to list of broken
            queries (Microsoft, -Apple) if broken query start with - that means
            results shouldn't have*/
            var none = (query.StartsWith("-"));
            string term = query.Replace("-", "");

            var pathCount = Calculate(resolvedPath, term);
            var titleCount = Calculate(title, term);
            var keywordsCount = Calculate(keywords, term);
            var descriptionCount = Calculate(description, term);
            var wordsCount = Calculate(words, term);

            var result = (pathCount * 100) + (titleCount * 50) + (keywordsCount * 25) + (descriptionCount * 10) + (wordsCount);

            if (none)
                baseRate -= result;
            else
                baseRate += result;
        }
        return baseRate;
    }

    private int Calculate(string source, string query)
    {
        if (!string.IsNullOrWhiteSpace(source))
            return Calculate(source.Split(' ').AsEnumerable<string>(), query);
        return 0;
    }

    private int Calculate(IEnumerable<string> sources, string query)
    {
        var count = 0;
        if (sources != null && sources.Count() > 0)
        {
            //to comparing two strings
            //first case sensitive
            var elements = sources.Where(source => source == query);
            count += elements.Count();
            //second case insensitive (half point of sensitive)
            count += sources.Except(elements).Where(source => source.ToLowerInvariant() == query.ToLowerInvariant()).Count() / 2;
        }
        return count;
    }

Please guide me to improve performance (speed of my search engine is very very low)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:06:02+00:00Added an answer on May 15, 2026 at 10:06 pm

    I expect this is down to your from urls in _context.Urls – with no Where on this you’re getting a lot of data to then throw away when building up your results. How many items are in tmpQuery / results?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.