Ben
Ben

Reputation: 11

Issues with code when upgrading to Lucene .net 4.8.0-beta0004

I upgraded Lucene.net in my C sharp application from 3.0.3 to 4.8.0-beta0004 and I also installed the last version of Lucene.net.analysis.common and Lucene.net.queries.

Several lines in my code are throwing errors:

Error 1:) Analyzer standAnalyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

The error is : The type or the namespace name "StandardAnalyzer" could not be found.

Error 2) Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Content", standAnalyzer);

The error is: The type or the namespace name "QueryParsers" does not exist in the namespace 'Lucene.Net'

Error 3) Lucene.Net.Search.Searcher schr = new Lucene.Net.Search.IndexSearcher(Lucene.Net.Index.IndexReader.Open(directory, true));

The error is : The type or the namespace name "Searcher" does not exist in the namespace 'Lucene.Net.Search'

I'm using the following namaspace in my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Lucene.Net.Analysis;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Search.Spans;

Could be please help? Thanks

Upvotes: 1

Views: 1441

Answers (2)

user2316116
user2316116

Reputation: 6814

The most recent prerelease version, which is now 4.8.0-beta00008, has no Lucene.Net.Analysis.Common in the main NuGet package (i.e. previous answer with using Lucene.Net.Analysis.Standard will not work). The namespace can be installed additionally as

Install-Package Lucene.Net -Version 4.8.0-beta00008 
Install-Package Lucene.Net.Analysis.Common -Version 4.8.0-beta00008

https://www.nuget.org/packages/Lucene.Net.Analysis.Common/

Upvotes: 1

NightOwl888
NightOwl888

Reputation: 56859

The project structure of Lucene changed greatly from 3.x to 4.x and increased in size by more than a factor of 10. As a result, many of the classes are no longer in the same Namespace as they were previously.

  1. StandardAnalyzer - add using Lucene.Net.Analysis.Standard.
  2. QueryParser - add using Lucene.Net.QueryParsers.Classic. Note there are now many other types of QueryParsers available.
  3. IndexSearcher - there is no longer an abstract Searcher base class. The simplest way to fix this would be to change the line to: var schr = new Lucene.Net.Search.IndexSearcher(Lucene.Net.Index.IndexReader.Open(directory, true));

For future reference, you can view the Lucene 4.8.0 API doucmentation (in Java) to see how the project structure has changed. Lucene.Net followed this structure very closely.

Also, using Visual Studio 2015 or higher, there is a nice feature that allows you do automatically add the using statements based on the class name. You just need to hover over the type that is underlined in red, and click on the little light bulb dropdown.

enter image description here

Upvotes: 2

Related Questions