-
Notifications
You must be signed in to change notification settings - Fork 781
Feature/uhighlighter #2052
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
Feature/uhighlighter #2052
Changes from all commits
dc1f06d
cee4f4b
0299007
431a6d7
efe6abf
f812a10
30f68de
fa8513d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ information: Portions Copyright [yyyy] [name of copyright owner] | |
CDDL HEADER END | ||
|
||
Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. | ||
Portions Copyright (c) 2017, Chris Fraire <[email protected]>. | ||
Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>. | ||
|
||
--> | ||
<project name="OpenGrok" default="jar" basedir="." xmlns:jacoco="antlib:org.jacoco.ant" | ||
|
@@ -507,6 +507,18 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>. | |
<available file="${lucene-analyzers-common.jar}" type="file" property="lucene-analyzers-common.jar.present"> | ||
<filepath refid="plainlib.search.path"/> | ||
</available> | ||
<available file="${lucene-highlighter.jar}" type="file" property="lucene-highlighter.jar.present"> | ||
<filepath refid="plainlib.search.path"/> | ||
</available> | ||
<available file="${lucene-join.jar}" type="file" property="lucene-join.jar.present"> | ||
<filepath refid="plainlib.search.path"/> | ||
</available> | ||
<available file="${lucene-memory.jar}" type="file" property="lucene-memory.jar.present"> | ||
<filepath refid="plainlib.search.path"/> | ||
</available> | ||
<available file="${lucene-queries.jar}" type="file" property="lucene-queries.jar.present"> | ||
<filepath refid="plainlib.search.path"/> | ||
</available> | ||
<available file="${lucene-queryparser.jar}" type="file" property="lucene-queryparser.jar.present"> | ||
<filepath refid="plainlib.search.path"/> | ||
</available> | ||
|
@@ -518,6 +530,10 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>. | |
<and> | ||
<isset property="lucene-core.jar.present"/> | ||
<isset property="lucene-analyzers-common.jar.present"/> | ||
<isset property="lucene-highlighter.jar.present"/> | ||
<isset property="lucene-join.jar.present"/> | ||
<isset property="lucene-memory.jar.present"/> | ||
<isset property="lucene-queries.jar.present"/> | ||
<isset property="lucene-queryparser.jar.present"/> | ||
<isset property="lucene-suggest.jar.present"/> | ||
</and> | ||
|
@@ -535,6 +551,14 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>. | |
dest="lib/${lucene-core.jar}" verbose="true" usetimestamp="true"/> | ||
<get src="${mvn.repository}/org/apache/lucene/lucene-analyzers-common/${lucene.version}/${lucene-analyzers-common.jar}" | ||
dest="lib/${lucene-analyzers-common.jar}" verbose="true" usetimestamp="true"/> | ||
<get src="${mvn.repository}/org/apache/lucene/lucene-highlighter/${lucene.version}/${lucene-highlighter.jar}" | ||
dest="lib/${lucene-highlighter.jar}" verbose="true" usetimestamp="true"/> | ||
<get src="${mvn.repository}/org/apache/lucene/lucene-join/${lucene.version}/${lucene-join.jar}" | ||
dest="lib/${lucene-join.jar}" verbose="true" usetimestamp="true"/> | ||
<get src="${mvn.repository}/org/apache/lucene/lucene-memory/${lucene.version}/${lucene-memory.jar}" | ||
dest="lib/${lucene-memory.jar}" verbose="true" usetimestamp="true"/> | ||
<get src="${mvn.repository}/org/apache/lucene/lucene-queries/${lucene.version}/${lucene-queries.jar}" | ||
dest="lib/${lucene-queries.jar}" verbose="true" usetimestamp="true"/> | ||
<get src="${mvn.repository}/org/apache/lucene/lucene-queryparser/${lucene.version}/${lucene-queryparser.jar}" | ||
dest="lib/${lucene-queryparser.jar}" verbose="true" usetimestamp="true"/> | ||
<get src="${mvn.repository}/org/apache/lucene/lucene-suggest/${lucene.version}/${lucene-suggest.jar}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ information: Portions Copyright [yyyy] [name of copyright owner] | |
CDDL HEADER END | ||
|
||
Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. | ||
Portions Copyright (c) 2017, Chris Fraire <[email protected]>. | ||
Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>. | ||
|
||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
|
@@ -476,6 +476,22 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>. | |
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-analyzers-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-highlighter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-join</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-memory</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-queries</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-queryparser</artifactId> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ information: Portions Copyright [yyyy] [name of copyright owner] | |
CDDL HEADER END | ||
|
||
Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy |
||
Portions Copyright (c) 2018, Chris Fraire <[email protected]>. | ||
|
||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
|
@@ -87,6 +88,26 @@ Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. | |
<artifactId>lucene-analyzers-common</artifactId> | ||
<version>${lucene.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-highlighter</artifactId> | ||
<version>${lucene.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-join</artifactId> | ||
<version>${lucene.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-memory</artifactId> | ||
<version>${lucene.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-queries</artifactId> | ||
<version>${lucene.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.lucene</groupId> | ||
<artifactId>lucene-queryparser</artifactId> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
/* | ||
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy |
||
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>. | ||
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>. | ||
*/ | ||
package org.opensolaris.opengrok.analysis; | ||
|
||
|
@@ -213,6 +213,13 @@ public class AnalyzerGuru { | |
|
||
private static final Map<String, String> fileTypeDescriptions = new TreeMap<>(); | ||
|
||
/** | ||
* Maps from {@link FileAnalyzer#getFileTypeName()} to | ||
* {@link FileAnalyzerFactory} | ||
*/ | ||
private static final Map<String, FileAnalyzerFactory> FILETYPE_FACTORIES = | ||
new HashMap<>(); | ||
|
||
/* | ||
* If you write your own analyzer please register it here. The order is | ||
* important for any factory that uses a FileAnalyzerFactory.Matcher | ||
|
@@ -338,6 +345,9 @@ private static void registerAnalyzer(FileAnalyzerFactory factory) { | |
} | ||
matchers.addAll(factory.getMatchers()); | ||
factories.add(factory); | ||
|
||
FileAnalyzer fa = factory.getAnalyzer(); | ||
FILETYPE_FACTORIES.put(fa.getFileTypeName(), factory); | ||
} | ||
|
||
/** | ||
|
@@ -385,6 +395,17 @@ public static FileAnalyzer getAnalyzer() { | |
return DEFAULT_ANALYZER_FACTORY.getAnalyzer(); | ||
} | ||
|
||
/** | ||
* Gets an analyzer for the specified {@code fileTypeName} if it accords | ||
* with a known {@link FileAnalyzer#getFileTypeName()}. | ||
* @param fileTypeName a defined name | ||
* @return a defined instance if known or otherwise {@code null} | ||
*/ | ||
public static FileAnalyzer getAnalyzer(String fileTypeName) { | ||
FileAnalyzerFactory factory = FILETYPE_FACTORIES.get(fileTypeName); | ||
return factory == null ? null : factory.getAnalyzer(); | ||
} | ||
|
||
/** | ||
* Get an analyzer suited to analyze a file. This function will reuse | ||
* analyzers since they are costly. | ||
|
@@ -531,6 +552,9 @@ public static void writeXref(FileAnalyzerFactory factory, Reader in, | |
args.setProject(project); | ||
|
||
FileAnalyzer analyzer = factory.getAnalyzer(); | ||
RuntimeEnvironment env = RuntimeEnvironment.getInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is because of testing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While testing the new highlighter, I found that scopes were not working when looking at historical versions of files or when annotating a file — i.e. where this |
||
analyzer.setScopesEnabled(env.isScopesEnabled()); | ||
analyzer.setFoldingEnabled(env.isFoldingEnabled()); | ||
analyzer.writeXref(args); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -378,8 +378,8 @@ private static String cutPattern(String tagLine, int startTab, int endTab) { | |
* Adds a tag to a {@code Definitions} instance. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy 2018 |
||
*/ | ||
private void addTag(Definitions defs, int lineno, String symbol, | ||
String type, String text, String namespace, String signature, | ||
int lineStart, int lineEnd) { | ||
String type, String text, String namespace, String signature, | ||
int lineStart, int lineEnd) { | ||
// The strings are frequently repeated (a symbol can be used in | ||
// multiple definitions, multiple definitions can have the same type, | ||
// one line can contain multiple definitions). Intern them to minimize | ||
|
@@ -397,9 +397,7 @@ private void addTag(Definitions defs, int lineno, String symbol, | |
* syntax. | ||
* @return a defined instance | ||
*/ | ||
private CpatIndex bestIndexOfTag(int lineno, String whole, | ||
String str) { | ||
|
||
private CpatIndex bestIndexOfTag(int lineno, String whole, String str) { | ||
if (whole.length() < 1) { | ||
return new CpatIndex(lineno, 0, 1, true); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 | ||
* United States License. To view a copy of this license, visit | ||
* http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to | ||
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. | ||
* | ||
* Copyright (c) 2012, https://stackoverflow.com/users/1270457/amas | ||
* Copyright (c) 2012, https://stackoverflow.com/questions/11945728/how-to-use-termvector-lucene-4-0 | ||
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>. | ||
*/ | ||
|
||
package org.opensolaris.opengrok.analysis; | ||
|
||
import java.io.Reader; | ||
import org.apache.lucene.analysis.TokenStream; | ||
import org.apache.lucene.document.Field; | ||
import org.apache.lucene.document.FieldType; | ||
import org.apache.lucene.index.IndexOptions; | ||
|
||
/** | ||
* Represents an OpenGrok-customized tokenized text field to centralize settings | ||
* across all the analyzers. | ||
*/ | ||
public class OGKTextField extends Field { | ||
|
||
/** Indexed, tokenized, not stored. */ | ||
public static final FieldType TYPE_NOT_STORED = new FieldType(); | ||
|
||
/** Indexed, tokenized, stored. */ | ||
public static final FieldType TYPE_STORED = new FieldType(); | ||
|
||
static { | ||
TYPE_NOT_STORED.setIndexOptions( | ||
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); | ||
TYPE_NOT_STORED.setTokenized(true); | ||
TYPE_NOT_STORED.freeze(); | ||
|
||
TYPE_STORED.setIndexOptions( | ||
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); | ||
TYPE_STORED.setTokenized(true); | ||
TYPE_STORED.setStored(true); | ||
TYPE_STORED.freeze(); | ||
} | ||
|
||
/** | ||
* Creates a new un-stored instance with {@link Reader} value. | ||
*/ | ||
public OGKTextField(String name, Reader reader) { | ||
super(name, reader, TYPE_NOT_STORED); | ||
} | ||
|
||
/** | ||
* Creates a new instance with {@link Reader} value. | ||
*/ | ||
public OGKTextField(String name, Reader reader, Store store) { | ||
super(name, reader, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED); | ||
} | ||
|
||
/** | ||
* Creates a new instance with {@code String} value. | ||
*/ | ||
public OGKTextField(String name, String value, Store store) { | ||
super(name, value, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED); | ||
} | ||
|
||
/** | ||
* Creates a new un-stored instance with {@link TokenStream} value. | ||
*/ | ||
public OGKTextField(String name, TokenStream stream) { | ||
super(name, stream, TYPE_NOT_STORED); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy