Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code snippets on https://lucenenet.apache.org/ doesn't works. #453

Closed
Kuinox opened this issue Mar 26, 2021 · 6 comments
Closed

Code snippets on https://lucenenet.apache.org/ doesn't works. #453

Kuinox opened this issue Mar 26, 2021 · 6 comments

Comments

@Kuinox
Copy link

Kuinox commented Mar 26, 2021

Hello,
I'm currently trying to get started on lucene.net, but no success so far.
First small issue:
The snippet on https://lucenenet.apache.org/ requires Lucene.Net.Analysis.Common which was not indicated.
Second issue, if I simply copy/paste the first snippet, it throws me a Lucene.Net.Index.IndexNotFoundException: 'no segments* file found in [truncated], on the IndexWriter constructor.

@NightOwl888
Copy link
Contributor

Thanks for letting us know about the issues you are having with the examples on the home page. We will surely look into finding ways to make the code that you see there runnable.

In the meantime, there are several runnable demos that you can inspect to get a feel for how the components work together to provide indexing and search:

General Search

Faceted Search

Runnable Demos

Do note that all of the above examples from Lucene.Net.Demo are compiled into the lucene-cli tool where they can be run if you don't happen to have handy access to an IDE. The code can also be viewed on the console and output to your local file system.

@Kuinox
Copy link
Author

Kuinox commented Mar 26, 2021

I tried to run the cli to see if the issue is not specific to my PC, but it look like the CLI need configuration after install and the doc doesn't specify it:

PS C:\Users\Kuinox> lucene
Unhandled exception. System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\Users\Kuinox\.dotnet\tools\.store\lucene-cli\4.8.0-beta00013\lucene-cli\4.8.0-beta00013\tools\netcoreapp3.1\any\appsettings.json'.
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Lucene.Net.Cli.Program.Main(String[] args) in D:\a\1\s\src\dotnet\tools\lucene-cli\Program.cs:line 27

So I found out that, the demo is working, but I was catching every exception and never let it run to completion ><.

@NightOwl888
Copy link
Contributor

Thanks for the additional report. I have confirmed the behavior and discovered this has been failing since 4.8.0-beta00009.

F:\Projects\lucenenet>dotnet tool install lucene-cli -g --version 4.8.0-beta00013
You can invoke the tool using the following command: lucene
Tool 'lucene-cli' (version '4.8.0-beta00013') was successfully installed.

F:\Projects\lucenenet>lucene
Unhandled exception. System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\Users\shad\.dotnet\tools\.store\lucene-cli\4.8.0-beta00013\lucene-cli\4.8.0-beta00013\tools\netcoreapp3.1\any\appsettings.json'.
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Lucene.Net.Cli.Program.Main(String[] args) in D:\a\1\s\src\dotnet\tools\lucene-cli\Program.cs:line 27

F:\Projects\lucenenet>dotnet tool uninstall lucene-cli -g
Tool 'lucene-cli' (version '4.8.0-beta00013') was successfully uninstalled.

F:\Projects\lucenenet>dotnet tool install lucene-cli -g --version 4.8.0-beta00012
You can invoke the tool using the following command: lucene
Tool 'lucene-cli' (version '4.8.0-beta00012') was successfully installed.

F:\Projects\lucenenet>lucene
Unhandled exception. System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\Users\shad\.dotnet\tools\.store\lucene-cli\4.8.0-beta00012\lucene-cli\4.8.0-beta00012\tools\netcoreapp3.1\any\appsettings.json'.
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Lucene.Net.Cli.Program.Main(String[] args) in D:\a\1\s\src\dotnet\tools\lucene-cli\Program.cs:line 27

F:\Projects\lucenenet>dotnet tool uninstall lucene-cli -g
Tool 'lucene-cli' (version '4.8.0-beta00012') was successfully uninstalled.

F:\Projects\lucenenet>dotnet tool install lucene-cli -g --version 4.8.0-beta00011
You can invoke the tool using the following command: lucene
Tool 'lucene-cli' (version '4.8.0-beta00011') was successfully installed.

F:\Projects\lucenenet>lucene
Unhandled exception. System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\Users\shad\.dotnet\tools\.store\lucene-cli\4.8.0-beta00011\lucene-cli\4.8.0-beta00011\tools\netcoreapp3.1\any\appsettings.json'.
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Lucene.Net.Cli.Program.Main(String[] args) in D:\a\1\s\src\dotnet\tools\lucene-cli\Program.cs:line 27

F:\Projects\lucenenet>
F:\Projects\lucenenet>dotnet tool uninstall lucene-cli -g
Tool 'lucene-cli' (version '4.8.0-beta00011') was successfully uninstalled.

F:\Projects\lucenenet>dotnet tool install lucene-cli -g --version 4.8.0-beta00010
You can invoke the tool using the following command: lucene
Tool 'lucene-cli' (version '4.8.0-beta00010') was successfully installed.

F:\Projects\lucenenet>lucene
Unhandled exception. System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\Users\shad\.dotnet\tools\.store\lucene-cli\4.8.0-beta00010\lucene-cli\4.8.0-beta00010\tools\netcoreapp3.1\any\appsettings.json'.
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Lucene.Net.Cli.Program.Main(String[] args) in D:\a\1\s\src\dotnet\tools\lucene-cli\Program.cs:line 27

