Skip to content

Commit cee4f4b

Browse files
committed
Use UnifiedHighlighter subclass for Results, more/ contexts
Also: - Add Context toggleAlt() so the side effect previously implicit in getContext() is now an explicit, separate call by clients.
1 parent dc1f06d commit cee4f4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3872
-139
lines changed

build.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ information: Portions Copyright [yyyy] [name of copyright owner]
1919
CDDL HEADER END
2020
2121
Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
22-
Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2323
2424
-->
2525
<project name="OpenGrok" default="jar" basedir="." xmlns:jacoco="antlib:org.jacoco.ant"
@@ -507,6 +507,18 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
507507
<available file="${lucene-analyzers-common.jar}" type="file" property="lucene-analyzers-common.jar.present">
508508
<filepath refid="plainlib.search.path"/>
509509
</available>
510+
<available file="${lucene-highlighter.jar}" type="file" property="lucene-highlighter.jar.present">
511+
<filepath refid="plainlib.search.path"/>
512+
</available>
513+
<available file="${lucene-join.jar}" type="file" property="lucene-join.jar.present">
514+
<filepath refid="plainlib.search.path"/>
515+
</available>
516+
<available file="${lucene-memory.jar}" type="file" property="lucene-memory.jar.present">
517+
<filepath refid="plainlib.search.path"/>
518+
</available>
519+
<available file="${lucene-queries.jar}" type="file" property="lucene-queries.jar.present">
520+
<filepath refid="plainlib.search.path"/>
521+
</available>
510522
<available file="${lucene-queryparser.jar}" type="file" property="lucene-queryparser.jar.present">
511523
<filepath refid="plainlib.search.path"/>
512524
</available>
@@ -518,6 +530,10 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
518530
<and>
519531
<isset property="lucene-core.jar.present"/>
520532
<isset property="lucene-analyzers-common.jar.present"/>
533+
<isset property="lucene-highlighter.jar.present"/>
534+
<isset property="lucene-join.jar.present"/>
535+
<isset property="lucene-memory.jar.present"/>
536+
<isset property="lucene-queries.jar.present"/>
521537
<isset property="lucene-queryparser.jar.present"/>
522538
<isset property="lucene-suggest.jar.present"/>
523539
</and>
@@ -535,6 +551,14 @@ Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
535551
dest="lib/${lucene-core.jar}" verbose="true" usetimestamp="true"/>
536552
<get src="${mvn.repository}/org/apache/lucene/lucene-analyzers-common/${lucene.version}/${lucene-analyzers-common.jar}"
537553
dest="lib/${lucene-analyzers-common.jar}" verbose="true" usetimestamp="true"/>
554+
<get src="${mvn.repository}/org/apache/lucene/lucene-highlighter/${lucene.version}/${lucene-highlighter.jar}"
555+
dest="lib/${lucene-highlighter.jar}" verbose="true" usetimestamp="true"/>
556+
<get src="${mvn.repository}/org/apache/lucene/lucene-join/${lucene.version}/${lucene-join.jar}"
557+
dest="lib/${lucene-join.jar}" verbose="true" usetimestamp="true"/>
558+
<get src="${mvn.repository}/org/apache/lucene/lucene-memory/${lucene.version}/${lucene-memory.jar}"
559+
dest="lib/${lucene-memory.jar}" verbose="true" usetimestamp="true"/>
560+
<get src="${mvn.repository}/org/apache/lucene/lucene-queries/${lucene.version}/${lucene-queries.jar}"
561+
dest="lib/${lucene-queries.jar}" verbose="true" usetimestamp="true"/>
538562
<get src="${mvn.repository}/org/apache/lucene/lucene-queryparser/${lucene.version}/${lucene-queryparser.jar}"
539563
dest="lib/${lucene-queryparser.jar}" verbose="true" usetimestamp="true"/>
540564
<get src="${mvn.repository}/org/apache/lucene/lucene-suggest/${lucene.version}/${lucene-suggest.jar}"

debian/ant.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
DEB_JARS=JFlex.jar:ant-junit.jar:ant-nodeps.jar:junit4.jar:bcel.jar:swing-layout.jar:lucene-core.jar:lucene-spellchecker.jar:servlet-api.jar
2-
WAR_JARS=bcel.jar:swing-layout.jar:lucene-core.jar:lucene-spellchecker.jar
1+
DEB_JARS=JFlex.jar:ant-junit.jar:ant-nodeps.jar:junit4.jar:bcel.jar:swing-layout.jar:lucene-core.jar:lucene-highlighter.jar:lucene-join.jar:lucene-memory.jar:lucene-queries.jar:lucene-spellchecker.jar:servlet-api.jar
2+
WAR_JARS=bcel.jar:swing-layout.jar:lucene-core.jar:lucene-highlighter.jar:lucene-join.jar:lucene-memory.jar:lucene-queries.jar:lucene-spellchecker.jar
33

44
file.reference.jrcs.jar=lib/jrcs.jar
55

nbproject/project.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ manifest.custom.caller.allowable.codebase=
1111
project.licensePath=./nbproject/licenseheader.txt
1212
src.generatedsrc.dir=generatedsrc
1313
file.reference.lucene-core.jar=lib/${lucene-core.jar}
14+
file.reference.lucene-highlighter.jar=lib/${lucene-highlighter.jar}
15+
file.reference.lucene-join.jar=lib/${lucene-join.jar}
16+
file.reference.lucene-memory.jar=lib/${lucene-memory.jar}
17+
file.reference.lucene-queries.jar=lib/${lucene-queries.jar}
1418
dist.war=${dist.dir}/source.war
1519
javac.target=1.8
1620
build.generated.dir=${build.dir}/generated
@@ -19,6 +23,10 @@ run.classpath=\
1923
${build.classes.dir}
2024
lucene.version=7.2.1
2125
lucene-core.jar=lucene-core-${lucene.version}.jar
26+
lucene-highlighter.jar=lucene-highlighter-${lucene.version}.jar
27+
lucene-join.jar=lucene-join-${lucene.version}.jar
28+
lucene-memory.jar=lucene-memory-${lucene.version}.jar
29+
lucene-queries.jar=lucene-queries-${lucene.version}.jar
2230
file.reference.opengrok-dev-test=test
2331
debug.test.classpath=${run.test.classpath}
2432
jnlp.descriptor=application
@@ -78,6 +86,10 @@ javac.classpath=\
7886
${file.reference.bcel.jar}:\
7987
${file.reference.lucene-analyzers-common.jar}:\
8088
${file.reference.lucene-core.jar}:\
89+
${file.reference.lucene-highlighter.jar}:\
90+
${file.reference.lucene-join.jar}:\
91+
${file.reference.lucene-memory.jar}:\
92+
${file.reference.lucene-queries.jar}:\
8193
${file.reference.lucene-queryparser.jar}:\
8294
${file.reference.lucene-suggest.jar}:\
8395
${file.reference.servlet-api.jar}

