You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2020/10/23 13:58:06 UTC

[lucenenet] 02/08: website: Updated code samples to include using blocks and made path xplat

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 15968734e9e5482e754397cfd2263bd3878e9681
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Fri Oct 23 16:11:10 2020 +0700

    website: Updated code samples to include using blocks and made path xplat
---
 .../partials/home-quick-start.tmpl.partial         | 37 +++++++++++++---------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/websites/site/lucenetemplate/partials/home-quick-start.tmpl.partial b/websites/site/lucenetemplate/partials/home-quick-start.tmpl.partial
index 4819950..adc85fd 100644
--- a/websites/site/lucenetemplate/partials/home-quick-start.tmpl.partial
+++ b/websites/site/lucenetemplate/partials/home-quick-start.tmpl.partial
@@ -1,25 +1,30 @@
 <section id="quick-start" class="home-section">
 <div class="container">
 <div class="row">
-<div class="col-xs-12 col-md-6">
+<div class="col-xs-12 col-lg-6">
 <p class="text-center">Create an index and define a text analyzer</p>
 <pre class="clean">
-<code class="csharp">// Ensures index backwards compatibility
-var AppLuceneVersion = LuceneVersion.LUCENE_48;
+<code class="csharp">
+// Ensures index backwards compatibility
+const LuceneVersion AppLuceneVersion = LuceneVersion.LUCENE_48;
 
-var indexLocation = @"C:\Index";
-var dir = FSDirectory.Open(indexLocation);
+// Construct a machine-independent path for the index
+var personalFolder = Environment.SpecialFolder.Personal;
+var basePath = Environment.GetFolderPath(personalFolder);
+var indexPath = Path.Combine(basePath, "index");
 
-//create an analyzer to process the text
+using var dir = FSDirectory.Open(indexPath);
+
+// Create an analyzer to process the text
 var analyzer = new StandardAnalyzer(AppLuceneVersion);
 
-//create an index writer
+// Create an index writer
 var indexConfig = new IndexWriterConfig(AppLuceneVersion, analyzer);
-var writer = new IndexWriter(dir, indexConfig);
+using var writer = new IndexWriter(dir, indexConfig);
 </code>
 </pre>
 </div>
-<div class="col-xs-12 col-md-6">
+<div class="col-xs-12 col-lg-6">
 <p class="text-center">Add to the index</p>
 <pre class="clean">
 <code class="csharp">var source = new
@@ -27,7 +32,7 @@ var writer = new IndexWriter(dir, indexConfig);
     Name = "Kermit the Frog",
     FavoritePhrase = "The quick brown fox jumps over the lazy dog"
 };
-Document doc = new Document
+var doc = new Document
 {
     // StringField indexes but doesn't tokenize
     new StringField("name", 
@@ -41,13 +46,14 @@ Document doc = new Document
 writer.AddDocument(doc);
 writer.Flush(triggerMerge: false, applyAllDeletes: false);
 </code>
+</pre>
 </div>
 </div>
 <div class="row">
-<div class="col-xs-12 col-md-6">
+<div class="col-xs-12 col-lg-6">
 <p class="text-center">Construct a query</p>
 <pre class="clean">
-<code class="csharp">// search with a phrase
+<code class="csharp">// Search with a phrase
 var phrase = new MultiPhraseQuery
 {
     new Term("favoritePhrase", "brown"),
@@ -56,11 +62,12 @@ var phrase = new MultiPhraseQuery
 </code>
 </pre>
 </div>                    
-<div class="col-xs-12 col-md-6">
+<div class="col-xs-12 col-lg-6">
 <p class="text-center">Fetch the results</p>
 <pre class="clean">
-<code class="csharp">// re-use the writer to get real-time updates
-var searcher = new IndexSearcher(writer.GetReader(applyAllDeletes: true));
+<code class="csharp">// Re-use the writer to get real-time updates
+using var reader = writer.GetReader(applyAllDeletes: true);
+var searcher = new IndexSearcher(reader);
 var hits = searcher.Search(phrase, 20 /* top 20 */).ScoreDocs;
 foreach (var hit in hits)
 {