F:\Projects\lucenenet>dotnet tool uninstall lucene-cli -g
Tool 'lucene-cli' (version '4.8.0-beta00010') was successfully uninstalled.

F:\Projects\lucenenet>dotnet tool install lucene-cli -g --version 4.8.0-beta00009
You can invoke the tool using the following command: lucene
Tool 'lucene-cli' (version '4.8.0-beta00009') was successfully installed.

F:\Projects\lucenenet>lucene
Unhandled exception. System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'C:\Users\shad\.dotnet\tools\.store\lucene-cli\4.8.0-beta00009\lucene-cli\4.8.0-beta00009\tools\netcoreapp3.1\any\appsettings.json'.
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Lucene.Net.Cli.Program.Main(String[] args) in D:\a\1\s\src\dotnet\tools\lucene-cli\Program.cs:line 27

F:\Projects\lucenenet>dotnet tool uninstall lucene-cli -g
Tool 'lucene-cli' (version '4.8.0-beta00009') was successfully uninstalled.

F:\Projects\lucenenet>dotnet tool install lucene-cli -g --version 4.8.0-beta00008
You can invoke the tool using the following command: lucene
Tool 'lucene-cli' (version '4.8.0-beta00008') was successfully installed.

F:\Projects\lucenenet>lucene
 Lucene.Net Command Line Utility, Version: 4.8.0-beta00008 commit:[c63b8834c6]

Usage:  [command]

Commands:
  analysis   Utilities to manage specialized analyzers.
  benchmark  Utilities for benchmarking Lucene.Net.
  demo       Demos for various Lucene.Net functionality including C# code samples.
  index      Utilities to analyze or maintain an index.
  lock       Utilities for verifying concurrent locking integrity.

Use " [command] --help" for more information about a command.


F:\Projects\lucenenet>

It seems that when the Microsoft.Extensions.Configuration features were added, the default option of requiring an appsettings.json file was chosen instead of allowing it to be optional.

I am considering just supplying a appsettings.json file with all of the default settings to make it clearer which settings are available in lucene-cli until we have documentation (see #307). But even with a default file, it should still be made optional.

In addition, it is clear we need some basic smoke tests to ensure that the tool will install and run without throwing exceptions.

In the meantime, you can work around this problem by manually adding an empty JSON file named appsettings.json to the appropriate directory on your system.

appsettings.json

{
}

IMPORTANT: There must be at least opening and closing curly brackets in the file, or it won't be parsed as valid JSON.

The location it is looking for the file on your system in is in the error message:

The physical path is 'C:\Users\Kuinox\.dotnet\tools\.store\lucene-cli\4.8.0-beta00013\lucene-cli\4.8.0-beta00013\tools\netcoreapp3.1\any\appsettings.json'.

But if you need more help locating where the tool is located, see How to manage .NET tools.

@Kuinox
Copy link
Author

Kuinox commented Mar 26, 2021

I was running the tool only to know if LuceneNet could run on my machine :p.

Is it expected that Lucene.Net throws exceptions internally (but catches them) in normal operations?

@NightOwl888
Copy link
Contributor

NightOwl888 commented Mar 26, 2021

I was running the tool only to know if LuceneNet could run on my machine :p.

Is it expected that Lucene.Net throws exceptions internally (but catches them) in normal operations?

This is a line-by-line port of Java Lucene. The designers made the unfortunate choice of relying on exceptions for control flow by using exceptions as messages similar to events. This behavior was deemed too much of a risk to change due to the fact that some bugs can only be found by comparing where the execution paths diverge between Lucene and Lucene.NET.

@NightOwl888 NightOwl888 self-assigned this Mar 27, 2021
NightOwl888 added a commit to NightOwl888/lucenenet that referenced this issue Mar 27, 2021
NightOwl888 added a commit to NightOwl888/lucenenet that referenced this issue Mar 27, 2021
…d run it to ensure it can be installed and has basic functionality. (See apache#453)
NightOwl888 added a commit to NightOwl888/lucenenet that referenced this issue Mar 27, 2021
…t server, since it is required by installation tests (See apache#453)
NightOwl888 added a commit to NightOwl888/lucenenet that referenced this issue Mar 27, 2021
…d run it to ensure it can be installed and has basic functionality. (See apache#453)
NightOwl888 added a commit to NightOwl888/lucenenet that referenced this issue Mar 27, 2021
…t server, since it is required by installation tests (See apache#453)
NightOwl888 added a commit to NightOwl888/lucenenet that referenced this issue Mar 27, 2021
…d run it to ensure it can be installed and has basic functionality. (See apache#453)
NightOwl888 added a commit to NightOwl888/lucenenet that referenced this issue Mar 27, 2021
…t server, since it is required by installation tests (See apache#453)
@NightOwl888 NightOwl888 removed their assignment Mar 27, 2021
NightOwl888 added a commit that referenced this issue Apr 5, 2021
…d run it to ensure it can be installed and has basic functionality. (See #453)
NightOwl888 added a commit that referenced this issue Apr 5, 2021
…t server, since it is required by installation tests (See #453)
@NightOwl888
Copy link
Contributor

Closing as #453 fixes the appsettings.json problem and #457 is tracking the hope page code sample issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants