remove old files

This commit is contained in:
Stephan
2017-05-22 15:41:16 +02:00
parent 8561d85f7a
commit 0be86efc50
5 changed files with 0 additions and 1160 deletions

View File

@@ -1,37 +0,0 @@
using Examine.SearchCriteria;
namespace UmbracoExamine.SearchCriteria
{
internal class ExamineValue : IExamineValue
{
public ExamineValue(Examineness vagueness, string value) : this(vagueness, value, 1)
{
}
public ExamineValue(Examineness vagueness, string value, float level)
{
this.Examineness = vagueness;
this.Value = value;
this.Level = level;
}
public Examineness Examineness
{
get;
private set;
}
public string Value
{
get;
private set;
}
public float Level
{
get;
private set;
}
}
}

View File

@@ -1,70 +0,0 @@
using Examine.SearchCriteria;
using Lucene.Net.Search;
namespace UmbracoExamine.SearchCriteria
{
/// <summary>
/// An implementation of the fluent API boolean operations
/// </summary>
public class LuceneBooleanOperation : IBooleanOperation
{
private LuceneSearchCriteria search;
internal LuceneBooleanOperation(LuceneSearchCriteria search)
{
this.search = search;
}
#region IBooleanOperation Members
/// <summary>
/// Sets the next operation to be AND
/// </summary>
/// <returns></returns>
public IQuery And()
{
return new LuceneQuery(this.search, BooleanClause.Occur.MUST);
}
/// <summary>
/// Sets the next operation to be OR
/// </summary>
/// <returns></returns>
public IQuery Or()
{
return new LuceneQuery(this.search, BooleanClause.Occur.SHOULD);
}
/// <summary>
/// Sets the next operation to be NOT
/// </summary>
/// <returns></returns>
public IQuery Not()
{
return new LuceneQuery(this.search, BooleanClause.Occur.MUST_NOT);
}
/// <summary>
/// Compiles this instance for fluent API conclusion
/// </summary>
/// <returns></returns>
public ISearchCriteria Compile()
{
if (!string.IsNullOrEmpty(this.search.SearchIndexType))
{
var query = this.search.query;
this.search.query = new BooleanQuery();
this.search.query.Add(query, BooleanClause.Occur.MUST);
//this.search.query.Add(this.search.queryParser.Parse("(" + query.ToString() + ")"), BooleanClause.Occur.MUST);
this.search.FieldInternal(LuceneExamineIndexer.IndexTypeFieldName, new ExamineValue(Examineness.Explicit, this.search.SearchIndexType.ToString().ToLower()), BooleanClause.Occur.MUST);
}
return this.search;
}
#endregion
}
}

View File