opengrok-web-nbproject/nbproject/build-impl.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,10 @@ exists or setup the property manually. For example like this:
991991
<copyfiles files="${file.reference.bcel.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
992992
<copyfiles files="${file.reference.lucene-core.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
993993
<copyfiles files="${file.reference.lucene-analyzers-common.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
994+
<copyfiles files="${file.reference.lucene-highlighter.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
995+
<copyfiles files="${file.reference.lucene-join.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
996+
<copyfiles files="${file.reference.lucene-memory.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
997+
<copyfiles files="${file.reference.lucene-queries.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
994998
<copyfiles files="${file.reference.lucene-queryparser.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
995999
<copyfiles files="${file.reference.lucene-suggest.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
9961000
<copyfiles files="${file.reference.json-simple-1.1.1.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
@@ -1004,6 +1008,10 @@ exists or setup the property manually. For example like this:
10041008
<copyfiles files="${file.reference.bcel.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
10051009
<copyfiles files="${file.reference.lucene-core.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
10061010
<copyfiles files="${file.reference.lucene-analyzers-common.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
1011+
<copyfiles files="${file.reference.lucene-highlighter.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
1012+
<copyfiles files="${file.reference.lucene-join.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
1013+
<copyfiles files="${file.reference.lucene-memory.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
1014+
<copyfiles files="${file.reference.lucene-queries.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
10071015
<copyfiles files="${file.reference.lucene-queryparser.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
10081016
<copyfiles files="${file.reference.lucene-suggest.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
10091017
<copyfiles files="${file.reference.json-simple-1.1.1.jar}" todir="${build.web.dir}/WEB-INF/lib"/>

