lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mhern...@apache.org
Subject [05/12] git commit: Port QueryParsers.Ext namespace
Date Sun, 06 Oct 2013 23:05:57 GMT
Port QueryParsers.Ext namespace


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/93d96323
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/93d96323
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/93d96323

Branch: refs/heads/branch_4x
Commit: 93d96323805cb710e23897651f4b4f4c481ec331
Parents: b31a8ce
Author: Paul Irwin <paulirwin@gmail.com>
Authored: Thu Oct 3 12:36:21 2013 -0400
Committer: Paul Irwin <paulirwin@gmail.com>
Committed: Thu Oct 3 12:36:21 2013 -0400

----------------------------------------------------------------------
 .../QueryParsers/Contrib.QueryParsers.csproj    |  4 +
 .../QueryParsers/Ext/ExtendableQueryParser.cs   | 51 +++++++++++
 src/contrib/QueryParsers/Ext/ExtensionQuery.cs  | 47 +++++++++++
 src/contrib/QueryParsers/Ext/Extensions.cs      | 89 ++++++++++++++++++++
 src/contrib/QueryParsers/Ext/ParserExtension.cs | 14 +++
 5 files changed, 205 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/93d96323/src/contrib/QueryParsers/Contrib.QueryParsers.csproj
----------------------------------------------------------------------
diff --git a/src/contrib/QueryParsers/Contrib.QueryParsers.csproj b/src/contrib/QueryParsers/Contrib.QueryParsers.csproj
index 6ca31a9..a9f08d6 100644
--- a/src/contrib/QueryParsers/Contrib.QueryParsers.csproj
+++ b/src/contrib/QueryParsers/Contrib.QueryParsers.csproj
@@ -50,6 +50,10 @@
     <Compile Include="Classic\QueryParserTokenManager.cs" />
     <Compile Include="Classic\Token.cs" />
     <Compile Include="Classic\TokenMgrError.cs" />
+    <Compile Include="Ext\ExtendableQueryParser.cs" />
+    <Compile Include="Ext\ExtensionQuery.cs" />
+    <Compile Include="Ext\Extensions.cs" />
+    <Compile Include="Ext\ParserExtension.cs" />
     <Compile Include="Flexible\Standard\ICommonQueryParserConfiguration.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/93d96323/src/contrib/QueryParsers/Ext/ExtendableQueryParser.cs