@@ -1,330 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Examine.SearchCriteria;
using Lucene.Net.Search;
namespace UmbracoExamine.SearchCriteria
{
public class LuceneQuery : IQuery
{
private LuceneSearchCriteria search;
private BooleanClause.Occur occurance;
/// <summary>
/// Initializes a new instance of the <see cref="LuceneQuery"/> class.
/// </summary>
/// <param name="search">The search.</param>
/// <param name="occurance">The occurance.</param>
internal LuceneQuery(LuceneSearchCriteria search, BooleanClause.Occur occurance)
{
this.search = search;
this.occurance = occurance;
}
/// <summary>
/// Gets the boolean operation which this query method will be added as
/// </summary>
/// <value>The boolean operation.</value>
public BooleanOperation BooleanOperation
{
get { return occurance.ToBooleanOperation(); }
}
#region ISearch Members
/// <summary>
/// Query on the id
/// </summary>
/// <param name="id">The id.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Id(int id)
{
return this.search.IdInternal(id, this.occurance);
}
/// <summary>
/// Query on the NodeName
/// </summary>
/// <param name="nodeName">Name of the node.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation NodeName(string nodeName)
{
return this.search.NodeNameInternal(new ExamineValue(Examineness.Explicit, nodeName), occurance);
}
/// <summary>
/// Query on the NodeTypeAlias
/// </summary>
/// <param name="nodeTypeAlias">The node type alias.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation NodeTypeAlias(string nodeTypeAlias)
{
return this.search.NodeTypeAliasInternal(new ExamineValue(Examineness.Explicit, nodeTypeAlias), occurance);
}
/// <summary>
/// Query on the Parent ID
/// </summary>
/// <param name="id">The id of the parent.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation ParentId(int id)
{
return this.search.ParentIdInternal(id, occurance);
}
/// <summary>
/// Query on the specified field
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="fieldValue">The field value.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Field(string fieldName, string fieldValue)
{
return this.search.FieldInternal(fieldName, new ExamineValue(Examineness.Explicit, fieldValue), occurance);
}
/// <summary>
/// Ranges the specified field name.
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Range(string fieldName, DateTime start, DateTime end)
{
return this.Range(fieldName, start, end, true, true);
}
/// <summary>
/// Ranges the specified field name.
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <param name="includeLower">if set to <c>true</c> [include lower].</param>
/// <param name="includeUpper">if set to <c>true</c> [include upper].</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Range(string fieldName, DateTime start, DateTime end, bool includeLower, bool includeUpper)
{
return this.search.Range(fieldName, start, end, includeLower, includeUpper);
}
/// <summary>
/// Ranges the specified field name.
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Range(string fieldName, int start, int end)
{
return this.Range(fieldName, start, end, true, true);
}
/// <summary>
/// Ranges the specified field name.
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <param name="includeLower">if set to <c>true</c> [include lower].</param>
/// <param name="includeUpper">if set to <c>true</c> [include upper].</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Range(string fieldName, int start, int end, bool includeLower, bool includeUpper)
{
return this.search.RangeInternal(fieldName, start, end, includeLower, includeUpper, occurance);
}
/// <summary>
/// Ranges the specified field name.
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Range(string fieldName, string start, string end)
{
return this.Range(fieldName, start, end, true, true);
}
/// <summary>
/// Ranges the specified field name.
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="start">The start.</param>
/// <param name="end">The end.</param>
/// <param name="includeLower">if set to <c>true</c> [include lower].</param>
/// <param name="includeUpper">if set to <c>true</c> [include upper].</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Range(string fieldName, string start, string end, bool includeLower, bool includeUpper)
{
return this.search.RangeInternal(fieldName, start, end, includeLower, includeUpper, occurance);
}
/// <summary>
/// Query on the NodeName
/// </summary>
/// <param name="nodeName">Name of the node.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation NodeName(IExamineValue nodeName)
{
return this.search.NodeNameInternal(nodeName, occurance);
}
/// <summary>
/// Query on the NodeTypeAlias
/// </summary>
/// <param name="nodeTypeAlias">The node type alias.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation NodeTypeAlias(IExamineValue nodeTypeAlias)
{
return this.search.NodeTypeAliasInternal(nodeTypeAlias, occurance);
}
/// <summary>
/// Query on the specified field
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="fieldValue">The field value.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Field(string fieldName, IExamineValue fieldValue)
{
return this.search.FieldInternal(fieldName, fieldValue, occurance);
}
/// <summary>
/// Queries multiple fields with each being an And boolean operation
/// </summary>
/// <param name="fields">The fields.</param>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation GroupedAnd(IEnumerable<string> fields, params string[] query)
{
var fieldVals = new List<IExamineValue>();
foreach (var f in query)
{
fieldVals.Add(new ExamineValue(Examineness.Explicit, f));
}
return this.search.GroupedAndInternal(fields.ToArray(), fieldVals.ToArray(), this.occurance);
}
/// <summary>
/// Queries multiple fields with each being an And boolean operation
/// </summary>
/// <param name="fields">The fields.</param>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation GroupedAnd(IEnumerable<string> fields, params IExamineValue[] query)
{
throw new NotImplementedException();
}
/// <summary>
/// Queries multiple fields with each being an Or boolean operation
/// </summary>
/// <param name="fields">The fields.</param>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation GroupedOr(IEnumerable<string> fields, params string[] query)
{
var fieldVals = new List<IExamineValue>();
foreach (var f in query)
{
fieldVals.Add(new ExamineValue(Examineness.Explicit, f));
}
return this.search.GroupedOrInternal(fields.ToArray(), fieldVals.ToArray(), this.occurance);
}
/// <summary>
/// Queries multiple fields with each being an Or boolean operation
/// </summary>
/// <param name="fields">The fields.</param>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation GroupedOr(IEnumerable<string> fields, params IExamineValue[] query)
{
return this.search.GroupedOrInternal(fields.ToArray(), query, this.occurance);
}
/// <summary>
/// Queries multiple fields with each being an Not boolean operation
/// </summary>
/// <param name="fields">The fields.</param>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation GroupedNot(IEnumerable<string> fields, params string[] query)
{
var fieldVals = new List<IExamineValue>();
foreach (var f in query)
{
fieldVals.Add(new ExamineValue(Examineness.Explicit, f));
}
return this.search.GroupedNotInternal(fields.ToArray(), fieldVals.ToArray(), this.occurance);
}
/// <summary>
/// Queries multiple fields with each being an Not boolean operation
/// </summary>
/// <param name="fields">The fields.</param>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation GroupedNot(IEnumerable<string> fields, params IExamineValue[] query)
{
return this.search.GroupedNotInternal(fields.ToArray(), query, this.occurance);
}
/// <summary>
/// Queries on multiple fields with their inclusions customly defined
/// </summary>
/// <param name="fields">The fields.</param>
/// <param name="operations">The operations.</param>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation GroupedFlexible(IEnumerable<string> fields, IEnumerable<BooleanOperation> operations, params string[] query)
{
var fieldVals = new List<IExamineValue>();
foreach (var f in query)
{
fieldVals.Add(new ExamineValue(Examineness.Explicit, f));
}
return this.search.GroupedFlexibleInternal(fields.ToArray(), operations.ToArray(), fieldVals.ToArray(), occurance);
}
/// <summary>
/// Queries on multiple fields with their inclusions customly defined
/// </summary>
/// <param name="fields">The fields.</param>
/// <param name="operations">The operations.</param>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation GroupedFlexible(IEnumerable<string> fields, IEnumerable<BooleanOperation> operations, params IExamineValue[] query)
{
return this.search.GroupedFlexibleInternal(fields.ToArray(), operations.ToArray(), query, occurance);
}
/// <summary>
/// Orders the results by the specified fields
/// </summary>
/// <param name="fieldNames">The field names.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation OrderBy(params string[] fieldNames)
{
return this.search.OrderBy(fieldNames);
}
/// <summary>
/// Orders the results by the specified fields in a descending order
/// </summary>
/// <param name="fieldNames">The field names.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation OrderByDescending(params string[] fieldNames)
{
return this.search.OrderByDescending(fieldNames);
}
#endregion
}
}

