forked from SolrNet/SolrNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance improvement on SolrQueryInList
Previously the SolrQueryInList serialiser would print out a query on the field "id" with the list {1,2,3} as: id:(1) OR id:(2) OR id:(3) I replaced this with: id:((1) OR (2) OR (3))
- Loading branch information
Stephen Lacy
committed
Oct 1, 2012
1 parent
952cf17
commit 2a8b85a
Showing
4 changed files
with
94 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,94 @@ | ||
#region license | ||
// Copyright (c) 2007-2010 Mauricio Scheffer | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
#endregion | ||
|
||
using System; | ||
using MbUnit.Framework; | ||
using SolrNet.Impl.FieldSerializers; | ||
using SolrNet.Impl.QuerySerializers; | ||
|
||
namespace SolrNet.DSL.Tests { | ||
[TestFixture] | ||
public class QueryBuildingTests { | ||
|
||
public string Serialize(object q) { | ||
var serializer = new DefaultQuerySerializer(new DefaultFieldSerializer()); | ||
return serializer.Serialize(q); | ||
} | ||
|
||
|
||
[Test] | ||
public void Simple() { | ||
var q = Query.Simple("name:solr"); | ||
Assert.AreEqual("name:solr", q.Query); | ||
} | ||
|
||
[Test] | ||
public void FieldValue() { | ||
var q = Query.Field("name").Is("solr"); | ||
Assert.AreEqual("name:(solr)", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void FieldValueDecimal() { | ||
var q = Query.Field("price").Is(400); | ||
Assert.AreEqual("price:(400)", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void FieldValueEmpty() { | ||
var q = Query.Field("price").Is(""); | ||
Assert.AreEqual("price:(\"\")", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void FieldValueNot() { | ||
var q = Query.Field("name").Is("solr").Not(); | ||
Assert.AreEqual("-name:(solr)", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
#region license | ||
// Copyright (c) 2007-2010 Mauricio Scheffer | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
#endregion | ||
|
||
using System; | ||
using MbUnit.Framework; | ||
using SolrNet.Impl.FieldSerializers; | ||
using SolrNet.Impl.QuerySerializers; | ||
|
||
namespace SolrNet.DSL.Tests { | ||
[TestFixture] | ||
public class QueryBuildingTests { | ||
|
||
public string Serialize(object q) { | ||
var serializer = new DefaultQuerySerializer(new DefaultFieldSerializer()); | ||
return serializer.Serialize(q); | ||
} | ||
|
||
|
||
[Test] | ||
public void Simple() { | ||
var q = Query.Simple("name:solr"); | ||
Assert.AreEqual("name:solr", q.Query); | ||
} | ||
|
||
[Test] | ||
public void FieldValue() { | ||
var q = Query.Field("name").Is("solr"); | ||
Assert.AreEqual("name:(solr)", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void FieldValueDecimal() { | ||
var q = Query.Field("price").Is(400); | ||
Assert.AreEqual("price:(400)", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void FieldValueEmpty() { | ||
var q = Query.Field("price").Is(""); | ||
Assert.AreEqual("price:(\"\")", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void FieldValueNot() { | ||
var q = Query.Field("name").Is("solr").Not(); | ||
Assert.AreEqual("-name:(solr)", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void FieldValueRequired() { | ||
var q = Query.Field("name").Is("solr").Required(); | ||
Assert.AreEqual("+name:(solr)", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void Range() { | ||
var q = Query.Field("price").From(10).To(20); | ||
Assert.AreEqual("price:[10 TO 20]", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void InList() { | ||
var q = Query.Field("price").In(10, 20, 30); | ||
Assert.AreEqual("(price:(10) OR price:(20) OR price:(30))", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void InList_empty_is_ignored() { | ||
var q = Query.Field("price").In(new string[0]) && Query.Field("id").Is(123); | ||
var query = Serialize(q); | ||
Console.WriteLine(query); | ||
Assert.AreEqual("(id:(123))", query); | ||
} | ||
|
||
[Test] | ||
public void HasValue() { | ||
var q = Query.Field("name").HasAnyValue(); | ||
Assert.AreEqual("name:[* TO *]", Serialize(q)); | ||
} | ||
} | ||
public void Range() { | ||
var q = Query.Field("price").From(10).To(20); | ||
Assert.AreEqual("price:[10 TO 20]", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void InList() { | ||
var q = Query.Field("price").In(10, 20, 30); | ||
Assert.AreEqual("(price:((10) OR (20) OR (30)))", Serialize(q)); | ||
} | ||
|
||
[Test] | ||
public void InList_empty_is_ignored() { | ||
var q = Query.Field("price").In(new string[0]) && Query.Field("id").Is(123); | ||
var query = Serialize(q); | ||
Console.WriteLine(query); | ||
Assert.AreEqual("(id:(123))", query); | ||
} | ||
|
||
[Test] | ||
public void HasValue() { | ||
var q = Query.Field("name").HasAnyValue(); | ||
Assert.AreEqual("name:[* TO *]", Serialize(q)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters