Skip to content

Commit 9c1b147

Browse files
committed
Merge branch 'dev'
# Conflicts: # docs/searching.md
2 parents f5afffe + a869cbb commit 9c1b147

File tree

162 files changed

+56016
-44674
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+56016
-44674
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
with:
4141
dotnet-version: 5.0.x
4242

43+
- name: Setup .NET SDK 6.0.x
44+
uses: actions/setup-dotnet@v2
45+
with:
46+
dotnet-version: 6.0.x
47+
4348
- name: Install GitVersion
4449
uses: gittools/actions/gitversion/setup@v0.9.9
4550
with:
@@ -56,8 +61,6 @@ jobs:
5661

5762
- name: Test
5863
run: dotnet test "${{ env.Test_Proj }}" --no-build --verbosity normal --results-directory ${{ github.workspace }}/_TestResults --logger "trx;logfilename=tests.trx"
59-
60-
# TODO: Update the script to build the nuget packages (for now we use dev-ops)
6164

6265
- name: Upload test results
6366
uses: actions/upload-artifact@v2 # upload test results

docs/Gemfile.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
addressable (2.7.0)
5-
public_suffix (>= 2.0.2, < 5.0)
4+
addressable (2.8.1)
5+
public_suffix (>= 2.0.2, < 6.0)
66
colorator (1.1.0)
77
concurrent-ruby (1.1.6)
88
em-websocket (0.5.1)
@@ -14,7 +14,7 @@ GEM
1414
http_parser.rb (0.6.0)
1515
i18n (0.9.5)
1616
concurrent-ruby (~> 1.0)
17-
jekyll (3.9.0)
17+
jekyll (3.9.2)
1818
addressable (~> 2.4)
1919
colorator (~> 1.0)
2020
em-websocket (~> 0.5)
@@ -27,7 +27,7 @@ GEM
2727
pathutil (~> 0.9)
2828
rouge (>= 1.7, < 4)
2929
safe_yaml (~> 1.0)
30-
jekyll-feed (0.12.1)
30+
jekyll-feed (0.17.0)
3131
jekyll (>= 3.7, < 5.0)
3232
jekyll-readme-index (0.2.0)
3333
jekyll (~> 3.0)
@@ -48,22 +48,22 @@ GEM
4848
kramdown-parser-gfm (1.1.0)
4949
kramdown (~> 2.0)
5050
liquid (4.0.3)
51-
listen (3.2.1)
51+
listen (3.7.1)
5252
rb-fsevent (~> 0.10, >= 0.10.3)
5353
rb-inotify (~> 0.9, >= 0.9.10)
5454
mercenary (0.3.6)
55-
mini_portile2 (2.5.1)
55+
mini_portile2 (2.8.0)
5656
minima (2.5.1)
5757
jekyll (>= 3.5, < 5.0)
5858
jekyll-feed (~> 0.9)
5959
jekyll-seo-tag (~> 2.1)
60-
nokogiri (1.11.5)
61-
mini_portile2 (~> 2.5.0)
60+
nokogiri (1.13.9)
61+
mini_portile2 (~> 2.8.0)
6262
racc (~> 1.4)
6363
pathutil (0.16.2)
6464
forwardable-extended (~> 2.6)
65-
public_suffix (4.0.5)
66-
racc (1.5.2)
65+
public_suffix (4.0.7)
66+
racc (1.6.0)
6767
rb-fsevent (0.10.4)
6868
rb-inotify (0.10.1)
6969
ffi (~> 1.0)
@@ -76,7 +76,7 @@ GEM
7676
rb-fsevent (~> 0.9, >= 0.9.4)
7777
rb-inotify (~> 0.9, >= 0.9.7)
7878
thread_safe (0.3.6)
79-
tzinfo (1.2.5)
79+
tzinfo (1.2.10)
8080
thread_safe (~> 0.1)
8181
tzinfo-data (1.2019.3)
8282
tzinfo (>= 1.0.0)

docs/searching.md