View File

@@ -1,559 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Examine;
using Examine.SearchCriteria;
using Lucene.Net.Analysis;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Search.Spans;
using Lucene.Net.Index;
using Lucene.Net.Documents;
namespace UmbracoExamine.SearchCriteria
{
/// <summary>
/// This class is used to query against Lucene.Net
/// </summary>
public class LuceneSearchCriteria : ISearchCriteria
{
internal MultiFieldQueryParser queryParser;
internal BooleanQuery query;
internal List<SortField> sortFields = new List<SortField>();
private readonly BooleanClause.Occur occurance;
private readonly Lucene.Net.Util.Version luceneVersion = Lucene.Net.Util.Version.LUCENE_29;
internal LuceneSearchCriteria(string type, Analyzer analyzer, string[] fields, bool allowLeadingWildcards, BooleanOperation occurance)
{
Enforcer.ArgumentNotNull(fields, "fields");
SearchIndexType = type;
query = new BooleanQuery();
this.BooleanOperation = occurance;
this.queryParser = new MultiFieldQueryParser(luceneVersion, fields, analyzer);
this.queryParser.SetAllowLeadingWildcard(allowLeadingWildcards);
this.occurance = occurance.ToLuceneOccurance();
}
/// <summary>
/// Gets the boolean operation which this query method will be added as
/// </summary>
/// <value>The boolean operation.</value>
public BooleanOperation BooleanOperation
{
get;
protected set;
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public override string ToString()
{
return string.Format("{{ SearchIndexType: {0}, LuceneQuery: {1} }}", this.SearchIndexType, this.query.ToString());
}
private static void ValidateIExamineValue(IExamineValue v)
{
var ev = v as ExamineValue;
if (ev == null)
{
throw new ArgumentException("IExamineValue was not created from this provider. Ensure that it is created from the ISearchCriteria this provider exposes");
}
}
#region ISearchCriteria Members
public string SearchIndexType
{
get;
protected set;
}
public bool IncludeHitCount
{
get;
set;
}
public int TotalHits
{
get;
internal protected set;
}
#endregion
#region ISearch Members
/// <summary>
/// Query on the id
/// </summary>
/// <param name="id">The id.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Id(int id)
{
return IdInternal(id, occurance);
}
internal protected IBooleanOperation IdInternal(int id, BooleanClause.Occur occurance)
{
//use a query parser (which uses the analyzer) to build up the field query which we want
query.Add(this.queryParser.GetFieldQuery(LuceneExamineIndexer.IndexNodeIdFieldName, id.ToString()), occurance);
return new LuceneBooleanOperation(this);
}
/// <summary>
/// Query on the NodeName
/// </summary>
/// <param name="nodeName">Name of the node.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation NodeName(string nodeName)
{
Enforcer.ArgumentNotNull(nodeName, "nodeName");
return NodeName(new ExamineValue(Examineness.Explicit, nodeName));
}
/// <summary>
/// Query on the NodeName
/// </summary>
/// <param name="nodeName">Name of the node.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation NodeName(IExamineValue nodeName)
{
Enforcer.ArgumentNotNull(nodeName, "nodeName");
return this.NodeNameInternal(nodeName, occurance);
}
internal protected IBooleanOperation NodeNameInternal(IExamineValue examineValue, BooleanClause.Occur occurance)
{
return this.FieldInternal("nodeName", examineValue, occurance);
}
/// <summary>
/// Query on the NodeTypeAlias
/// </summary>
/// <param name="nodeTypeAlias">The node type alias.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation NodeTypeAlias(string nodeTypeAlias)
{
Enforcer.ArgumentNotNull(nodeTypeAlias, "nodeTypeAlias");
return this.NodeTypeAlias(new ExamineValue(Examineness.Explicit, nodeTypeAlias));
}
/// <summary>
/// Query on the NodeTypeAlias
/// </summary>
/// <param name="nodeTypeAlias">The node type alias.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation NodeTypeAlias(IExamineValue nodeTypeAlias)
{
Enforcer.ArgumentNotNull(nodeTypeAlias, "nodeTypeAlias");
return this.NodeTypeAliasInternal(nodeTypeAlias, occurance);
}
internal protected IBooleanOperation NodeTypeAliasInternal(IExamineValue examineValue, BooleanClause.Occur occurance)
{
return this.FieldInternal("nodeTypeAlias", examineValue, occurance);
}
/// <summary>
/// Query on the Parent ID
/// </summary>
/// <param name="id">The id of the parent.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation ParentId(int id)
{
return this.ParentIdInternal(id, occurance);
}
internal protected IBooleanOperation ParentIdInternal(int id, BooleanClause.Occur occurance)
{
query.Add(this.queryParser.GetFieldQuery("parentID", id.ToString()), occurance);
return new LuceneBooleanOperation(this);
}
/// <summary>
/// Query on the specified field
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="fieldValue">The field value.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Field(string fieldName, string fieldValue)
{
Enforcer.ArgumentNotNull(fieldName, "fieldName");
Enforcer.ArgumentNotNull(fieldValue, "fieldValue");
return this.FieldInternal(fieldName, new ExamineValue(Examineness.Explicit, fieldValue), occurance);
}
/// <summary>
/// Query on the specified field
/// </summary>
/// <param name="fieldName">Name of the field.</param>
/// <param name="fieldValue">The field value.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation Field(string fieldName, IExamineValue fieldValue)
{
Enforcer.ArgumentNotNull(fieldName, "fieldName");
Enforcer.ArgumentNotNull(fieldValue, "fieldValue");
return this.FieldInternal(fieldName, fieldValue, occurance);
}
/// <summary>
/// Returns the Lucene query object for a field given an IExamineValue
/// </summary>
/// <param name="fieldName"></param>
/// <param name="fieldValue"></param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
internal protected Query GetFieldInternalQuery(string fieldName, IExamineValue fieldValue)
{
Query queryToAdd;
switch (fieldValue.Examineness)
{
case Examineness.Fuzzy:
queryToAdd = this.queryParser.GetFuzzyQuery(fieldName, fieldValue.Value, fieldValue.Level);
break;
case Examineness.SimpleWildcard:
case Examineness.ComplexWildcard:
queryToAdd = this.queryParser.GetWildcardQuery(fieldName, fieldValue.Value);
break;
case Examineness.Boosted:
queryToAdd = this.queryParser.GetFieldQuery(fieldName, fieldValue.Value);
queryToAdd.SetBoost(fieldValue.Level);
break;
case Examineness.Proximity:
//This is how you are supposed to do this based on this doc here:
//http://lucene.apache.org/java/2_4_1/api/org/apache/lucene/search/spans/package-summary.html#package_description
//but i think that lucene.net has an issue with it's internal parser since it parses to a very strange query
//we'll just manually make it instead below
//var spans = new List<SpanQuery>();
//foreach (var s in fieldValue.Value.Split(' '))
//{
// spans.Add(new SpanTermQuery(new Term(fieldName, s)));
//}
//queryToAdd = new SpanNearQuery(spans.ToArray(), Convert.ToInt32(fieldValue.Level), true);
var proxQuery = fieldName + ":\"" + fieldValue.Value + "\"~" + Convert.ToInt32(fieldValue.Level).ToString();
queryToAdd = queryParser.Parse(proxQuery);
break;
case Examineness.Explicit:
default:
queryToAdd = this.queryParser.GetFieldQuery(fieldName, fieldValue.Value);
break;
}
return queryToAdd;
}
internal protected IBooleanOperation FieldInternal(string fieldName, IExamineValue fieldValue, BooleanClause.Occur occurance)
{
Query queryToAdd = GetFieldInternalQuery(fieldName, fieldValue);
if (queryToAdd != null)
query.Add(queryToAdd, occurance);
return new LuceneBooleanOperation(this);
}
public IBooleanOperation Range(string fieldName, DateTime start, DateTime end)
{
return this.Range(fieldName, start, end, true, true);
}
public IBooleanOperation Range(string fieldName, DateTime start, DateTime end, bool includeLower, bool includeUpper)
{
//since lucene works on string's for all searching we need to flatten the date
return this.RangeInternal(fieldName, DateTools.DateToString(start, DateTools.Resolution.MILLISECOND), DateTools.DateToString(end, DateTools.Resolution.MILLISECOND), includeLower, includeUpper, occurance);
}
public IBooleanOperation Range(string fieldName, int start, int end)
{
Enforcer.ArgumentNotNull(fieldName, "fieldName");
return this.Range(fieldName, start, end, true, true);
}
public IBooleanOperation Range(string fieldName, int start, int end, bool includeLower, bool includeUpper)
{
return this.RangeInternal(fieldName, start, end, includeLower, includeUpper, occurance);
}
protected internal IBooleanOperation RangeInternal(string fieldName, int start, int end, bool includeLower, bool includeUpper, BooleanClause.Occur occurance)
{
query.Add(NumericRangeQuery.NewIntRange(fieldName, start, end, includeLower, includeUpper), occurance);
return new LuceneBooleanOperation(this);
}
public IBooleanOperation Range(string fieldName, string start, string end)
{
Enforcer.ArgumentNotNull(fieldName, "fieldName");
Enforcer.ArgumentNotNull(start, "start");
Enforcer.ArgumentNotNull(end, "end");
return this.Range(fieldName, start, end, true, true);
}
public IBooleanOperation Range(string fieldName, string start, string end, bool includeLower, bool includeUpper)
{
Enforcer.ArgumentNotNull(fieldName, "fieldName");
Enforcer.ArgumentNotNull(start, "start");
Enforcer.ArgumentNotNull(end, "end");
return this.RangeInternal(fieldName, start, end, includeLower, includeUpper, occurance);
}
protected internal IBooleanOperation RangeInternal(string fieldName, string start, string end, bool includeLower, bool includeUpper, BooleanClause.Occur occurance)
{
query.Add(new TermRangeQuery(fieldName, start, end, includeLower, includeUpper), occurance);
return new LuceneBooleanOperation(this);
}
public IBooleanOperation GroupedAnd(IEnumerable<string> fields, params string[] query)
{
Enforcer.ArgumentNotNull(fields, "fields");
Enforcer.ArgumentNotNull(query, "query");
var fieldVals = new List<IExamineValue>();
foreach (var f in query)
{
fieldVals.Add(new ExamineValue(Examineness.Explicit, f));
}
return this.GroupedAnd(fields.ToArray(), fieldVals.ToArray());
}
public IBooleanOperation GroupedAnd(IEnumerable<string> fields, IExamineValue[] fieldVals)
{
Enforcer.ArgumentNotNull(fields, "fields");
Enforcer.ArgumentNotNull(query, "fieldVals");
return this.GroupedAndInternal(fields.ToArray(), fieldVals.ToArray(), occurance);
}
protected internal IBooleanOperation GroupedAndInternal(string[] fields, IExamineValue[] fieldVals, BooleanClause.Occur occurance)
{
//if there's only 1 query text we want to build up a string like this:
//(+field1:query +field2:query +field3:query)
//but Lucene will bork if you provide an array of length 1 (which is != to the field length)
query.Add(GetMultiFieldQuery(fields, fieldVals, BooleanClause.Occur.MUST), occurance);
return new LuceneBooleanOperation(this);
}
public IBooleanOperation GroupedOr(IEnumerable<string> fields, params string[] query)
{
Enforcer.ArgumentNotNull(fields, "fields");
Enforcer.ArgumentNotNull(query, "query");
var fieldVals = new List<IExamineValue>();
foreach (var f in query)
{
fieldVals.Add(new ExamineValue(Examineness.Explicit, f));
}
return this.GroupedOr(fields.ToArray(), fieldVals.ToArray());
}
public IBooleanOperation GroupedOr(IEnumerable<string> fields, params IExamineValue[] fieldVals)
{
Enforcer.ArgumentNotNull(fields, "fields");
Enforcer.ArgumentNotNull(query, "query");
return this.GroupedOrInternal(fields.ToArray(), fieldVals, occurance);
}
protected internal IBooleanOperation GroupedOrInternal(string[] fields, IExamineValue[] fieldVals, BooleanClause.Occur occurance)
{
//if there's only 1 query text we want to build up a string like this:
//(field1:query field2:query field3:query)
//but Lucene will bork if you provide an array of length 1 (which is != to the field length)
query.Add(GetMultiFieldQuery(fields, fieldVals, BooleanClause.Occur.SHOULD), occurance);
return new LuceneBooleanOperation(this);
}
public IBooleanOperation GroupedNot(IEnumerable<string> fields, params string[] query)
{
Enforcer.ArgumentNotNull(fields, "fields");
Enforcer.ArgumentNotNull(query, "query");
var fieldVals = new List<IExamineValue>();
foreach (var f in query)
{
fieldVals.Add(new ExamineValue(Examineness.Explicit, f));
}
return this.GroupedNot(fields.ToArray(), fieldVals.ToArray());
}
public IBooleanOperation GroupedNot(IEnumerable<string> fields, params IExamineValue[] query)
{
Enforcer.ArgumentNotNull(fields, "fields");
Enforcer.ArgumentNotNull(query, "query");
return this.GroupedNotInternal(fields.ToArray(), query, occurance);
}
protected internal IBooleanOperation GroupedNotInternal(string[] fields, IExamineValue[] fieldVals, BooleanClause.Occur occurance)
{
//if there's only 1 query text we want to build up a string like this:
//(!field1:query !field2:query !field3:query)
//but Lucene will bork if you provide an array of length 1 (which is != to the field length)
query.Add(GetMultiFieldQuery(fields, fieldVals, BooleanClause.Occur.MUST_NOT), occurance);
return new LuceneBooleanOperation(this);
}
/// <summary>
/// Creates our own style 'multi field query' used internal for the grouped operations
/// </summary>
/// <param name="fields"></param>
/// <param name="fieldVals"></param>
/// <param name="occurance"></param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
protected internal BooleanQuery GetMultiFieldQuery(string[] fields, IExamineValue[] fieldVals, BooleanClause.Occur occurance)
{
//if there's only 1 query text we want to build up a string like this:
//(!field1:query !field2:query !field3:query)
//but Lucene will bork if you provide an array of length 1 (which is != to the field length)
var queryVals = new IExamineValue[fields.Length];
if (fieldVals.Length == 1)
{
for (int i = 0; i < queryVals.Length; i++)
queryVals[i] = fieldVals[0];
}
else
{
queryVals = fieldVals;
}
var qry = new BooleanQuery();
for (int i = 0; i < fields.Length; i++)
{
qry.Add(this.GetFieldInternalQuery(fields[i], queryVals[i]), occurance);
}
return qry;
}
public IBooleanOperation GroupedFlexible(IEnumerable<string> fields, IEnumerable<BooleanOperation> operations, params string[] query)
{
Enforcer.ArgumentNotNull(fields, "fields");
Enforcer.ArgumentNotNull(query, "query");
Enforcer.ArgumentNotNull(operations, "operations");
var fieldVals = new List<IExamineValue>();
foreach (var f in query)
{
fieldVals.Add(new ExamineValue(Examineness.Explicit, f));
}
return this.GroupedFlexible(fields.ToArray(), operations.ToArray(), fieldVals.ToArray());
}
public IBooleanOperation GroupedFlexible(IEnumerable<string> fields, IEnumerable<BooleanOperation> operations, params IExamineValue[] fieldVals)
{
Enforcer.ArgumentNotNull(fields, "fields");
Enforcer.ArgumentNotNull(query, "query");
Enforcer.ArgumentNotNull(operations, "operations");
return this.GroupedFlexibleInternal(fields.ToArray(), operations.ToArray(), fieldVals, occurance);
}
protected internal IBooleanOperation GroupedFlexibleInternal(string[] fields, BooleanOperation[] operations, IExamineValue[] fieldVals, BooleanClause.Occur occurance)
{
//if there's only 1 query text we want to build up a string like this:
//(field1:query field2:query field3:query)
//but Lucene will bork if you provide an array of length 1 (which is != to the field length)
var flags = new BooleanClause.Occur[operations.Count()];
for (int i = 0; i < flags.Length; i++)
flags[i] = operations.ElementAt(i).ToLuceneOccurance();
var queryVals = new IExamineValue[fields.Length];
if (fieldVals.Length == 1)
{
for (int i = 0; i < queryVals.Length; i++)
queryVals[i] = fieldVals[0];
}
else
{
queryVals = fieldVals;
}
var qry = new BooleanQuery();
for (int i = 0; i < fields.Length; i++)
{
qry.Add(this.GetFieldInternalQuery(fields[i], queryVals[i]), flags[i]);
}
this.query.Add(qry, occurance);
return new LuceneBooleanOperation(this);
}
/// <summary>
/// Passes a raw search query to the provider to handle
/// </summary>
/// <param name="query">The query.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public ISearchCriteria RawQuery(string query)
{
this.query.Add(this.queryParser.Parse(query), this.occurance);
return this;
}
/// <summary>
/// Orders the results by the specified fields
/// </summary>
/// <param name="fieldNames">The field names.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation OrderBy(params string[] fieldNames)
{
Enforcer.ArgumentNotNull(fieldNames, "fieldNames");
return this.OrderByInternal(false, fieldNames);
}
/// <summary>
/// Orders the results by the specified fields in a descending order
/// </summary>
/// <param name="fieldNames">The field names.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
public IBooleanOperation OrderByDescending(params string[] fieldNames)
{
Enforcer.ArgumentNotNull(fieldNames, "fieldNames");
return this.OrderByInternal(true, fieldNames);
}
/// <summary>
/// Internal operation for adding the ordered results
/// </summary>
/// <param name="descending">if set to <c>true</c> [descending].</param>
/// <param name="fieldNames">The field names.</param>
/// <returns>A new <see cref="Examine.SearchCriteria.IBooleanOperation"/> with the clause appended</returns>
protected internal IBooleanOperation OrderByInternal(bool descending, params string[] fieldNames)
{
foreach (var fieldName in fieldNames)
{
this.sortFields.Add(new SortField(LuceneExamineIndexer.SortedFieldNamePrefix + fieldName, SortField.STRING, descending));
}
return new LuceneBooleanOperation(this);
}
#endregion
}
}

View File

@@ -1,164 +0,0 @@
using Examine.SearchCriteria;
using Lucene.Net.Search;
using Lucene.Net.QueryParsers;
using System;
namespace UmbracoExamine.SearchCriteria
{
public static class LuceneSearchExtensions
{
/// <summary>
/// Adds a single character wildcard to the string for Lucene wildcard matching
/// </summary>
/// <param name="s">The string to wildcard.</param>
/// <returns>An IExamineValue for the required operation</returns>
/// <exception cref="System.ArgumentException">Thrown when the string is null or empty</exception>
public static IExamineValue SingleCharacterWildcard(this string s)
{
if (System.String.IsNullOrEmpty(s))
throw new ArgumentException("Supplied string is null or empty.", "s");
return new ExamineValue(Examineness.SimpleWildcard, s + "?");
}
/// <summary>
/// Adds a multi-character wildcard to a string for Lucene wildcard matching
/// </summary>
/// <param name="s">The string to wildcard.</param>
/// <returns>An IExamineValue for the required operation</returns>
/// <exception cref="System.ArgumentException">Thrown when the string is null or empty</exception>
public static IExamineValue MultipleCharacterWildcard(this string s)
{
if (String.IsNullOrEmpty(s))
throw new ArgumentException("Supplied string is null or empty.", "s");
return new ExamineValue(Examineness.ComplexWildcard, s + "*");
}
/// <summary>
/// Configures the string for fuzzy matching in Lucene using the default fuzziness level
/// </summary>
/// <param name="s">The string to configure fuzzy matching on.</param>
/// <returns>An IExamineValue for the required operation</returns>
/// <exception cref="System.ArgumentException">Thrown when the string is null or empty</exception>
public static IExamineValue Fuzzy(this string s)
{
return Fuzzy(s, 0.5f);
}
/// <summary>
/// Configures the string for fuzzy matching in Lucene using the supplied fuzziness level
/// </summary>
/// <param name="s">The string to configure fuzzy matching on.</param>
/// <param name="fuzzieness">The fuzzieness level.</param>
/// <returns>
/// An IExamineValue for the required operation
/// </returns>
/// <exception cref="System.ArgumentException">Thrown when the string is null or empty</exception>
public static IExamineValue Fuzzy(this string s, float fuzzieness)
{
if (String.IsNullOrEmpty(s))
throw new ArgumentException("Supplied string is null or empty.", "s");
return new ExamineValue(Examineness.Fuzzy, s, fuzzieness);
}
/// <summary>
/// Configures the string for boosting in Lucene
/// </summary>
/// <param name="s">The string to wildcard.</param>
/// <param name="boost">The boost level.</param>
/// <returns>
/// An IExamineValue for the required operation
/// </returns>
/// <exception cref="System.ArgumentException">Thrown when the string is null or empty</exception>
public static IExamineValue Boost(this string s, float boost)
{
if (String.IsNullOrEmpty(s))
throw new ArgumentException("Supplied string is null or empty.", "s");
return new ExamineValue(Examineness.Boosted, s + "^", boost);
}
/// <summary>
/// Configures the string for proximity matching
/// </summary>
/// <param name="s">The string to wildcard.</param>
/// <param name="proximity">The proximity level.</param>
/// <returns>
/// An IExamineValue for the required operation
/// </returns>
/// <exception cref="System.ArgumentException">Thrown when the string is null or empty</exception>
public static IExamineValue Proximity(this string s, int proximity)
{
if (String.IsNullOrEmpty(s))
throw new ArgumentException("Supplied string is null or empty.", "s");
return new ExamineValue(Examineness.Proximity, s + "~", Convert.ToSingle(proximity));
}
/// <summary>
/// Escapes the string within Lucene
/// </summary>
/// <param name="s">The string to wildcard.</param>
/// <returns>An IExamineValue for the required operation</returns>
/// <exception cref="System.ArgumentException">Thrown when the string is null or empty</exception>
public static IExamineValue Escape(this string s)
{
if (String.IsNullOrEmpty(s))
throw new ArgumentException("Supplied string is null or empty.", "s");
return new ExamineValue(Examineness.Escaped, QueryParser.Escape(s));
}
/// <summary>
/// Sets up an <see cref="IExamineValue"/> for an additional Examiness
/// </summary>
/// <param name="examineValue">The IExamineValue to continue working with.</param>
/// <param name="s">The string to postfix.</param>
/// <returns>Combined strings</returns>
public static string Then(this IExamineValue examineValue, string s)
{
if (examineValue == null)
throw new ArgumentNullException("examineValue", "examineValue is null.");
if (String.IsNullOrEmpty(s))
throw new ArgumentException("Supplied string is null or empty.", "s");
return examineValue.Value + s;
}
/// <summary>
/// Converts an Examine boolean operation to a Lucene representation
/// </summary>
/// <param name="o">The operation.</param>
/// <returns>The translated Boolean operation</returns>
public static BooleanClause.Occur ToLuceneOccurance(this BooleanOperation o)
{
switch (o)
{
case BooleanOperation.And:
return BooleanClause.Occur.MUST;
case BooleanOperation.Not:
return BooleanClause.Occur.MUST_NOT;
case BooleanOperation.Or:
default:
return BooleanClause.Occur.SHOULD;
}
}
/// <summary>
/// Converts a Lucene boolean occurrence to an Examine representation
/// </summary>
/// <param name="o">The occurrence to translate.</param>
/// <returns>The translated boolean occurrence</returns>
public static BooleanOperation ToBooleanOperation(this BooleanClause.Occur o)
{
if (o == BooleanClause.Occur.MUST)
{
return BooleanOperation.And;
}
else if (o == BooleanClause.Occur.MUST_NOT)
{
return BooleanOperation.Not;
}
else
{
return BooleanOperation.Or;
}
}
}
}