05.31.07

Creating Tag Search in an Application

Posted in My Articles at 2:20 am by codetiger

Introduction

This is more the architect of creating a search in an database or application, rather than code. This was my first attempt at search and I don’t know if there are better ways or not. If you know of a better way please add it as a comment. I am always open to finding better ways of doing this.

Having a tag base search in a database is cool.

Data Structure

This is how I set up my data structures, but you can create any entities you want. Note that I have only entered the Primary and foreign keys, you can add what ever attributes you feel you will need or like. The secret is the TagToTitle (Junction table), which maps tags to a title. This will allow us to get a list of titles for each tag.

Stored procedures

I have not listed all procedures needed, Insert, Update, Delete ect. Only the one that are needed for the search.

List of stored procedures

  • getTitleByTag
  • getTagIDByTagDiscription
  • getDataByTitle

Walkthrough

  1. The user enters the words they want as their search string and begins the search .
  2. Split the search string into a list of single words.
  3. Check each word and remove unwanted words. Like to, the, with, and ect. I tend to create a default list of words, charicters and numbers that should be remove. The idea is to end up with a list words that you might have tags for. If you want to have a tag = 2 then you would not have 2 remove from the search string. It will also reduce the the number of queries made to the database. 
  4. Get the TagID for each word in search list. (getTagIDByTagDescription)
  5. For each TagID get a list of Titles that belong to that tag.
  6. Once the list of titles is complete get a count of the number of times each title is in the list.
  7. For each title count we calculate the weight for that title and then divide the count by the number of words in the search string(before we remove unwanted charicters). TitleWeight = (TitleCount / SearchWordCount) * 100.
  8. Check the weight for each title if it is greater than the threshold then get the data item/s for that title. The threshold is your limit at which you will or will not show the Data item. If you choose 33 has a threshold, any title with a weight less than 33 will not be returned in the search results. I allow the user to define this value rather that having it fixed, so I place the threshold in the defaults options or they can adjust it for a particular search.
  9. Lastly display the search result to the user sorting it by the weight of each title the data is linked(mapped) to.

Conclusion

Note that when you are inserting a TagToTitle row, they must be unique. This will only be a problem if you try to add the same tag to a title.

I hope that if you plan to use search in an application this article helps you in some way.

Have a good day Clint

05.28.07

C# compared to C++

Posted in Code Speak at 2:14 am by codetiger

I went from Borland 6 C++ to C#, which was an easy transition as they aren’t very different in syntax. This can give you the sense that C# behaves like C++. However there are some noticeable differences. C# is a translated language and C++ is a compiled language. In my experience C# is slower but more portable, easier to create applications and it utilizes the most recent software technology from Microsoft. This includes web services and network programming.  There are ways to help it appear faster. Like the Singleton technique, however the first time the object (form)  is created it still take some time to display to the user. Once the object is in memory though the speed is good.  I must point out that most of my experience with C# has been on Mobile Devices, were you have very limited resources. With desktop applications I don’t notice this as much.  In C# all object are references (pointers) and List<> behaves different to Vector<>. In C++ vectors, when objects are added to it they are added by value or a copy of the object is inserted into the vector. With C# the List<> adds by reference. This means that you need to make sure that the scope of the object will last as long as the List<> needs the object.  Or else you will end up with a reference to an object that does not exist anymore. The frame work setup makes it easy to include (using) header files into your application than C++. I fact this is one of the best things about the framework and C#. To find the Classes, functions or objects that you can create is as easy as navigating methods of an object. C# can use pointers Like C++, but to do this you need to mark the code as unsafe and set the option for the project to allow the running of unsafe code. This is because of the garbage collector, it needs to be told not to clean up memory area in heap. I don’t tend to do this as it adds more complexity to the code. I am a full believer in keeping this simple.

Vista Review

Posted in Code Speak at 2:06 am by codetiger

Well I have had Vista for 4 months now so I thought I would give it a review from a daily users perspective. I have Vista Business some I can’t comment on the Media Center and such.

The best place to start is with my favourite part of vista. Which is the Start Search on widows main Menu, this is so cool. Now if I want to run a program I don’t have to navigate though folders or list of shortcuts, I just start typing in the first few characters and the program shortcut is displayed to me. I find it difficult to go to my XP machine as I don’t want to “find locations” any more. This is not just go for application you install but also with Windows applications like Mobile center, Error Reporting ect. I am finding thing that were in XP, but so buried I didn’t know that it was there. The Aero graphic is cool but the search is by far the most useful feature about Vista that XP will never have. The Vista search is good enough for me to remove Google desktop search. Although I must also mention that when I had Google desktop on, it didn’t look like the crawler was indexing my public folders, so items in these folders were not returning with search results (Even when I set the fold in Google desktop search options). I think this has to do with Vista Security, which has been the rainy cloud on an otherwise sunny day.   

Setting programs to run in admin mode will help most application that will just stop responding. The reason being that vista has not allowed it to perform a task. Even with Visual Studios 2005 after installing the vista patch and then the update I had problems updating a web reference (this error seems to have been fix in an update). Another problem I had was with my PDA not being able to access the internet though my computer.

Some programs that run on XP though won’t run on vista at all and some won’t perform some tasks. The software that came with my laptop for burning gives a driver block error ever time my computer starts. The software still works but it is annoying having to see this message all the time.  

But all in all I still think that Vista is a good OS and I am glad I went to it from XP. I am however looking forward to future updates that fix some of the security issues (not the lack of). I think that an OS should not stop an application from running that the user knowingly wants to run. Just who is the Master here, computers should bend to the users will, not humans bending to the will of a computer.