### Start Luke with JAR Source: https://github.com/apache/lucene/blob/main/lucene/luke/src/distribution/README.md Use this command to start Luke when running from a JAR file. Ensure the correct Java version is installed. ```bash java -jar ${luke.cmd} ``` -------------------------------- ### Interactive Program Notice Example Source: https://github.com/apache/lucene/blob/main/lucene/demo/src/test/org/apache/lucene/demo/test-files/docs/gpl1.0.txt Display this short notice when an interactive program starts to inform users about its version, warranty, and redistribution conditions. The commands like `show w` and `show c` should display relevant license details. ```text Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Display All Gradle Help Guides Source: https://github.com/apache/lucene/blob/main/CONTRIBUTING.md Execute this command to view all available help guides that explain various parts of the build system. ```bash ./gradlew help ``` -------------------------------- ### Start Luke with Java Modules Source: https://github.com/apache/lucene/blob/main/lucene/luke/src/distribution/README.md This command starts Luke using Java modules. It requires specifying the module path and adding the 'jdk.unsupported' module. ```bash java --module-path . --add-modules jdk.unsupported --module org.apache.lucene.luke ``` -------------------------------- ### BoostingQuery Example Source: https://github.com/apache/lucene/blob/main/lucene/queryparser/docs/xml/LuceneContribQuery.dtd.html Illustrates how to use BoostingQuery to find documents matching a primary query while optionally boosting or de-boosting based on a secondary query. This example finds documents about banks, preferably related to mergers, and preferably not about 'World bank'. ```xml merger bank "world bank" ``` -------------------------------- ### BM25 Similarity Implementation in Lucene Source: https://github.com/apache/lucene/blob/main/lucene/CHANGES.txt Example of how to set the BM25 similarity for all fields in an IndexSearcher. For per-field configurations, implement PerFieldSimilarityWrapper. ```java searcher.setSimilarity(new BM25Similarity()); ``` -------------------------------- ### Get Matched Text Source: https://github.com/apache/lucene/blob/main/gradle/regenerate/jflex/skeleton.disable.buffer.expansion.txt Returns the actual text that was matched by the current regular expression. This is constructed from the buffer using start and marked positions. ```Java public final String yytext() { return new String(zzBuffer, zzStartRead, zzMarkedPos-zzStartRead); } ``` -------------------------------- ### Get Matched Text Length Source: https://github.com/apache/lucene/blob/main/gradle/regenerate/jflex/skeleton.disable.buffer.expansion.txt Returns the length of the text matched by the current regular expression. This is calculated as the difference between the marked and start read positions. ```Java public final int yylength() { return zzMarkedPos-zzStartRead; } ``` -------------------------------- ### Install Python Modules Source: https://github.com/apache/lucene/blob/main/dev-tools/scripts/README.md Installs necessary Python modules for development scripts. Requires Python 3.12 or above. ```bash make env source .env/bin/activate ``` -------------------------------- ### Check Dependency Licenses and Notices Source: https://github.com/apache/lucene/blob/main/help/dependencies.txt Verify that licenses, notice files, and checksums are in place for all new dependencies. This command reports any missing information. ```bash gradlew licenses ``` -------------------------------- ### Index and Search Text with Lucene Source: https://github.com/apache/lucene/blob/main/lucene/core/src/java/overview.html This example demonstrates how to index a simple text document and then search it using Apache Lucene. It covers setting up the analyzer, directory, index writer, document creation, and performing a search query. Ensure JUnit is available for assertions. ```java Analyzer analyzer = new StandardAnalyzer(); Path indexPath = Files.createTempDirectory("tempIndex"); try (Directory directory = FSDirectory.open(indexPath)) { IndexWriterConfig config = new IndexWriterConfig(analyzer); try (IndexWriter iwriter = new IndexWriter(directory, config)) { Document doc = new Document(); String text = "This is the text to be indexed."; doc.add(new Field("fieldname", text, TextField.TYPE_STORED)); iwriter.addDocument(doc); } // Now search the index: try (DirectoryReader ireader = DirectoryReader.open(directory)) { IndexSearcher isearcher = new IndexSearcher(ireader); // Parse a simple query that searches for "text": QueryParser parser = new QueryParser("fieldname", analyzer); Query query = parser.parse("text"); ScoreDoc[] hits = isearcher.search(query, 10).scoreDocs; assertEquals(1, hits.length); // Iterate through the results: StoredFields storedFields = isearcher.storedFields(); for (int i = 0; i < hits.length; i++) { Document hitDoc = storedFields.document(hits[i].doc); assertEquals("This is the text to be indexed.", hitDoc.get("fieldname")); } } } finally { IOUtils.rm(indexPath); } ``` -------------------------------- ### Format Code with Gradle Source: https://github.com/apache/lucene/blob/main/help/workflow.txt Run this command to ensure your code changes adhere to the project's formatting standards. Refer to ':helpFormatting' for more details. ```gradle gradlew tidy ``` -------------------------------- ### Install Xvfb on Arch Linux Source: https://github.com/apache/lucene/blob/main/help/tests.txt Installs Xvfb using the pacman package manager. This is a prerequisite for certain testing scenarios on Arch Linux. ```bash $ sudo pacman -S xorg-server-xvfb ``` -------------------------------- ### BooleanQuery Example Source: https://github.com/apache/lucene/blob/main/lucene/queryparser/docs/xml/LuceneContribQuery.dtd.html Demonstrates how to construct a BooleanQuery with 'should', 'mustnot', and 'must' clauses to define complex search criteria. ```xml merger sumitomo bank ``` -------------------------------- ### Install Xvfb on Ubuntu/Debian-based systems Source: https://github.com/apache/lucene/blob/main/help/tests.txt Installs Xvfb using the apt package manager. This is a prerequisite for certain testing scenarios on Ubuntu or Debian. ```bash $ sudo apt install xvfb ``` -------------------------------- ### Install Precommit Hook Source: https://github.com/apache/lucene/blob/main/help/precommit.txt Install a precommit hook to automatically run checks before each commit. The '--allow-missing-config' option is needed for older release branches. ```bash uv tool install prek prek install --allow-missing-config ```