c# - Simple rating algorithm to sorting results according to user query -


I am developing a very basic web search engine, in which there are several parts, after recovering results according to the user query, I want to calculate the rate of each result and then sort the results by the rate of calculation. Here is my query:

  at tmpQuery_context.Urls = (The url documents are equivalent to joining _context.Documents on urls.UrlId documents.DocumentId in word = (_context.Words) Words associated with words are hit on words, WordID equals according to hit, where they are hit.DocumentId == DOCUMENTATION: Choose the word of the document ID.Text Select new (URL, document, word); = (In tmpQuery.AsEnumerable () from R where r.urls.ResolvedPath.Contains (breakedQuer Y, 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) New SearchResult Selection () {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.Wublisation. Length, rate = 0 colatear ating (breakedQuery, r.urls.ResolvedPath, r.documents.Title, r.documents.keywords, r.documents.Description, r.words)}) AsEnumerable () .OrderByDescending (Results => Results. Right) Undoubtedly (new search ResultEqualityComparer ());  

And the rate is calculated by this method:

  Private int calculation (IEnumerable & lt; string & gt; breakxide, string dependent, String title, string keyword, string description, ienumerable & lt; string & gt; word) {var baseRate = 0; Foreach (var query in breakedQuery) First I break user raw query (Microsoft-Apple) for a list of broken queries (Microsoft, Apple) if broken query starts - this means that the result * / Var none = (query.StartsWith ("-")); String term = query Replay ("-", ""); Var Pathcat = Count (Conceptual Word, Word); Var titlecount = count (title, word); Var keyword count = count (keyword, word); Var details count = count (description, word); Var word count = count (words, words); Var result = (Pathcount * 100) + (TitleCount * 50) + (KeywordCount * 25) + (DescriptionCount * 10) + (Word Count); If (none) baseRate - = results; Other baseline + = results; } Return basette; } Private integer calculation (string source, string query) {if calculation of profit (source. Plit ('') .sEnumerable & lt; string & gt; (), query) (string.IsNullOrWhiteSpace (source)!); Return 0; } Private int calculate (INMMerable & lt; string & gt; source, string query) {var count = 0; If (source! = Null & number of sources;) ()> 0) {// To compare two strings // first case sensitive diverse element = source. Where (source = & gt; source == query); Calculation = element Calculation (); // second case insensitive (half point of sensitive) + = sources. (Except) element Where (source = & gt; source.ToverInvoRient () == query.layover invariant ()). Calculations () / 2; } Calculation of return; }  

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

I hope this is below your url in _context.Urls - with no, where you are getting a lot of data, when you Your results are. How many items are there in TmpQuery / result?


Comments