google like search syntax parsing (also posted in sql programming group)

Discussion in 'ASP .Net' started by neilmcguigan, Oct 29, 2005.

  1. neilmcguigan

    neilmcguigan Guest

    this is more of a text parsing/regex kind of question, but i figured
    i'd start here. please let me know if this should go somewhere else.

    I'd like to implement google-like search syntax, a la

    so a text query like this:

    ("google search" "regular expressions") OR (syntax text)

    [some intermediate object that holds the expressions]

    and turns into an sql query like this:

    ([aSpecificField] LIKE '%somevalue%') AND
    (([field1] LIKE '%google search%' AND [field1] LIKE '%regular
    expression%') OR ([field1] LIKE '%syntax%' AND [field1] LIKE '%text%'))
    OR (([field2...repeat for all fields

    basically i am having trouble figuring out how to parse the text query
    to keep track of brackets and double-quoted expressions. am more
    interested in parsing the text than turning it into SQL.

    anyone have a reference that shows this being done?

    thanks in advance!
    neilmcguigan, Oct 29, 2005
    1. Advertisements

  2. wrote in
    Have you taken a look at SQL Server Full Text Search?
    Usenet Honey Pot, Oct 30, 2005
    1. Advertisements

  3. neilmcguigan

    neilmcguigan Guest

    hi stan

    thanks for your reply. i'm looking more for info on parsing strings to
    keep track of quoted and parenthesized values.


    neilmcguigan, Oct 30, 2005
  4. Well, your original example had the phrase "Regular Expressions" in it, and
    it sounds like you're on the right track there.


    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    A watched clock never boils.
    Kevin Spencer, Oct 30, 2005
  5. wrote in
    If you're going to manual parse - regular expressions is the way to go.

    So basically you'll need to perfect your regular expression (Maybe use Sub-
    Group matching?)
    Usenet Honey Pot, Oct 30, 2005
  6. neilmcguigan


    Jun 26, 2011
    Likes Received:
    I've just posted an article at that parses a search query into a simple expression tree. My code converts the input into a SQL Server Full-Text Search query, but should be useful if you are interested in parsing search terms in a way that allows you to support and control operator precedence using parentheses.
    scwebgroup, Jun 26, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.