Skip to content

Instantly share code, notes, and snippets.

View BartDM's full-sized avatar

Bart De Meyer BartDM

View GitHub Profile
/// <summary>
/// Parse the givven query string to a Lucene Query object
/// </summary>
/// <param name="searchQuery">The query string</param>
/// <param name="parser">The Lucense QueryParser</param>
/// <returns>A Lucene Query object</returns>
private Query ParseQuery(string searchQuery, QueryParser parser)
{
parser.AllowLeadingWildcard = true;
Query q;
using System.Collections.Generic;
using System.Linq;
namespace LuceneWrapper.TestApp
{
public class PersonDocument : ADocument
{
private string lastName;
private string firstName;
private IEnumerable<string> languages;
using System.Collections.Generic;
namespace LuceneWrapper
{
/// <summary>
/// Class to represent the Searh results
/// </summary>
public class SearchResult
{
public string SearchTerm { get; set; }
protected SearchResult Search<T>(string field, string searchQuery) where T : IDocument
{
Log.DebugFormat("Searching for Type: {0} with query \"{1}\" for field \"{2}\"", typeof(T), searchQuery, field);
//Fetch the possible fields to search on
PropertyInfo[] properties = typeof(T).GetProperties();
var fields = new List<string>();
var fieldsToSearchOn = new List<string>();
foreach (PropertyInfo property in properties)
using (var searcher = new IndexSearcher(LuceneDirectory))
{
Log.Debug("Starting new IndexSearcher");
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var searchResults = new SearchResult
{
SearchTerm = searchQuery,
SearchResultItems = new List<SearchResultItem>()
};
using System.Collections.Generic;
using System.Linq;
using log4net;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Util;
namespace LuceneWrapper
{
using System.IO;
using Lucene.Net.Store;
namespace LuceneWrapper
{
/// <summary>
/// The abstract base class to be implemented by everything that uses the Lucene directory
/// </summary>
public abstract class BaseSearch
{
/// <summary>
/// Custom attribute to define the field that can be seached on
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property)]
public class SearchField : System.Attribute
{
public string[] CombinedSearchFields;
public SearchField(params string[] values)
using System.Linq;
using System.Reflection;
using System.Text;
using Lucene.Net.Documents;
namespace LuceneWrapper
{
/// <summary>
/// Abstract class as base for all Seach Documents
/// </summary>
<Feature Id="ProductFeature" Title="DemoWebsite.Setup" Level="1">
<ComponentGroupRef Id="MyWebWebComponents" />
<ComponentGroupRef Id="DemoWebsiteIssConfiguration" />
<Component Directory="INSTALLFOLDER" Id="InstallFolderCmp" Guid="{88D22DB9-656B-4423-AA6A-92875F5F74EC}">
<File Id="WebConfigFile" KeyPath="yes" Source="$(var.publishDir)\Web.config" Vital="yes" />
</Component>
</Feature>