Archive for Main

LINQ to SQL multi-keyword search

Thursday, April 15th, 2010

how-to search mutiple keywords using LINQ to SQL

this bit of LINQ code will let you search for records using any number of keywords

it’s a bit limited, but it illustrates the starting point for something more.

the key is to get results for the first keyword into a disconnected object (in this case, a simple List<String>) and then search for the remaining keywords in there. clearly you could up the ante, and select more fields and spin up a collection of custom objects (i.e. List<MyClass>) but this suited my needs for an autocomplete for country names.

// GetMatchesIntersect(string csv, int maxMatches)
// mainly developed for auto-complete scenarios
//
// searches single [n]varchar|text|char field for multiple keywords
//
// returns array of field values containing ALL keywords
//
// NOTE: i decided on array because i am implementing this a webservice
//       to be consumed by other languages/platforms)
public string[] GetMatchesIntersect(string csv, int maxMatches)
{

    // keywords come in as comma-separated values
    string[] keywords = csv.Split(new char[] { ' ', ',' });

    // this list will hold the matches
    List<string> matches;

    using (DbDataContext db = new DbDataContext())
    {

     // build list of matches for first keyword into generic List<string>
     matches = (from s in db.TableToSearch
                where s.FieldToSearch.Contains(keywords[0])
                select s.FieldToSearch).ToList<string>();

     // if any were found
     if (null != matches && matches.Count > 0)
     {
         // start searching at the 2nd keyword (if any)
         for (int i = 1; i < keywords.Length && matches.Count > 0; i++)
         {
          // using .ToUpper() because matching in a List<string> is case-sensitive
          // set matches equal to the query results for each succesive keyword.
          matches = (from match in matches
                  where match.ToUpper().Contains(keywords[i].ToUpper())
                  select match).ToList<string>();
         }
     }
    }
    // ship it out as array
    return matches.Take(maxMatches).ToArray<string>();
}

Anniversary of a Dark Day

Thursday, September 11th, 2008

9/11 is now long enough ago, that when i read e-mails from the time I am surprised by how antiquated my technology was.

i didn’t know anybody who died that day, thankfully.

*moment of silence*

convert heat to electricty via sound

Tuesday, June 12th, 2007

so many processes we employ in our modern world generate heat that goes to waste — from cpu in laptops to nuclear power plant

Orest Symko from the university of utah has found a way to create sound from waste heat and then use that sound to generate electricity

very cool tech http://www.sciencedaily.com/releases/2007/06/070603225026.htm

legalized gange just wasn’t enough, hunh?

Wednesday, June 6th, 2007

Reuters is reporting today that Dutch students have concocted a powered alcoholic beverage that when mixed with water becomes a “a bubbly, lime-colored and -flavored drink with just 3 percent alcohol content.”

called Booz2Go, the target audience is clearly hikers who want to party after a long day but don’t wanna carry all that fluid around.

ha!

article here

now that is high art

Wednesday, May 23rd, 2007

oh how many days seem like this one:

tune in, turn on, and drop out

Wednesday, May 9th, 2007

completely self-contained computer pod
http://www.theoculas.com/gallery.html

flat-screen, surround sound, immersive environment

daddy likey — i want one!

smoking buds

Wednesday, April 25th, 2007

scored me a new pair of ear buds for my ipod, and dude they rock, i’ve got uncle l, and momma said these bud’s will knock you out — bass response to 18Hz, boom bap pow.

only$20 bucks! cheap!

vacation ruled

Tuesday, April 24th, 2007

if you ever get the chance to vacation in the dominican republic, i would totally go for it, in particular, if you have children stay at Melia Caribe resort, very kid friendly, good food, safe environment, fantastic beaches.

my hump

Wednesday, April 11th, 2007

day.

just writing code today and doing a little surfing on the side, nothing too exciting. i want to hit my deadline for the day and bug out of here.

exercise and politics

Tuesday, April 3rd, 2007

my working out is going pretty good, i found out on monday that i’ve been doing stomach crunches wrong and doing them correctly has me at 75 (3 sets of 25) instead of 150.

whatever, i’d like to get rid of my food blister by summer if i can.

i’ve been pinging my buddy ray with political discourse lately, and it has been good. he is a very well read guy and an independent thinker, which is uncommon in conservatives.  it’s good for me to hear from conservatives that i respect.

i am trying to get the vegas thing going on right now, found good air+hotel, am waiting on the boss lady to hear whether it’s cool.