Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Craig Cronin 304 posts 503 karma points
    Jan 24, 2012 @ 22:40
    Craig Cronin
    0

    Tag cloud from examine....

    I'm looking to create a dynamic tag cloud for the website and was hoping to use the examine index. Does anyone know if this can be done and have any help in any way....

    Thanks

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 25, 2012 @ 12:13
    Ismail Mayat
    0

    Craig,

    See http://richardfriedman.blogspot.com/2007/06/creating-tag-cloud.html however the links seem to be broken for source and its in php there is also java version but again broken links you might be able to contact the guy for source and port to .net. Think you will need to work directly with lucene and not examine.

    Regards

    Ismail

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jan 25, 2012 @ 18:12
    Ismail Mayat
    1

    Craig,

    I have something working the method is

            public List<Freq> GetTopTermsWithCount(string index,string fieldToSearch)

            {

                var listTerms = new List<Freq>();

                string indexPath = GetIndexPath(index);

                var reader = IndexReader.Open(indexPath);

     

                TermEnum termEnum = reader.Terms();

     

                while(termEnum.Next())

                {

                    if(termEnum.Term().Field().Equals(fieldToSearch))

                    {

                        Freq freq = new Freq(termEnum.Term().Text(), termEnum.DocFreq());

                        listTerms.Add(freq);

                    }

                }

                listTerms.Sort();

                reader.Close();

     

                return listTerms;

            }

     

            private string GetIndexPath(string indexToQuery)

            {

                string configFile = HttpContext.Current.Server.MapPath("/config/ExamineIndex.Config");

                // Create the query 

                var config =

                    XElement.Load(configFile).Elements("IndexSet").Where(

                        c => c.Attribute("SetName").Value == indexToQuery.Replace("Indexer", "IndexSet"));

     

                return HttpContext.Current.Server.MapPath(config.Attributes("IndexPath").FirstOrDefault().Value +"Index");

            }

    and the Freq class 

    public class Freq:IComparable

        {

            #region IComparable Members

     

            private string term;

            private int frequency;

            

            public string TermValue

            {

                get

                {

                    return term;

                }

            }

     

            public int FrequencyNo

            {

                get { return frequency; }

            }

     

     

     

            public Freq(string Term,int Frequeny)

            {

                term = Term;

                frequency = Frequeny;

            }

     

            public int CompareTo(object obj)

            {

               

                Freq oFreq = (Freq) obj;

                return frequency.CompareTo(oFreq.frequency);

     

            }

     

            #endregion

        }

    You can then easily sort as Freq implements IComparable.  So you give it the index and a field that you want to inspect good one would be bodyText. Works for me.

    Regards

    Ismail

     

     

Please Sign in or register to post replies

Write your reply to:

Draft