Lines changed: 157 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _**Tip**: There are many examples of searching in the [`FluentApiTests` source c
1212

1313
## All fields (managed queries)
1414

15-
The simplest way of querying with examine is with the `Search` method:
15+
The simplest way of querying with Examine is with the `Search` method:
1616

1717
```cs
1818
var results = searcher.Search("hello world");
@@ -21,8 +21,8 @@ var results = searcher.Search("hello world");
2121
The above is just shorthand for doing this:
2222

2323
```cs
24-
var query = CreateQuery().ManagedQuery("hello world");
25-
var results = sc.Execute(options);
24+
var query = searcher.CreateQuery().ManagedQuery("hello world");
25+
var results = query.Execute(QueryOptions.Default);
2626
```
2727

2828
A Managed query is a search operation that delegates to the underlying field types to determine how the field should
@@ -31,110 +31,222 @@ be searched. In most cases the field value type will be 'Full Text', others may
3131
## Per field
3232

3333
```csharp
34-
var searcher = myIndex.GetSearcher(); // Get a searcher
34+
var searcher = myIndex.Searcher; // Get a searcher
3535
var results = searcher.CreateQuery() // Create a query
3636
.Field("Address", "Hills") // Look for any "Hills" addresses
3737
.Execute(); // Execute the search
3838
```
3939

40+
### Terms and Phrases
41+
42+
When searching on fields like in the example above you might want to search on more than one word/term. In Examine this can be done by simply adding more terms to the field filter.
43+
44+
```csharp
45+
var searcher = myIndex.Searcher;
46+
var results = searcher.CreateQuery()
47+
// Look for any addresses that has "Hills" or "Rockyroad" or "Hollywood"
48+
.Field("Address", "Hills Rockyroad Hollywood")
49+
.Execute();
50+
```
51+
52+
The way that terms are split depends on the Analyzer being used. The StandardAnalyzer is the default. An example of how Analyzers work are:
53+
54+
- StandardAnalyzer - will split a string based on whitespace and 'stop words' (i.e. common words that are not normally searched on like "and")
55+
- WhitespaceAnalyzer - will split a string based only on whitespace
56+
- KeywordAnalyzer - will not split a string and will treat the single string as one term - this means that searching will be done on an exact match
57+
58+
There are many [Analyzers](https://lucenenet.apache.org/docs/4.8.0-beta00016/api/core/Lucene.Net.Analysis.html) and you can even create your own. See more about analyzers in [configuration](./configuration.md#example---phone-number).
59+
60+
Looking at this example when using the default StandardAnalyser the code above means that the `Address` in this example has to match any the values set in the statement. This is because Examine will create a Lucene query like this one where every word is matched separately: `Address:hills Address:rockyroad Address:hollywood`.
61+
62+
Instead, if you want to search for entries with the values above in that exact order you specified you will need to use the `.Escape()` method. See under [Escape](#escape).
63+
64+
```csharp
65+
var searcher = myIndex.Searcher;
66+
var results = searcher.CreateQuery()
67+
// Look for any addresses with the exact phrase "Hills Rockyroad Hollywood"
68+
.Field("Address", "Hills Rockyroad Hollywood".Escape())
69+
.Execute();
70+
```
71+
72+
This creates a query like this instead: `Address:"Hills Rockyroad Hollywood"`. This means that you're now searching for the exact phrase instead of entries where terms appear.
73+
4074
## Range queries
4175

76+
Range Queries allow one to match documents whose field(s) values are between the lower and upper bound specified by the Range Query
77+
4278
### Float Range
4379

80+
Example:
81+
4482
```csharp
45-
var searcher = indexer.GetSearcher();
46-
var criteria1 = searcher.CreateQuery();
47-
var filter1 = criteria1.RangeQuery<float>(new[] { "SomeFloat" }, 0f, 100f, true, true);
83+
var searcher = myIndex.Searcher;
84+
var query = searcher.CreateQuery();
85+
query.RangeQuery<float>(new[] { "SomeFloat" }, 0f, 100f, minInclusive: true, maxInclusive: true);
86+
var results = query.Execute(QueryOptions.Default);
4887
```
4988

89+
This will return results where the field `SomeFloat` is within the range 0 - 100 (min value and max value included).
90+
5091
### Date Range
5192

93+
Example:
94+
5295
```csharp
53-
var searcher = indexer.GetSearcher();
96+
var searcher = indexer.Searcher;
5497

55-
var numberSortedCriteria = searcher.CreateQuery()
98+
var query = searcher.CreateQuery()
5699
.RangeQuery<DateTime>(
57-
new[] { "created" },
58-
new DateTime(2000, 01, 02),
59-
new DateTime(2000, 01, 05),
100+
new[] { "created" },
101+
new DateTime(2000, 01, 02),
102+
new DateTime(2000, 01, 05),
103+
minInclusive: true,
60104
maxInclusive: false);
105+
106+
var results = query.Execute();
61107
```
62108

109+
This will return results where the field `created` is within the date 2000/01/02 and 2000/01/05 (min value included and max value excluded).
110+
63111
## Booleans, Groups & Sub Groups
64112

65113
_TODO: Fill this in..._
66114

67-
## Lucene queries
115+
## Boosting
68116

69-
### Native Query
117+
Boosting is the practice of making some parts of your query more relevant than others. This means that you can have terms that will make entries matching that term score higher in the search results.
70118

71-
```csharp
72-
var searcher = indexer.GetSearcher();
119+
Example:
73120

74-
var results = searcher.CreateQuery().NativeQuery("hello:world").Execute();
121+
```csharp
122+
var searcher = indexer.Searcher;
123+
var query = searcher.CreateQuery("content");
124+
query.Field("nodeTypeAlias", "CWS_Home".Boost(20));
125+
var results = query.Execute();
75126
```
76127

77-
### Combine a custom lucene query with raw lucene query
128+
This will boost the term `CWS_Home` and make enteries with `nodeTypeAlias:CWS_Home` score higher in the results.
78129

79-
```csharp
80-
var searcher = indexer.GetSearcher();
81-
var query = (LuceneSearchQuery)searcher.CreateQuery();
130+
## Proximity
82131

83-
// first create the Native Query and suffix with an And() call.
84-
var op = criteria.NativeQuery("hello:world").And();
132+
Proximity searching helps in finding entries where words that are within a specific distance away from each other.
85133

86-
// use the original LuceneSearchQuery instance to append
87-
// the next query value.
88-
query.LuceneQuery(NumericRangeQuery.NewInt64Range("numTest", 4, 5, true, true));
134+
Example:
89135

136+
```csharp
137+
var searcher = indexer.Searcher;
138+
var query = searcher.CreateQuery("content");
139+
140+
// Get all nodes that contain the words warren and creative within 5 words of each other
141+
query.Field("metaKeywords", "Warren creative".Proximity(5));
90142
var results = query.Execute();
91143
```
144+
## Fuzzy
145+
146+
Fuzzy searching is the practice of finding spellings that are similar to each other. Examine searches based on the [Damerau-Levenshtein Distance](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance). The parameter given in the `.Fuzzy()` method is the edit distance allowed by default this value is `0.5` if not specified.
92147

93-
## Boosting, Proximity, Fuzzy & Escape
148+
The value on `.Fuzzy()` can be between 0 and 2. Any number higher than 2 will be lowered to 2 when creating the query.
94149

95-
### Boosting
150+
Example:
96151

97152
```csharp
98-
var searcher = indexer.GetSearcher();
153+
var searcher = indexer.Searcher;
154+
var query = searcher.CreateQuery();
99155

156+
query.Field("Content", "think".Fuzzy(0.1F));
157+
var results = query.Execute();
158+
```
159+
160+
## Escape
161+
162+
Escapes the string within Lucene.
100163

101-
var criteria = searcher.CreateQuery("content");
164+
```csharp
165+
var searcher = indexer.Searcher;
166+
var query = searcher.CreateQuery("content");
102167

103-
var filter = criteria.Field("nodeTypeAlias", "CWS_Home".Boost(20));
168+
query.Field("__Path", "-1,123,456,789".Escape());
169+
var results = query.Execute();
104170
```
105171

106-
### Proximity
172+
## Wildcards
173+
174+
Examine supports single and multiple-character wildcards on single terms. (Cannot be used with the `.Escape()` method)
175+
176+
### Examine query (Single character)
177+
178+
The `.SingleCharacterWildcard()` method will add a single character wildcard to the end of the term or terms being searched on a field.
107179

108180
```csharp
109-
var searcher = indexer.GetSearcher();
181+
var query = searcher.CreateQuery()
182+
.Field("type", "test".SingleCharacterWildcard());
183+
```
110184

111-
//Arrange
185+
This will match for example: `test` and `tests`
112186

113-
var criteria = searcher.CreateQuery("content");
187+
### Examine query (Multiple characters)
114188

115-
//get all nodes that contain the words warren and creative within 5 words of each other
116-
var filter = criteria.Field("metaKeywords", "Warren creative".Proximity(5));
189+
The `.MultipleCharacterWildcard()` method will add a multiple characters wildcard to the end of the term or terms being searched on a field.
190+
191+
```csharp
192+
var query = searcher.CreateQuery()
193+
.Field("type", "test".MultipleCharacterWildcard());
117194
```
118195

119-
### Fuzzy
196+
This will match for example: `test`, `tests` , `tester`, `testers`
197+
### Lucene native query (Multiple characters)
120198

199+
The multiple wildcard character is `*`. It will match 0 or more characters.
200+
201+
Example
121202
```csharp
122-
var searcher = indexer.GetSearcher();
123-
var criteria = searcher.CreateQuery();
203+
var query = searcher.CreateQuery()
204+
.NativeQuery("equipment:t*pad");
205+
```
206+
207+
This will match for example: `Trackpad` and `Teleportationpad`
208+
209+
Example
124210

125-
var filter = criteria.Field("Content", "think".Fuzzy(0.1F));
211+
```csharp
212+
var query = searcher.CreateQuery()
213+
.NativeQuery("role:test*");
126214
```
127215

128-
### Escape
216+
This will match for example: `test`, `tests` and `tester`
217+
218+
## Lucene queries
219+
220+
Find a reference to how to write Lucene queries in the [Lucene 4.8.0 docs](https://lucene.apache.org/core/4_8_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package_description).
221+
222+
### Native Query
129223

130224
```csharp
131-
var exactcriteria = searcher.CreateQuery("content");
225+
var searcher = indexer.Searcher;
226+
var query = searcher.CreateQuery();
227+
var results = query.NativeQuery("hello:world").Execute();
228+
```
132229

133-
var exactfilter = exactcriteria.Field("__Path", "-1,123,456,789".Escape());
230+
### Combine a native query and Fluent API searching.
134231

135-
var results2 = exactfilter.Execute();
232+
```csharp
233+
var searcher = indexer.Searcher;
234+
var query = searcher.CreateQuery();
235+
query.NativeQuery("hello:world");
236+
query.And().Field("Address", "Hills"); // Combine queries
237+
var results = query.Execute();
136238
```
137239

240+
### Combine a custom lucene query with raw lucene query
241+
242+
```csharp
243+
var searcher = indexer.Searcher;
244+
var query = searcher.CreateQuery();
245+
246+
var query = (LuceneSearchQuery)query.NativeQuery("hello:world").And(); // Make query ready for extending
247+
query.LuceneQuery(NumericRangeQuery.NewInt64Range("numTest", 4, 5, true, true)); // Add the raw lucene query
248+
var results = query.Execute();
249+
```
138250
### Lucene Searches
139251

140252
Sometimes you need access to the underlying Lucene.NET APIs to perform a manual Lucene search.

0 commit comments

Comments
 (0)