protected void Button1_Click(object sender, EventArgs e)
{
string[] stringInput = TextBox1.Text.Split(' ');
ShowPermutations<string>(stringInput, stringInput.Length);
}
static void ShowPermutations<T>(IEnumerable<T> input, int count)
{
var xx = new List<string>();
foreach (IEnumerable<T> permutation in PermuteUtils.Permute<T>(input, count))
{
foreach (T i in permutation)
{
xx.Add(" " + i);
}
Console.WriteLine();
}
}
Add a new class to your site and put the following code in it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Class1
/// </summary>
using System;
using System.Collections.Generic;
public class PermuteUtils
{
// Returns an enumeration of enumerators, one for each permutation
// of the input.
public static IEnumerable<IEnumerable<T>> Permute<T>(IEnumerable<T> list, int count)
{
if (count == 0)
{
yield return new T[0];
}
else
{
int startingElementIndex = 0;
foreach (T startingElement in list)
{
IEnumerable<T> remainingItems = AllExcept(list, startingElementIndex);
foreach (IEnumerable<T> permutationOfRemainder in Permute(remainingItems, count - 1))
{
yield return Concat<T>(
new T[] { startingElement },
permutationOfRemainder);
}
startingElementIndex += 1;
}
}
}
// Enumerates over contents of both lists.
public static IEnumerable<T> Concat<T>(IEnumerable<T> a, IEnumerable<T> b)
{
foreach (T item in a) { yield return item; }
foreach (T item in b) { yield return item; }
}
// Enumerates over all items in the input, skipping over the item
// with the specified offset.
public static IEnumerable<T> AllExcept<T>(IEnumerable<T> input, int indexToSkip)
{
int index = 0;
foreach (T item in input)
{
if (index != indexToSkip) yield return item;
index += 1;
}
}
}
Mojorz
Member
3 Points
22 Posts
Search gridview based on word permutations introduced
Dec 11, 2012 10:44 PM|LINK
Hi ,
My question is how to search records on a gridview base on word permutation and what is the best approach to reach that.
It is urgent , any help will be aprecciated
oned_gk
All-Star
31257 Points
6389 Posts
Re: Search gridview based on word permutations introduced
Dec 12, 2012 12:13 AM|LINK
Define full-text index for your sql table .
Create stored procedure to use fulltextsearch query, SELECT * WHERE CONTAINTS(yourfield ...
http://msdn.microsoft.com/en-us/library/ms142571.aspx
yuvakom
Member
28 Points
47 Posts
Re: Search gridview based on word permutations introduced
Dec 12, 2012 10:38 AM|LINK
u can search that by using row filter property
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Search gridview based on word permutations introduced
Dec 12, 2012 12:18 PM|LINK
Can you give us an example to explain that?
Can you offer us detailled information?
Mojorz
Member
3 Points
22 Posts
Re: Search gridview based on word permutations introduced
Dec 12, 2012 02:22 PM|LINK
Hi
For example if the user digit in the search field "asp net forum"
first searches for
asp net forum
asp net
net asp
asp forum
forum asp etc
I would appreciate any help thanks
sarathi125
Star
13599 Points
2691 Posts
Re: Search gridview based on word permutations introduced
Dec 12, 2012 03:24 PM|LINK
Hi,
Try like the following,
Add the following code in the code behind
protected void Button1_Click(object sender, EventArgs e) { string[] stringInput = TextBox1.Text.Split(' '); ShowPermutations<string>(stringInput, stringInput.Length); } static void ShowPermutations<T>(IEnumerable<T> input, int count) { var xx = new List<string>(); foreach (IEnumerable<T> permutation in PermuteUtils.Permute<T>(input, count)) { foreach (T i in permutation) { xx.Add(" " + i); } Console.WriteLine(); } }Add a new class to your site and put the following code in it.
using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> /// Summary description for Class1 /// </summary> using System; using System.Collections.Generic; public class PermuteUtils { // Returns an enumeration of enumerators, one for each permutation // of the input. public static IEnumerable<IEnumerable<T>> Permute<T>(IEnumerable<T> list, int count) { if (count == 0) { yield return new T[0]; } else { int startingElementIndex = 0; foreach (T startingElement in list) { IEnumerable<T> remainingItems = AllExcept(list, startingElementIndex); foreach (IEnumerable<T> permutationOfRemainder in Permute(remainingItems, count - 1)) { yield return Concat<T>( new T[] { startingElement }, permutationOfRemainder); } startingElementIndex += 1; } } } // Enumerates over contents of both lists. public static IEnumerable<T> Concat<T>(IEnumerable<T> a, IEnumerable<T> b) { foreach (T item in a) { yield return item; } foreach (T item in b) { yield return item; } } // Enumerates over all items in the input, skipping over the item // with the specified offset. public static IEnumerable<T> AllExcept<T>(IEnumerable<T> input, int indexToSkip) { int index = 0; foreach (T item in input) { if (index != indexToSkip) yield return item; index += 1; } } }For more help check here
http://www.interact-sw.co.uk/iangblog/2004/09/16/permuterate
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
Madhu1234
Participant
1380 Points
287 Posts
Re: Search gridview based on word permutations introduced
Dec 12, 2012 04:18 PM|LINK
As per my understanding you can use Auto completeextender in Ajax toolkit.
Check this example on how to use autocompleteextender..
http://www.aspsnippets.com/Articles/ASP.Net-AJAX-Control-Toolkit-AutoCompleteExtender-without-using-Web-Services.aspx
Mojorz
Member
3 Points
22 Posts
Re: Search gridview based on word permutations introduced
Dec 12, 2012 08:14 PM|LINK
Firstly thanks for the quick answer ,I was able to implement this in my project .
Now I need a strategy to make a sql select statement that contains this permutations
and display results in gridview .
Any ideas ?
Thanks once again
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Search gridview based on word permutations introduced
Dec 13, 2012 12:05 AM|LINK
Well……It's not such an easy way to implement such a task. I suggest you:
1) Trying to use Full-Text Search.
2) Trying to write some searching enginee like Google or Bing's. Maybe you can have a look at this:
http://www.codeproject.com/Articles/5981/Internal-Site-Search-Engine