Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Possible to use Linq to query a column that contains a description and remove the whitespaces?

Possible to use Linq to query a column that contains a description and remove the whitespaces?

Scheduled Pinned Locked Moved Database
databasehelpcsharplinqalgorithms
7 Posts 6 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #1

    Boy that was a mouth full. Let me explain. I have a table of products with names and descriptions. So take a word like kneepads. The correct way to spell it is knee pads and the column contains that correct spelling. But users will type in kneepads to search. I solved the plural issue with a custom function that I wrote. But I'm wondering if I can query the database in Linq, and say something like without removing, replacing a value in the database from pr in context.PRODUCT_ITEMS WHERE pr.Name.Replace(" ", "").Contains("kneepad") Basically I'm just looking for ideas to handle this. My older program had another table that contains names and descriptions that were pre-stripped for searching and I really don't want to go back to that.

    If it ain't broke don't fix it

    J C L J J 6 Replies Last reply
    0
    • J jkirkerx

      Boy that was a mouth full. Let me explain. I have a table of products with names and descriptions. So take a word like kneepads. The correct way to spell it is knee pads and the column contains that correct spelling. But users will type in kneepads to search. I solved the plural issue with a custom function that I wrote. But I'm wondering if I can query the database in Linq, and say something like without removing, replacing a value in the database from pr in context.PRODUCT_ITEMS WHERE pr.Name.Replace(" ", "").Contains("kneepad") Basically I'm just looking for ideas to handle this. My older program had another table that contains names and descriptions that were pre-stripped for searching and I really don't want to go back to that.

      If it ain't broke don't fix it

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #2

      It would be a very slow solution. Assuming t-sql, I would add a computed column and put an index on it.

      Wrong is evil and must be defeated. - Jeff Ello

      1 Reply Last reply
      0
      • J jkirkerx

        Boy that was a mouth full. Let me explain. I have a table of products with names and descriptions. So take a word like kneepads. The correct way to spell it is knee pads and the column contains that correct spelling. But users will type in kneepads to search. I solved the plural issue with a custom function that I wrote. But I'm wondering if I can query the database in Linq, and say something like without removing, replacing a value in the database from pr in context.PRODUCT_ITEMS WHERE pr.Name.Replace(" ", "").Contains("kneepad") Basically I'm just looking for ideas to handle this. My older program had another table that contains names and descriptions that were pre-stripped for searching and I really don't want to go back to that.

        If it ain't broke don't fix it

        C Offline
        C Offline
        Chris Quinn
        wrote on last edited by
        #3

        I would suggest holding a table of synonyms, with possible search terms pointing to the actual terms in the product description

        ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

        1 Reply Last reply
        0
        • J jkirkerx

          Boy that was a mouth full. Let me explain. I have a table of products with names and descriptions. So take a word like kneepads. The correct way to spell it is knee pads and the column contains that correct spelling. But users will type in kneepads to search. I solved the plural issue with a custom function that I wrote. But I'm wondering if I can query the database in Linq, and say something like without removing, replacing a value in the database from pr in context.PRODUCT_ITEMS WHERE pr.Name.Replace(" ", "").Contains("kneepad") Basically I'm just looking for ideas to handle this. My older program had another table that contains names and descriptions that were pre-stripped for searching and I really don't want to go back to that.

          If it ain't broke don't fix it

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Add a normal search without the gimmicks and explain that if "kneepads" don't give the correct results, they should search for "knee".

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          • J jkirkerx

            Boy that was a mouth full. Let me explain. I have a table of products with names and descriptions. So take a word like kneepads. The correct way to spell it is knee pads and the column contains that correct spelling. But users will type in kneepads to search. I solved the plural issue with a custom function that I wrote. But I'm wondering if I can query the database in Linq, and say something like without removing, replacing a value in the database from pr in context.PRODUCT_ITEMS WHERE pr.Name.Replace(" ", "").Contains("kneepad") Basically I'm just looking for ideas to handle this. My older program had another table that contains names and descriptions that were pre-stripped for searching and I really don't want to go back to that.

            If it ain't broke don't fix it

            J Offline
            J Offline
            jkirkerx
            wrote on last edited by
            #5

            Guess the original idea I had might be the best. A separate table of straight text with no white spaces and just do a join. Or maybe a table of words with white space that are parsed out with conjunctions removed and verbs fixed. Alright Thanks!

            If it ain't broke don't fix it

            1 Reply Last reply
            0
            • J jkirkerx

              Boy that was a mouth full. Let me explain. I have a table of products with names and descriptions. So take a word like kneepads. The correct way to spell it is knee pads and the column contains that correct spelling. But users will type in kneepads to search. I solved the plural issue with a custom function that I wrote. But I'm wondering if I can query the database in Linq, and say something like without removing, replacing a value in the database from pr in context.PRODUCT_ITEMS WHERE pr.Name.Replace(" ", "").Contains("kneepad") Basically I'm just looking for ideas to handle this. My older program had another table that contains names and descriptions that were pre-stripped for searching and I really don't want to go back to that.

              If it ain't broke don't fix it

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              As I read this you have decided on a solution and now are attempting to implement that. My take on the problem, not your solution, is that you should investigate it first and then decide on a solution to implement. Your problem is not new. It has been around for decades and I doubt your solution will work. For starters because it doesn't really deal with misspellings. Not to mention synonyms. However there are solutions that do work fairly well. So you should see if you can find them first.

              1 Reply Last reply
              0
              • J jkirkerx

                Boy that was a mouth full. Let me explain. I have a table of products with names and descriptions. So take a word like kneepads. The correct way to spell it is knee pads and the column contains that correct spelling. But users will type in kneepads to search. I solved the plural issue with a custom function that I wrote. But I'm wondering if I can query the database in Linq, and say something like without removing, replacing a value in the database from pr in context.PRODUCT_ITEMS WHERE pr.Name.Replace(" ", "").Contains("kneepad") Basically I'm just looking for ideas to handle this. My older program had another table that contains names and descriptions that were pre-stripped for searching and I really don't want to go back to that.

                If it ain't broke don't fix it

                G Offline
                G Offline
                GuyThiebaut
                wrote on last edited by
                #7

                Something along these lines will work:

                        List words = new List() { "hEllo", "World" };
                        words = words.Select(x => x.Replace("hE", "He")).ToList();
                
                “That which can be asserted without evidence, can be dismissed without evidence.”

                ― Christopher Hitchens

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups