<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C.M. Jackson .Net &#187; code</title>
	<atom:link href="http://www.cmjackson.net/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cmjackson.net</link>
	<description>Web Design, Programming, Tutorials</description>
	<lastBuildDate>Tue, 18 May 2010 22:43:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ASP.NET MVC Using Forms Authentication With LDAP</title>
		<link>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/</link>
		<comments>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 19:49:03 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Forms Authentication]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=262</guid>
		<description><![CDATA[If you are using ASP.NET MVC and you want to authenticate your users against Active Directory using LDAP, you need to do a little work to get everything set up. It is pretty easy to authenticate users with Active Directory using the &#60;Authorize()&#62; attribute, but I ran into some problems when I wanted to authorize [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using ASP.NET MVC and you want to authenticate your users against Active Directory using LDAP, you need to do a little work to get everything set up. It is pretty easy to authenticate users with Active Directory using the &lt;Authorize()&gt; attribute, but I ran into some problems when I wanted to authorize a user based on a Windows Group.</p>
<p>Here are the steps I took to be able to authenticate active directory users and authorize their use of actions based on being members to user groups.</p>
<h3>Web.Config</h3>
<p>Find the authentication tag and change it to the following:</p>
<pre class="brush: xml;">
&lt;authentication mode=&quot;Forms&quot;&gt;
  &lt;forms loginUrl=&quot;~/Account/LogOn&quot; timeout=&quot;2880&quot; /&gt;
&lt;/authentication&gt;
</pre>
<p>The LoginUrl points to the Controller/Action where the login function is.</p>
<h3>UserRepository</h3>
<p>This is the class object that does the communication with Active Directory via LDAP. The project where this class resides should also add a reference to the System.DirectoryServices DLL.</p>
<pre class="brush: vb;">
Imports System.DirectoryServices

Public Class UserRepository

  Private _server As String

  Public Sub New(ByVal server As String)

    _server = server

  End Sub

  Public Function GetUser(ByVal userName As String) As Data.User

    Dim root As DirectoryEntry = New DirectoryEntry(&quot;LDAP://&quot; + _server)
    Dim search As DirectorySearcher = New DirectorySearcher(root)

    search.SearchScope = SearchScope.Subtree
    search.Filter = &quot;(sAMAccountName=&quot; + userName.Substring(userName.IndexOf(&quot;\&quot;) + 1) + &quot;)&quot;

    Dim results As SearchResultCollection = search.FindAll()

    Return _GetUser(results(0).Path)

  End Function

  Public Function GetUserByFullName(ByVal fullName As String) As Data.User

    Dim root As DirectoryEntry = New DirectoryEntry(&quot;LDAP://&quot; + _server)
    Dim search As DirectorySearcher = New DirectorySearcher(root)

    search.SearchScope = SearchScope.Subtree
    search.Filter = &quot;(displayName=&quot; + fullName + &quot;)&quot;

    Dim results As SearchResultCollection = search.FindAll()

    Return _GetUser(results(0).Path)

  End Function

  Public Function GetMembers(ByVal groupPath As String) As IQueryable(Of Data.User)

    Dim root As DirectoryEntry = New DirectoryEntry(&quot;LDAP://&quot; + _server)
    Dim search As DirectorySearcher = New DirectorySearcher(root)
    Dim members As List(Of Data.User) = New List(Of Data.User)()

    search.SearchScope = SearchScope.Subtree
    search.Filter = &quot;(memberOf=&quot; + groupPath + &quot;)&quot;

    Dim results As SearchResultCollection = search.FindAll()

    For Each result As SearchResult In results
      members.Add(_GetUser(result.Path))
    Next

    root.Close()

    Return members.AsQueryable

  End Function

  Public Function Authenticate(ByVal userName As String, ByVal password As String) As Data.User

    Dim root As DirectoryEntry = New DirectoryEntry(&quot;LDAP://&quot; + _server, userName, password)
    Dim search As DirectorySearcher = New DirectorySearcher(root)
    Dim user As User = Nothing

    search.SearchScope = SearchScope.Subtree
    search.Filter = &quot;(sAMAccountName=&quot; + userName + &quot;)&quot;

    Dim results As SearchResultCollection = search.FindAll()

    If (Not (results Is Nothing)) Then

        user = _GetUser(results(0).Path)

    End If

    Return user

  End Function

  Private Function _GetUser(ByVal userPath As String) As Data.User

    Dim entry As DirectoryEntry = New DirectoryEntry(userPath)
    Dim user As Data.User = New Data.User()

    user.UserName = entry.Properties(&quot;sAMAccountName&quot;).Value
    user.FirstName = entry.Properties(&quot;givenname&quot;).Value
    user.LastName = entry.Properties(&quot;sn&quot;).Value
    user.Email = entry.Properties(&quot;mail&quot;).Value

    For Each group In entry.Properties(&quot;memberOf&quot;)

        user.Groups.Add(_GetGroup(group))

    Next

    entry.Close()

    Return user

  End Function

  Private Function _GetGroup(ByVal path As String) As String

    Dim value As String = &quot;&quot;
    Dim index1 As Integer = path.IndexOf(&quot;=&quot;, 1)
    Dim index2 As Integer = path.IndexOf(&quot;,&quot;, 1)

    If (Not (index1 = -1)) Then

        value = path.Substring((index1 + 1), (index2 - index1) - 1)

    End If

    Return value

  End Function

End Class
</pre>
<h3>User</h3>
<p>This class hold the user information that we want to work with from Active Directory. Here I am storing the username, first and last names, email address, and the list of groups the user is a member of.</p>
<p>This class is in my Data project and that is why you will see Data.User in the UserRepository. If you want everything to be in one project, you could create the Data namespace around the User class. I did run into problems with MVC getting confused between my User class and a built in one if I did not specify the namespace. You could also simply rename the User class to something else.</p>
<pre class="brush: vb;">
Public Class User

    Private _userName As String
    Private _firstName As String
    Private _lastName As String
    Private _email As String
    Private _groups As List(Of String)

    Public Property UserName() As String
        Get
            Return _userName
        End Get
        Set(ByVal value As String)
            _userName = value
        End Set
    End Property

    Public Property FirstName() As String
        Get
            Return _firstName
        End Get
        Set(ByVal value As String)
            _firstName = value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return _lastName
        End Get
        Set(ByVal value As String)
            _lastName = value
        End Set
    End Property

    Public Property Email() As String
        Get
            Return _email
        End Get
        Set(ByVal value As String)
            _email = value
        End Set
    End Property

    Public Property Groups() As List(Of String)
        Get
            Return _groups
        End Get
        Set(ByVal value As List(Of String))
            _groups = value
        End Set
    End Property

    Public Sub New()

        Me.UserName = &quot;&quot;
        Me.FirstName = &quot;&quot;
        Me.LastName = &quot;&quot;
        Me.Email = &quot;&quot;

        Me.Groups = New List(Of String)()

    End Sub

    Public Function GetFullName() As String

        Dim s As System.Text.StringBuilder = New System.Text.StringBuilder()

        If (Not (Me.FirstName = &quot;&quot;)) Then

            s.Append(Me.FirstName)
            s.Append(&quot; &quot;)

        End If

        s.Append(Me.LastName)

        Return s.ToString()

    End Function

    Public Function SerializeGroups() As String

        Dim text As String = &quot;&quot;

        For Each item In Groups

            If (text = &quot;&quot;) Then

                text = item

            Else

                text = text + &quot;|&quot; + item

            End If

        Next

        Return text

    End Function

End Class
</pre>
<h3>AccountController</h3>
<p>Next is the controller that handles signing in and out of the application. I&#8217;ve simplified this controller code for the sake of simplicity. Under normal circumstances, I would have the controller communicate to a service class that then interacts with the repository. The service class could do validation on the login form before attempting to authenticate empty user and password strings.</p>
<pre class="brush: vb;">
Imports System.Globalization
Imports System.Security.Principal
Imports S3.Data

&lt;HandleError()&gt; _
Public Class AccountController
    Inherits System.Web.Mvc.Controller

    'data members.
    Private _userRepository as UserRepository
    Private _formsAuthentication As IFormsAuthentication

    Public Sub New()

        _userRepository = New UserRepository(ConfigurationManager.AppSettings(&quot;LDAPServer&quot;)
        _formsAuthentication = New FormsAuthentication()

    End Sub

    'GET: /Account/LogOn
    Public Function LogOn() As ActionResult

        Return View(&quot;LogOn&quot;)

    End Function

    'POST: /Account/LogOn
    &lt;AcceptVerbs(HttpVerbs.Post)&gt; _
    Public Function LogOn( _
        ByVal userName As String, _
        ByVal password As String, _
        ByVal rememberMe As Boolean, _
        ByVal returnUrl As String) As ActionResult

        Dim result As ActionResult = View(&quot;LogOn&quot;)
        Dim user As User = _userRepository.Authenticate(userName, password)

        If (Not (user Is Nothing)) Then

            _formsAuthentication.SignIn(user, rememberMe)

            If (returnUrl Is Nothing) Then

                result = RedirectToAction(&quot;Index&quot;, &quot;Home&quot;)

            Else

                result = Redirect(returnUrl)

            End If

        End If

        Return result

    End Function

    Public Function LogOff() As ActionResult

        _formsAuthentication.SignOut()
        Return RedirectToAction(&quot;Index&quot;, &quot;Home&quot;)

    End Function

End Class
</pre>
<h3>FormsAuthentication</h3>
<p>The next class is the FormsAuthentication class. The main reason that I made this code a class of its own is for the sake of unit testing my project. During unit testing, the commands that deal with writing and clearing the cookie would error out. To get around this, I created an empty FormsAuthenticationTest class that does nothing for the SignIn and SignOut methods. <strong>Note: The example code does not show the interfaces. Check out the repository pattern and factory pattern to see how to setup services and repositories for unit testing.</strong></p>
<p>After a user has been authenticated by the UserRepository, the controller passes the returned user into the SignIn method of the FormsAuthentication. This method then stores the user&#8217;s full name and serialized groups in a cookie. The list of groups is serialized by creating a string with each group name separated by a &#8220;|&#8221; character. This serialization takes place in the User object.</p>
<pre class="brush: vb;">
Imports System.Web.Security

Public Class FormsAuthentication

    Public Sub SignIn(ByVal user As Data.User, ByVal createPersistentCookie As Boolean)

        Dim authTicket As System.Web.Security.FormsAuthenticationTicket = _
            New System.Web.Security.FormsAuthenticationTicket( _
            1, _
            user.GetFullName(), _
            Now, _
            Now.AddMinutes(60), _
            createPersistentCookie, _
            user.SerializeGroups())

        Dim encryptedTicket As String = System.Web.Security.FormsAuthentication.Encrypt(authTicket)

        Dim authCookie As HttpCookie = New HttpCookie( _
            System.Web.Security.FormsAuthentication.FormsCookieName, _
            encryptedTicket)

        If (createPersistentCookie) Then

            authCookie.Expires = authTicket.Expiration

        End If

        HttpContext.Current.Response.Cookies.Add(authCookie)

    End Sub

    Public Sub SignOut()

        System.Web.Security.FormsAuthentication.SignOut()

    End Sub

End Class
</pre>
<h3>Global.asax</h3>
<p>With the previous code, you should be able to use Forms Authentication to log into your application and authenticate a user against the Active Directory via LDAP. The &lt;Authorize()&gt; attribute will allow you to secure your controller or actions. There&#8217;s just one problem. Now, if you want to use &lt;Authorize(Roles:=&#8221;GroupName&#8221;),  your user does not get authorization to the action or controller.</p>
<p>There&#8217;s just one change left that we need to make. ASP MVC makes the current logged in user available by accessing the Context.User. When you log into the application MVC is setting the user as authenticated, but no roles or groups have been added to that user. We need to modify the Global.asax file and use the AuthenticationRequest event.</p>
<p>The following code will fire each time an authentication request is triggered. The code will check if the authentication cookie exists and if it does, reads the user&#8217;s name and groups from it and stores them in the Context.User so MVC can access the groups.</p>
<pre class="brush: vb;">
    Private Sub MvcApplication_AuthenticateRequest(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.AuthenticateRequest

        Dim cookieName As String = System.Web.Security.FormsAuthentication.FormsCookieName
        Dim authCookie As HttpCookie = Context.Request.Cookies(cookieName)

        If (Not (authCookie Is Nothing)) Then

            Dim authTicket As System.Web.Security.FormsAuthenticationTicket = Nothing

            Try

                authTicket = System.Web.Security.FormsAuthentication.Decrypt(authCookie.Value)

                If (Not (authTicket Is Nothing)) Then

                    Dim groups As String() = authTicket.UserData.Split(New Char() {&quot;|&quot;})
                    Dim id As System.Security.Principal.GenericIdentity = _
                        New System.Security.Principal.GenericIdentity(authTicket.Name, &quot;LdapAuthentication&quot;)
                    Dim principal As System.Security.Principal.GenericPrincipal = _
                        New System.Security.Principal.GenericPrincipal(id, groups)

                    Context.User = principal

                End If

            Catch ex As Exception

                'Do nothing.

            End Try

        End If

    End Sub
</pre>
<p>And that should be all you need to use FormsAuthentication with LDAP and group authorization.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2009/10/23/asp-net-mvc-using-forms-authentication-with-ldap/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Full URL From A Controller</title>
		<link>http://www.cmjackson.net/2009/10/16/asp-net-mvc-full-url-from-a-controller/</link>
		<comments>http://www.cmjackson.net/2009/10/16/asp-net-mvc-full-url-from-a-controller/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 13:39:37 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[VB]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=257</guid>
		<description><![CDATA[In working with ASP.NET MVC, I came across the need to send an email with the URL of a document that is to be approved.  There are helper functions accessible from the View to build an ActionLink or get the URL of an action, but I had problems finding how to build this URL from [...]]]></description>
			<content:encoded><![CDATA[<p>In working with ASP.NET MVC, I came across the need to send an email with the URL of a document that is to be approved.  There are helper functions accessible from the View to build an ActionLink or get the URL of an action, but I had problems finding how to build this URL from within a controller.  Here is the simple code that I finally pieced together to do what I wanted:</p>
<pre class="brush: vb;">
Dim link As String = HttpContext.Request.Url.Scheme + _
    &quot;://&quot; + HttpContext.Request.Url.Authority + _
    Url.Action(&quot;ActionName&quot;, &quot;ControllerName&quot;, New With {.id = idOfDocument})</pre>
<p>HttpContext.Request.Url.Scheme returns &#8220;http&#8221; or &#8220;https&#8221;, which ever one you&#8217;re using.<br />
HttpContext.Request.Url.Authority returns the Base Url of your application.<br />
And, the Url.Action method creates the Url to the Controller, Action, and ID of the document that is being sent out for approval.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2009/10/16/asp-net-mvc-full-url-from-a-controller/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to use Zend_Search_Lucene with the PHP framework CodeIgniter</title>
		<link>http://www.cmjackson.net/2009/02/17/how-to-use-zend_search_lucene-with-the-php-framework-codeigniter/</link>
		<comments>http://www.cmjackson.net/2009/02/17/how-to-use-zend_search_lucene-with-the-php-framework-codeigniter/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 04:06:21 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Lucene]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[search engine]]></category>
		<category><![CDATA[Zend framework]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=99</guid>
		<description><![CDATA[If you&#8217;ve heard the buzz about Apache&#8217;s open source search engine, Lucene, then you probably already know what a great search engine tool it is.  The search engine is fast, has ports to various languages, and was written to be able to share the search index between the different Lucene ports. The PHP version of [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve heard the buzz about Apache&#8217;s open source search engine, Lucene, then you probably already know what a great search engine tool it is.  The search engine is fast, has ports to various languages, and was written to be able to share the search index between the different Lucene ports.</p>
<p>The PHP version of Lucene is packaged in the <a href="http://framework.zend.com/">Zend framework</a>and is called Zend_Search_Lucene.  When it comes to PHP frameworks, I tend to prefer using <a href="http://codeigniter.com/">CodeIgniter</a>as opposed to Zend.  So, you might ask, how can you use a favored framework such as CodeIgniter with the power of Lucene&#8217;s search capabilities?</p>
<p><strong>Install CodeIgniter 1.7.1</strong></p>
<p>I downloaded a copy of the latest version of <a href="http://codeigniter.com/downloads/">CodeIgniter 1.7.1</a> and configured it to run the default welcome action.  Next, I made a copy of the welcome controller and view to test my indexer and search actions (which we&#8217;ll get to in just a minute).</p>
<p><strong>Install Zend Framework 1.7</strong></p>
<p>Next, I downloaded the latest version of the <a href="http://www.zend.com/community/downloads">Zend Framework 1.7.5</a>.  After extracting the zip file, copy the Zend folder inside ZendFramework-1.7.5/library and paste it into the CodeIgniter framework under  System/application/libraries.</p>
<p><strong>Create A Zend Loader Class</strong><br />
The next thing that needs to be done is create a loader file to load the Zend library classes in CodeIgniter.  <a href="http://www.beyondcoding.com/2008/02/21/using-zend-framework-with-codeigniter/">This tutorial</a> also explains how to create this loader class.  This file below is named Zend.php and should be located in the System/application/libraries folder of CodeIgniter.</p>
<pre class="brush: php;"> &lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class CI_Zend
{  
    function __construct($class = NULL)  
    {   
        // include path for Zend Framework   
        // alter it accordingly if you have put the 'Zend' folder elsewhere   
        ini_set('include_path',   ini_get('include_path') .
        PATH_SEPARATOR . APPPATH . 'libraries');

        if ($class)   
        {    
            require_once (string) $class . EXT;
            log_message('debug', &quot;Zend Class $class Loaded&quot;);
        }
        else
        {    
            log_message('debug', &quot;Zend Class Initialized&quot;);
        }  
    }

    function load($class)  
    {   
        require_once (string) $class . EXT;   
        log_message('debug', &quot;Zend Class $class Loaded&quot;);  
    }
}
//End of File: Zend.php</pre>
<p><strong>Creating An Indexer</strong></p>
<p>Now we will create the search index.  For demonstration purposes, I&#8217;m going to place the indexer and search functions in the same controller.  You should have your indexer in a separate controller with security that will keep everyone from being able to run it.</p>
<p>We&#8217;ll start with the copy of the welcome controller, which I named home.php.  After changing the class name and function calls to home instead of welcome, the contents of the file should look like this.  Also, add the sanitize function below.</p>
<pre class="brush: php;"> &lt;?php
class Home extends Controller
{  
    function Home()  
    {
        parent::Controller();
    }    

    function index()  
    {   
        $this-&gt;load-&gt;view('home_view');  
    }

    function sanitize($input)
    {
        return htmlentities(strip_tags($input));
    }
}
/* End of file home.php */
/* Location: ./system/application/controllers/home.php */</pre>
<p>Now, we can just replace the contents of the index() function with the following.</p>
<pre class="brush: php;">$this-&gt;load-&gt;library('zend', 'Zend/Feed');   
$this-&gt;load-&gt;library('zend', 'Zend/Search/Lucene');   
$this-&gt;load-&gt;library('zend');   
$this-&gt;zend-&gt;load('Zend/Feed');   
$this-&gt;zend-&gt;load('Zend/Search/Lucene');     

//Create index.   
$index = new Zend_Search_Lucene('c:\wamp\www\ci\tmp\feeds_index', true);      
$feeds = array(    
    'http://www.cmjackson.net/feed/rss/',    
    'http://andrewmjackson.com/feed/rss');       

//grab each feed.   
foreach($feeds as $feed)   
{    
    $channel = Zend_Feed::import($feed);    
    echo $channel-&gt;title().'&lt;br /&gt;';        

    //index each item.    
    foreach($channel-&gt;items as $item)    
    {     
        if ($item-&gt;link() &amp;&amp; $item-&gt;title() &amp;&amp; $item-&gt;description())     
        {      
            //create an index doc.      
            $doc = new Zend_Search_Lucene_Document();            
            $doc-&gt;addField(Zend_Search_Lucene_Field::Keyword(
                'link', $this-&gt;sanitize($item-&gt;link())));      
            $doc-&gt;addField(Zend_Search_Lucene_Field::Text(
                'title', $this-&gt;sanitize($item-&gt;title())));      
            $doc-&gt;addField(Zend_Search_Lucene_Field::Unstored(
                'contents', $this-&gt;sanitize($item-&gt;description())));            

            echo &quot;\tAdding: &quot;. $item-&gt;title() .'&lt;br /&gt;';      
            $index-&gt;addDocument($doc);     
        }    
    }   
}      

$index-&gt;commit();      
echo $index-&gt;count() .' Documents indexed.&lt;br /&gt;';</pre>
<p>This indexer will read in the RSS feeds from this website as well as <a href="http://www.andrewmjackson.com">my brother&#8217;s</a>website and index the contents of the feed.  When the index is created, you must specify a location to store the index.  These are binary files that Lucene creates and it does not require a database for storage.</p>
<p>In <a href="http://devzone.zend.com/node/view/id/91">this article</a>, the author further explains the fields of the index document and when each should be used.</p>
<p>Feeds are not the only resource that Lucene can index.  Web sites, databases, Microsoft Office documents, etc.  Find out more information on Zend Search Lucene in the <a href="http://framework.zend.com/manual/en/zend.search.lucene.html">Zend Framework Manual </a>.</p>
<p><strong>A Basic Search</strong></p>
<p>After running the indexer, you are ready to try searching the documents that are indexed.  For demonstration purposes, I&#8217;ve added another function to the same controller as the index called search().  This function does not get the results of a form, but instead simulates a string query as if it were from a form.</p>
<pre class="brush: php;">function search()  
{   
    $this-&gt;load-&gt;library('zend', 'Zend/Search/Lucene');   
    $this-&gt;load-&gt;library('zend');   
    $this-&gt;zend-&gt;load('Zend/Search/Lucene');      

    $index = new Zend_Search_Lucene('c:\wamp\www\ci\tmp\feeds_index');      

    $query = 'new movie';      
    $hits = $index-&gt;find($query);      

    echo 'Index contains '. $index-&gt;count() .
        ' documents.&lt;br /&gt;&lt;br /&gt;';   
    echo 'Search for &quot;'. $query .'&quot; returned '. count($hits) .
        ' hits&lt;br /&gt;&lt;br /&gt;';      

    foreach($hits as $hit)   
    {    
        echo $hit-&gt;title .'&lt;br /&gt;';    
        echo 'Score: '. sprintf('%.2f', $hit-&gt;score) .'&lt;br /&gt;';    
        echo $hit-&gt;link .'&lt;br /&gt;&lt;br /&gt;';   
    }    
}</pre>
<p>This function loads the same index that we previously created and searches for the key phrase &#8216;new movie&#8217;.  The results that are returned are sorted by their score ranking.  To make the search results look more like google, styling could be added  as well as formatting the result entries, but this gives you a good idea of the basic functions of the search engine and how it works.<code></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2009/02/17/how-to-use-zend_search_lucene-with-the-php-framework-codeigniter/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>String Replace Function For Lotus Script</title>
		<link>http://www.cmjackson.net/2009/01/28/string-replace-function-for-lotus-script/</link>
		<comments>http://www.cmjackson.net/2009/01/28/string-replace-function-for-lotus-script/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 21:06:29 +0000</pubDate>
		<dc:creator>Chris Jackson</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Lotus Notes]]></category>
		<category><![CDATA[Lotus Script]]></category>
		<category><![CDATA[strreplace]]></category>

		<guid isPermaLink="false">http://www.cmjackson.net/?p=71</guid>
		<description><![CDATA[Here is a handy function that I sometimes use in my Lotus Script programs.  '=============================================================================== ' +----------------------------------------------------------------------------+ ' &#124; Function: strreplace ' +----------------------------------------------------------------------------+ ' &#124; Accepts: src, the value to search for to replace. ' &#124;          dest, the value to replace with. ' &#124;          arg, the string to search within. ' +----------------------------------------------------------------------------+ ' &#124; Description: [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a handy function that I sometimes use in my Lotus Script programs. </p>
<pre class="brush: vb;">'===============================================================================
' +----------------------------------------------------------------------------+
' | Function: strreplace
' +----------------------------------------------------------------------------+
' | Accepts: src, the value to search for to replace.
' |          dest, the value to replace with.
' |          arg, the string to search within.
' +----------------------------------------------------------------------------+
' | Description:
' | Replaces all occurances of src with dest in the string arg.
' +----------------------------------------------------------------------------+
'===============================================================================
Public Function strreplace(Byval src As String, Byval dest As String,
Byval arg As String) As String

    'Declare variables
    Dim pos As Integer

    'Initialize
    pos = Instr(arg, src)

    'Loop through the string
    While (pos &gt; 0)
        arg = Left(arg, pos - 1) + dest + Mid(arg, pos + Len(src))
        pos = Instr(pos + Len(dest), arg, src)
    Wend

    'Return the replaced string
    strreplace = arg

End Function</pre>
<p>Here is an example of how to use the function:</p>
<pre class="brush: vb;">newString = strreplace(&quot;WORLD&quot;, &quot;World&quot;, &quot;Hello WORLD!&quot;)</pre>
<p>The <em>newString</em> variable would contain &#8220;Hello World!&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cmjackson.net/2009/01/28/string-replace-function-for-lotus-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