opengrok-web-nbproject/nbproject/project.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ j2ee.platform.classpath=${j2ee.server.home}/lib/annotations-api.jar:${j2ee.serve
4040
lucene.version=7.2.1
4141
lucene-core.jar=lucene-core-${lucene.version}.jar
4242
lucene-analyzers-common.jar=lucene-analyzers-common-${lucene.version}.jar
43+
lucene-highlighter.jar=lucene-highlighter-${lucene.version}.jar
44+
lucene-join.jar=lucene-join-${lucene.version}.jar
45+
lucene-memory.jar=lucene-memory-${lucene.version}.jar
46+
lucene-queries.jar=lucene-queries-${lucene.version}.jar
4347
lucene-queryparser.jar=lucene-queryparser-${lucene.version}.jar
4448
lucene-suggest.jar=lucene-suggest-${lucene.version}.jar
4549
file.reference.lucene-core.jar=../lib/${lucene-core.jar}
4650
file.reference.lucene-analyzers-common.jar=../lib/${lucene-analyzers-common.jar}
51+
file.reference.lucene-highlighter.jar=../lib/${lucene-highlighter.jar}
52+
file.reference.lucene-join.jar=../lib/${lucene-join.jar}
53+
file.reference.lucene-memory.jar=../lib/${lucene-memory.jar}
54+
file.reference.lucene-queries.jar=../lib/${lucene-queries.jar}
4755
file.reference.lucene-queryparser.jar=../lib/${lucene-queryparser.jar}
4856
file.reference.lucene-suggest.jar=../lib/${lucene-suggest.jar}
4957
file.reference.ant.jar=${ant.library.dir}/ant.jar
@@ -67,6 +75,10 @@ javac.classpath=\
6775
${file.reference.bcel.jar}:\
6876
${file.reference.lucene-core.jar}:\
6977
${file.reference.lucene-analyzers-common.jar}:\
78+
${file.reference.lucene-highlighter.jar}:\
79+
${file.reference.lucene-join.jar}:\
80+
${file.reference.lucene-memory.jar}:\
81+
${file.reference.lucene-queries.jar}:\
7082
${file.reference.lucene-queryparser.jar}:\
7183
${file.reference.lucene-suggest.jar}:\
7284
${file.reference.json-simple-1.1.1.jar}

opengrok-web-nbproject/nbproject/project.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@
3030
<file>${file.reference.lucene-analyzers-common.jar}</file>
3131
<path-in-war>WEB-INF/lib</path-in-war>
3232
</library>
33+
<library dirs="200">
34+
<file>${file.reference.lucene-highlighter.jar}</file>
35+
<path-in-war>WEB-INF/lib</path-in-war>
36+
</library>
37+
<library dirs="200">
38+
<file>${file.reference.lucene-join.jar}</file>
39+
<path-in-war>WEB-INF/lib</path-in-war>
40+
</library>
41+
<library dirs="200">
42+
<file>${file.reference.lucene-memory.jar}</file>
43+
<path-in-war>WEB-INF/lib</path-in-war>
44+
</library>
45+
<library dirs="200">
46+
<file>${file.reference.lucene-queries.jar}</file>
47+
<path-in-war>WEB-INF/lib</path-in-war>
48+
</library>
3349
<library dirs="200">
3450
<file>${file.reference.lucene-queryparser.jar}</file>
3551
<path-in-war>WEB-INF/lib</path-in-war>

src/org/opensolaris/opengrok/analysis/AnalyzerGuru.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
22-
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
22+
* Portions Copyright (c) 2017-2018, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opensolaris.opengrok.analysis;
2525

@@ -531,6 +531,9 @@ public static void writeXref(FileAnalyzerFactory factory, Reader in,
531531
args.setProject(project);
532532

533533
FileAnalyzer analyzer = factory.getAnalyzer();
534+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
535+
analyzer.setScopesEnabled(env.isScopesEnabled());
536+
analyzer.setFoldingEnabled(env.isFoldingEnabled());
534537
analyzer.writeXref(args);
535538
}
536539

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
3+
* United States License. To view a copy of this license, visit
4+
* http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
5+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
6+
*
7+
* Copyright (c) 2012, https://stackoverflow.com/users/1270457/amas
8+
* Copyright (c) 2012, https://stackoverflow.com/questions/11945728/how-to-use-termvector-lucene-4-0
9+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
10+
*/
11+
12+
package org.opensolaris.opengrok.analysis;
13+
14+
import java.io.Reader;
15+
import org.apache.lucene.analysis.TokenStream;
16+
import org.apache.lucene.document.Field;
17+
import org.apache.lucene.document.FieldType;
18+
import org.apache.lucene.index.IndexOptions;
19+
20+
/**
21+
* Represents an OpenGrok-customized tokenized text field to centralize settings
22+
* across all the analyzers.
23+
*/
24+
public class OGKTextField extends Field {
25+
26+
/** Indexed, tokenized, not stored. */
27+
public static final FieldType TYPE_NOT_STORED = new FieldType();
28+
29+
/** Indexed, tokenized, stored. */
30+
public static final FieldType TYPE_STORED = new FieldType();
31+
32+
static {
33+
TYPE_NOT_STORED.setIndexOptions(
34+
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
35+
TYPE_NOT_STORED.setTokenized(true);
36+
TYPE_NOT_STORED.freeze();
37+
38+
TYPE_STORED.setIndexOptions(
39+
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
40+
TYPE_STORED.setTokenized(true);
41+
TYPE_STORED.setStored(true);
42+
TYPE_STORED.freeze();
43+
}
44+
45+
/**
46+
* Creates a new un-stored instance with Reader value.
47+
* @param name
48+
* @param reader
49+
*/
50+
public OGKTextField(String name, Reader reader) {
51+
super(name, reader, TYPE_NOT_STORED);
52+
}
53+
54+
/**
55+
* Creates a new instance with {@link Reader} value.
56+
* @param name
57+
* @param reader
58+
* @param store
59+
*/
60+
public OGKTextField(String name, Reader reader, Store store) {
61+
super(name, reader, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
62+
}
63+
64+
/**
65+
* Creates a new instance with {@code String} value.
66+
* @param name
67+
* @param value
68+
* @param store
69+
*/
70+
public OGKTextField(String name, String value, Store store) {
71+
super(name, value, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
72+
}
73+
74+
/**
75+
* Creates a new un-stored instance with {@link TokenStream} value.
76+
* @param name
77+
* @param stream
78+
*/
79+
public OGKTextField(String name, TokenStream stream) {
80+
super(name, stream, TYPE_NOT_STORED);
81+
}
82+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
3+
* United States License. To view a copy of this license, visit
4+
* http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
5+
* Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
6+
*
7+
* Copyright (c) 2012, https://stackoverflow.com/users/1270457/amas
8+
* Copyright (c) 2012, https://stackoverflow.com/questions/11945728/how-to-use-termvector-lucene-4-0
9+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
10+
*/
11+
12+
package org.opensolaris.opengrok.analysis;
13+
14+
import java.io.Reader;
15+
import org.apache.lucene.analysis.TokenStream;
16+
import org.apache.lucene.document.Field;
17+
import org.apache.lucene.document.FieldType;
18+
import org.apache.lucene.index.IndexOptions;
19+
20+
/**
21+
* Represents an OpenGrok-customized tokenized, text field with stored term
22+
* vectors to centralize settings across all the analyzers.
23+
*/
24+
public class OGKTextVecField extends Field {
25+
26+
/** Indexed, tokenized, not stored. */
27+
public static final FieldType TYPE_NOT_STORED = new FieldType();
28+
29+
/** Indexed, tokenized, stored. */
30+
public static final FieldType TYPE_STORED = new FieldType();
31+
32+
static {
33+
TYPE_NOT_STORED.setIndexOptions(
34+
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
35+
TYPE_NOT_STORED.setTokenized(true);
36+
TYPE_NOT_STORED.setStoreTermVectors(true);
37+
TYPE_NOT_STORED.freeze();
38+
39+
TYPE_STORED.setIndexOptions(
40+
IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
41+
TYPE_STORED.setTokenized(true);
42+
TYPE_STORED.setStoreTermVectors(true);
43+
TYPE_STORED.setStored(true);
44+
TYPE_STORED.freeze();
45+
}
46+
47+
/**
48+
* Creates a new un-stored instance with Reader value.
49+
* @param name
50+
* @param reader
51+
*/
52+
public OGKTextVecField(String name, Reader reader) {
53+
super(name, reader, TYPE_NOT_STORED);
54+
}
55+
56+
/**
57+
* Creates a new instance with {@link Reader} value.
58+
* @param name
59+
* @param reader
60+
* @param store
61+
*/
62+
public OGKTextVecField(String name, Reader reader, Store store) {
63+
super(name, reader, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
64+
}
65+
66+
/**
67+
* Creates a new instance with {@code String} value.
68+
* @param name
69+
* @param value
70+
* @param store
71+
*/
72+
public OGKTextVecField(String name, String value, Store store) {
73+
super(name, value, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);
74+
}
75+
76+
/**
77+
* Creates a new un-stored instance with {@link TokenStream} value.
78+
* @param name
79+
* @param stream
80+
*/
81+
public OGKTextVecField(String name, TokenStream stream) {
82+
super(name, stream, TYPE_NOT_STORED);
83+
}
84+
}

src/org/opensolaris/opengrok/analysis/archive/TarAnalyzer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@
1919

2020
/*
2121
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2018, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opensolaris.opengrok.analysis.archive;
2425

2526
import java.io.IOException;
2627
import java.io.Writer;
2728
import java.util.ArrayList;
2829
import org.apache.lucene.document.Document;
29-
import org.apache.lucene.document.TextField;
3030
import org.apache.tools.tar.TarEntry;
3131
import org.apache.tools.tar.TarInputStream;
3232
import org.opensolaris.opengrok.analysis.FileAnalyzer;
3333
import org.opensolaris.opengrok.analysis.FileAnalyzerFactory;
3434
import org.opensolaris.opengrok.analysis.IteratorReader;
3535
import org.opensolaris.opengrok.analysis.StreamSource;
36+
import org.opensolaris.opengrok.analysis.OGKTextField;
37+
import org.opensolaris.opengrok.search.QueryBuilder;
3638
import org.opensolaris.opengrok.web.Util;
3739

3840
/**
@@ -62,6 +64,6 @@ public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOExc
6264
}
6365
}
6466

65-
doc.add(new TextField("full", new IteratorReader(names)));
67+
doc.add(new OGKTextField(QueryBuilder.FULL, new IteratorReader(names)));
6668
}
6769
}

0 commit comments

Comments
 (0)