Querying the InSite Search Index


After setting up the InSite Search Index, the next step is to query it. The Ingeniux.Search.dll contains a class called QueryBuilder. It creates a query for you and has a single static method, called GetQuery, exposed for doing so. This method takes four parameters:


public static Query GetQuery(IEnumerable searchTerms,                 

         IEnumerable categoryIds= null, 

         IEnumerable typeIds = null

         IEnumerable sourceNames = null)

The first parameter is a list of terms for which the user wants to search. How this information is passed into the query will vary the results. If the user searched for hot dog, the results would return hot or dog. If hot and dog were sent to QueryBuilder separately instead of in a single string, it would only include results containing both terms. Lucene also supports quoted searches, so if "hot dog" were sent to the QueryBuilder, it would return results that include the entire phrase.

The second parameter is for filtering the results with categories. Note that these are not the actual category IDs in the CMS. In order to use the same categories from multiple systems, such as from Cartella or another search source, the category name is used instead.

The third parameter is for filtering the results even further, based on the type of the item being returned.  In the case of the CMS, it will be the name of the schema.

The last parameter is to filter to a specific source. For example, you may have serveral CMS instances/publishing targets. You could have multiple sources set up and filter based on the source. The "name" passed here will be the "name" of the source in the configuration file.

The next step in InSite Search configuration is creating a controller and a view.