Skip to content

Commit 9a6bdb0

Browse files
committed
Search 2
1 parent 55d1553 commit 9a6bdb0

16 files changed

Lines changed: 308 additions & 162 deletions

src/Libraries/SmartStore.Core/Collections/MultiMap.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,27 @@ public class Multimap<TKey, TValue> : IEnumerable<KeyValuePair<TKey, ICollection
2121
private readonly bool _isReadonly = false;
2222

2323
public Multimap()
24-
: this(false)
24+
: this(false, null)
2525
{
2626
}
2727

28-
internal Multimap(bool threadSafe)
28+
public Multimap(IEqualityComparer<TKey> comparer)
29+
: this(false, comparer)
30+
{
31+
}
32+
33+
public Multimap(bool threadSafe, IEqualityComparer<TKey> comparer)
2934
{
30-
if (threadSafe)
35+
comparer = comparer ?? EqualityComparer<TKey>.Default;
36+
37+
if (threadSafe)
3138
{
32-
_items = new ConcurrentDictionary<TKey, ICollection<TValue>>();
39+
_items = new ConcurrentDictionary<TKey, ICollection<TValue>>(comparer);
3340
_listCreator = () => new SynchronizedCollection<TValue>();
3441
}
3542
else
3643
{
37-
_items = new Dictionary<TKey, ICollection<TValue>>();
44+
_items = new Dictionary<TKey, ICollection<TValue>>(comparer);
3845
_listCreator = () => new List<TValue>();
3946
}
4047
}
@@ -264,11 +271,6 @@ private void CheckNotReadonly()
264271

265272
#region Static members
266273

267-
public static Multimap<TKey, TValue> ThreadSafe()
268-
{
269-
return new Multimap<TKey, TValue>(true);
270-
}
271-
272274
public static Multimap<TKey, TValue> CreateFromLookup(ILookup<TKey, TValue> source)
273275
{
274276
Guard.NotNull(source, nameof(source));

src/Libraries/SmartStore.Core/Indexing/ISearchEngine.cs

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/Libraries/SmartStore.Core/Indexing/Readme.txt

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SmartStore.Core.Search
8+
{
9+
public class DefaultIndexManager : IIndexManager
10+
{
11+
private readonly IEnumerable<IIndexProvider> _providers;
12+
13+
public DefaultIndexManager(IEnumerable<IIndexProvider> providers)
14+
{
15+
_providers = providers;
16+
}
17+
18+
public bool HasAnyProvider()
19+
{
20+
return _providers.Any();
21+
}
22+
23+
public IIndexProvider GetProvider()
24+
{
25+
return _providers.FirstOrDefault();
26+
}
27+
28+
29+
}
30+
}

src/Libraries/SmartStore.Core/Search/IIndexDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace SmartStore.Core.Search
88
{
99
public interface IIndexDocument : IEnumerable<IndexField>
1010
{
11+
int Id { get; }
1112
int Count { get; }
1213
void Add(IndexField field);
1314
int Remove(string name);
1415
bool Contains(string name);
15-
IndexField this[int index] { get; }
1616
IEnumerable<IndexField> this[string name] { get; }
1717
}
1818

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SmartStore.Core.Search
8+
{
9+
public interface IIndexManager
10+
{
11+
bool HasAnyProvider();
12+
IIndexProvider GetProvider();
13+
}
14+
}

src/Libraries/SmartStore.Core/Search/ISearchHit.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23

34
namespace SmartStore.Core.Search
45
{
@@ -12,5 +13,7 @@ public interface ISearchHit
1213
bool GetBoolean(string name);
1314
string GetString(string name);
1415
DateTime GetDateTime(string name);
16+
17+
IEnumerable<string> GetStoredFieldNames();
1518
}
1619
}

src/Libraries/SmartStore.Core/Search/ISearchQuery.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using SmartStore.Collections;
6+
7+
namespace SmartStore.Core.Search
8+
{
9+
public class IndexDocument : IIndexDocument
10+
{
11+
private readonly Multimap<string, IndexField> _fields;
12+
13+
public IndexDocument(int id)
14+
{
15+
_fields = new Multimap<string, IndexField>(StringComparer.OrdinalIgnoreCase);
16+
_fields.Add("id", new IndexField("id", id).Store());
17+
}
18+
19+
public int Id
20+
{
21+
get
22+
{
23+
return (int)_fields["id"].FirstOrDefault().Value;
24+
}
25+
}
26+
27+
public int Count => _fields.TotalValueCount;
28+
29+
public void Add(IndexField field)
30+
{
31+
if (field.Name.IsCaseInsensitiveEqual("id") && _fields.ContainsKey("id"))
32+
{
33+
// special treatment for id field: allow only one!
34+
_fields.RemoveAll("id");
35+
}
36+
_fields.Add(field.Name, field);
37+
}
38+
39+
public int Remove(string name)
40+
{
41+
if (_fields.ContainsKey(name))
42+
{
43+
var num = _fields[name].Count;
44+
_fields.RemoveAll(name);
45+
return num;
46+
}
47+
48+
return 0;
49+
}
50+
51+
public bool Contains(string name)
52+
{
53+
return _fields.ContainsKey(name);
54+
}
55+
56+
public IEnumerable<IndexField> this[string name]
57+
{
58+
get
59+
{
60+
if (_fields.ContainsKey(name))
61+
{
62+
return _fields[name];
63+
}
64+
65+
return Enumerable.Empty<IndexField>();
66+
}
67+
}
68+
69+
70+
public IEnumerator<IndexField> GetEnumerator()
71+
{
72+
return _fields.SelectMany(x => x.Value).GetEnumerator();
73+
}
74+
75+
IEnumerator IEnumerable.GetEnumerator()
76+
{
77+
return GetEnumerator();
78+
}
79+
}
80+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SmartStore.Core.Search
8+
{
9+
public abstract class IndexProviderBase : IIndexProvider
10+
{
11+
public abstract IEnumerable<string> EnumerateIndexes();
12+
13+
public virtual IIndexDocument CreateDocument(int id)
14+
{
15+
Guard.IsPositive(id, nameof(id));
16+
return new IndexDocument(id);
17+
}
18+
19+
public abstract IIndexStore GetIndexStore(string scope);
20+
21+
public abstract ISearchEngine GetSearchEngine(IIndexStore store, SearchQuery query);
22+
}
23+
}

0 commit comments

Comments
 (0)