----------------------------------------------------------------------
diff --git a/src/contrib/QueryParsers/Ext/ExtendableQueryParser.cs b/src/contrib/QueryParsers/Ext/ExtendableQueryParser.cs
new file mode 100644
index 0000000..6c75179
--- /dev/null
+++ b/src/contrib/QueryParsers/Ext/ExtendableQueryParser.cs
@@ -0,0 +1,51 @@
+using Lucene.Net.Analysis;
+using Lucene.Net.QueryParsers.Classic;
+using Lucene.Net.Search;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Version = Lucene.Net.Util.Version;
+
+namespace Lucene.Net.QueryParsers.Ext
+{
+    public class ExtendableQueryParser : QueryParser
+    {
+        private readonly String defaultField;
+        private readonly Extensions extensions;
+
+        private static readonly Extensions DEFAULT_EXTENSION = new Extensions();
+
+        public ExtendableQueryParser(Version matchVersion, string f, Analyzer a)
+            : this(matchVersion, f, a, DEFAULT_EXTENSION)
+        {
+        }
+
+        public ExtendableQueryParser(Version matchVersion, string f, Analyzer a, Extensions
ext)
+            : base(matchVersion, f, a)
+        {
+            this.defaultField = f;
+            this.extensions = ext;
+        }
+
+        public char ExtensionFieldDelimiter
+        {
+            get
+            {
+                return extensions.ExtensionFieldDelimiter;
+            }
+        }
+
+        protected override Query GetFieldQuery(string field, string queryText, bool quoted)
+        {
+            var splitExtensionField = this.extensions.SplitExtensionField(defaultField, field);
+            ParserExtension extension = this.extensions.GetExtension(splitExtensionField.cud);
+            if (extension != null)
+            {
+                return extension.Parse(new ExtensionQuery(this, splitExtensionField.cur,
queryText));
+            }
+            return base.GetFieldQuery(field, queryText, quoted);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/93d96323/src/contrib/QueryParsers/Ext/ExtensionQuery.cs
----------------------------------------------------------------------
diff --git a/src/contrib/QueryParsers/Ext/ExtensionQuery.cs b/src/contrib/QueryParsers/Ext/ExtensionQuery.cs
new file mode 100644
index 0000000..a83218d
--- /dev/null
+++ b/src/contrib/QueryParsers/Ext/ExtensionQuery.cs
@@ -0,0 +1,47 @@
+using Lucene.Net.QueryParsers.Classic;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lucene.Net.QueryParsers.Ext
+{
+    public class ExtensionQuery
+    {
+        private readonly string field;
+        private readonly string rawQueryString;
+        private readonly QueryParser topLevelParser;
+
+        public ExtensionQuery(QueryParser topLevelParser, string field, string rawQueryString)
+        {
+            this.field = field;
+            this.rawQueryString = rawQueryString;
+            this.topLevelParser = topLevelParser;
+        }
+
+        public string Field
+        {
+            get
+            {
+                return field;
+            }
+        }
+
+        public string RawQueryString
+        {
+            get
+            {
+                return rawQueryString;
+            }
+        }
+
+        public QueryParser TopLevelParser
+        {
+            get
+            {
+                return topLevelParser;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/93d96323/src/contrib/QueryParsers/Ext/Extensions.cs
----------------------------------------------------------------------
diff --git a/src/contrib/QueryParsers/Ext/Extensions.cs b/src/contrib/QueryParsers/Ext/Extensions.cs
new file mode 100644
index 0000000..52dbab1
--- /dev/null
+++ b/src/contrib/QueryParsers/Ext/Extensions.cs
@@ -0,0 +1,89 @@
+using Lucene.Net.QueryParsers.Classic;
+using Lucene.Net.Support;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lucene.Net.QueryParsers.Ext
+{
+    public class Extensions
+    {
+        private readonly IDictionary<string, ParserExtension> extensions = new HashMap<string,
ParserExtension>();
+        private readonly char extensionFieldDelimiter;
+
+        public const char DEFAULT_EXTENSION_FIELD_DELIMITER = ':';
+
+        public Extensions()
+            : this(DEFAULT_EXTENSION_FIELD_DELIMITER)
+        {
+        }
+
+        public Extensions(char extensionFieldDelimiter)
+        {
+            this.extensionFieldDelimiter = extensionFieldDelimiter;
+        }
+
+        public virtual void Add(string key, ParserExtension extension)
+        {
+            this.extensions[key] = extension;
+        }
+
+        public ParserExtension GetExtension(string key)
+        {
+            return this.extensions[key];
+        }
+
+        public char ExtensionFieldDelimiter
+        {
+            get
+            {
+                return extensionFieldDelimiter;
+            }
+        }
+
+        public Pair<string, string> SplitExtensionField(string defaultField, string
field)
+        {
+            int indexOf = field.IndexOf(this.extensionFieldDelimiter);
+            if (indexOf < 0)
+                return new Pair<string, string>(field, null);
+            string indexField = indexOf == 0 ? defaultField : field.Substring(0, indexOf);
+            string extensionKey = field.Substring(indexOf + 1);
+            return new Pair<string, string>(indexField, extensionKey);
+        }
+
+        public string EscapeExtensionField(string extfield)
+        {
+            return QueryParserBase.Escape(extfield);
+        }
+
+        public string BuildExtensionField(string extensionKey)
+        {
+            return BuildExtensionField(extensionKey, "");
+        }
+
+        public string BuildExtensionField(string extensionKey, string field)
+        {
+            StringBuilder builder = new StringBuilder(field);
+            builder.Append(this.extensionFieldDelimiter);
+            builder.Append(extensionKey);
+            return EscapeExtensionField(builder.ToString());
+        }
+
+        public class Pair<Cur, Cud>
+        {
+            // .NET Port: We could use Tuple<T1, T2> instead of this, but I ported
this class
+            // so that there wouldn't be any confusion as to which of {cur,cud} comes first.
+
+            public readonly Cur cur;
+            public readonly Cud cud;
+
+            public Pair(Cur cur, Cud cud)
+            {
+                this.cur = cur;
+                this.cud = cud;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/93d96323/src/contrib/QueryParsers/Ext/ParserExtension.cs
----------------------------------------------------------------------
diff --git a/src/contrib/QueryParsers/Ext/ParserExtension.cs b/src/contrib/QueryParsers/Ext/ParserExtension.cs
new file mode 100644
index 0000000..058f9d6
--- /dev/null
+++ b/src/contrib/QueryParsers/Ext/ParserExtension.cs
@@ -0,0 +1,14 @@
+using Lucene.Net.Search;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lucene.Net.QueryParsers.Ext
+{
+    public abstract class ParserExtension
+    {
+        public abstract Query Parse(ExtensionQuery query);
+    }
+}


Mime
View raw message