lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Todd Lucas" ...@toddlucas.net>
Subject RE: Visual Studio 2017 / Working Demo for Current Build
Date Wed, 31 May 2017 02:44:55 GMT
Hi Anthony,

The beta works fine on VS 2017 for me. Be sure to check ‘Include prerelease’ in NuGet.


 

Here is a sample that I was using for sanity checking the beta. I couldn’t find the original
source. You’ll find various versions of it if you search the Web. I just updated it to 4.8.

 

I created a .NET Core console app (netcoreapp1.1) and it worked fine.

 

using System;

 

using Lucene.Net.Analysis;

using Lucene.Net.Analysis.Standard;

using Lucene.Net.Documents;

using Lucene.Net.Index;

using Lucene.Net.Store;

using Lucene.Net.Util;

using Lucene.Net.Search;

 

namespace LuceneSample

{

    class Program

    {

        static void Main(string[] args)

        {

            //

            // 1. Initialize

            //

 

            Directory directory = FSDirectory.Open("LuceneIndex");

            Analyzer analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);

            using (IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(LuceneVersion.LUCENE_48,
analyzer)))

            {

                //

                // 2. Add documents to the index.

                //

 

                Document doc = new Document();

                doc.Add(new StringField("id", "1", Field.Store.YES));

                doc.Add(new TextField("postBody", "abc 123", Field.Store.YES));

                writer.AddDocument(doc);

 

                doc = new Document();

                doc.Add(new StringField("id", "2", Field.Store.YES));

                doc.Add(new TextField("postBody", "xyz abc", Field.Store.YES));

                writer.AddDocument(doc);

 

                // Close the writer

                // writer.Flush();

                // writer.Close();

            }

 

            //

            // 3. Create the query

            //

 

            Query query = new TermQuery(new Term("postBody", "abc"));

 

            //

            // Step 4 – Pass the Query to the IndexSearcher

            //

 

            // Setup searcher

            DirectoryReader indexReader = DirectoryReader.Open(directory);

            var indexSearcher = new IndexSearcher(indexReader);

 

            // Do the search

            TopDocs hits = indexSearcher.Search(query, 10);

 

            //

            // 5. Iterate over the results

            //

 

            int results = hits.TotalHits;

            Console.WriteLine("Found {0} results", results);

            for (int i = 0; i < results; i++)

            {

                ScoreDoc scoreDoc = hits.ScoreDocs[i];

                int docId = scoreDoc.Doc;

                float score = scoreDoc.Score;

 

                Document doc = indexSearcher.Doc(docId);

                Console.WriteLine("Result num {0}, score {1}", i + 1, score);

                Console.WriteLine("ID: {0}", doc.Get("id"));

                Console.WriteLine("Text found: {0}" + Environment.NewLine, doc.Get("postBody"));

            }

        }

    }

}

 

From: Anthony Gatlin [mailto:anthony.gatlin@happycatfish.com] 
Sent: Tuesday, May 30, 2017 4:06 PM
To: dev@lucenenet.apache.org
Subject: Visual Studio 2017 / Working Demo for Current Build

 

The LuceneNET GitHub site says that only Visual Studio 2015 is supported for Lucene.NET 4.8
 builds and that Visual Studio 2017 is not supported. 

 

Can anyone provide any insight as to why Visual Studio 2017 is not supported and if this is
something that will soon be resolved?

 

What I am really wanting/needing to do is to actually get some kind of functioning demo that
works with the latest GitHub commit or MyGet build so that I can actually begin learning Lucene
in preparation for applying it on a .NET Standard project. 

It seems like the namespaces and methods have radically changed over the past few versions,
and I have been unable to find a single demo that actually works on 4.8 builds. 

 

Even Itamar Synershko's 4.8 demo ( https://channel9.msdn.com/Blogs/MVP-VisualStudio-Dev/LuceneNET-48-a-pre-release-introduction
 / https://github.com/synhershko/LuceneNetDemo ) appears to have issues. 

For starters, I was unable to perform a .NET restore on  the referenced Lucene.NET packages.
When I updated them with the latest version from MyGet, the build failed. 

There is an Analyzer called the HtmlStripAnalyzerWrapper.

using System.IO;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.CharFilters;
 
namespace LuceneNetDemo.Analyzers
{
    class HtmlStripAnalyzerWrapper : Analyzer
    {
        private readonly Analyzer _wrappedAnalyzer;
 
        public HtmlStripAnalyzerWrapper(Analyzer wrappedAnalyzer)
        {
            _wrappedAnalyzer = wrappedAnalyzer;
        }
 
        public override TokenStreamComponents CreateComponents(string fieldName, TextReader
reader)
        {
            
            return _wrappedAnalyzer.CreateComponents(fieldName, new HTMLStripCharFilter(reader));
        }
    }
}

 

The build is throwing an error here.

 

        public override TokenStreamComponents CreateComponents(string fieldName, TextReader
reader)
        {
            
            return _wrappedAnalyzer.CreateComponents(fieldName, new HTMLStripCharFilter(reader));
        }

 



 

It appears that the access modifiers for a method may have been changed from public to protected.
Being unfamiliar with Lucene, I am unsure how to workaround the issue.

 

Severity   Code Description     Project    File Line     Suppression State

Error CS0507     'HtmlStripAnalyzerWrapper.CreateComponents(string, TextReader)': cannot change
access modifiers when overriding 'protected internal' inherited member 'Analyzer.CreateComponents(string,
TextReader)'  LuceneNetDemo E:\Projects\LuceneNetDemo\LuceneNetDemo\Analyzers\HtmlStripAnalyzerWrapper.cs
    16   Active

 

Severity   Code Description     Project    File Line     Suppression State

Error CS1540     Cannot access protected member 'Analyzer.CreateComponents(string, TextReader)'
via a qualifier of type 'Analyzer'; the qualifier must be of type 'HtmlStripAnalyzerWrapper'
(or derived from it)  LuceneNetDemo E:\Projects\LuceneNetDemo\LuceneNetDemo\Analyzers\HtmlStripAnalyzerWrapper.cs
    19   Active

 

I am new to Lucene.NET. I want to learn it. I want to use it. I am absolutely thrilled about
the possibilities it offers. I am a little discouraged because there just do not seem to up-to-date
demos or much recent documentation.

If someone could point me in the right direction for getting a 4.8 demo working, I would much
appreciate it. I would also welcome links to any up-to-date documentation.

Many thanks!



 

 

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message