"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java" between
lucene-7.6.0-src.tgz and lucene-7.7.0-src.tgz

About: Lucene is a Java full-text search engine (not a complete application, but rather a code library and API; java source code).

TestSuggestField.java  (lucene-7.6.0-src.tgz):TestSuggestField.java  (lucene-7.7.0-src.tgz)
skipping to change at line 24 skipping to change at line 24
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.apache.lucene.search.suggest.document; package org.apache.lucene.search.suggest.document;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CyclicBarrier; import java.util.concurrent.CyclicBarrier;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockAnalyzer;
skipping to change at line 56 skipping to change at line 55
import org.apache.lucene.document.StoredField; import org.apache.lucene.document.StoredField;
import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.RandomIndexWriter;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.suggest.BitsProducer; import org.apache.lucene.search.suggest.BitsProducer;
import org.apache.lucene.search.suggest.Lookup;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.OutputStreamDataOutput; import org.apache.lucene.store.OutputStreamDataOutput;
import org.apache.lucene.util.Bits; import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRefBuilder; import org.apache.lucene.util.CharsRefBuilder;
import org.apache.lucene.util.LineFileDocs; import org.apache.lucene.util.LineFileDocs;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
skipping to change at line 345 skipping to change at line 345
} }
// slow but hopefully correct suggester: // slow but hopefully correct suggester:
List<Entry> expected = new ArrayList<>(); List<Entry> expected = new ArrayList<>();
for(Entry doc : docs) { for(Entry doc : docs) {
if (doc.output.startsWith(prefix)) { if (doc.output.startsWith(prefix)) {
expected.add(doc); expected.add(doc);
} }
} }
Collections.sort(expected, Collections.sort(expected,
new Comparator<Entry>() { (a, b) -> {
@Override // sort by higher score:
public int compare(Entry a, Entry b) { int cmp = Float.compare(b.value, a.value);
// sort by higher score: if (cmp == 0) {
int cmp = Float.compare(b.value, a.value); // tie break by completion key
if (cmp == 0) { cmp = Lookup.CHARSEQUENCE_COMPARATOR.compare(a.output, b.output);
// tie break by smaller docID: if (cmp == 0) {
cmp = Integer.compare(a.id, b.id); // prefer smaller doc id, in case of a tie
} cmp = Integer.compare(a.id, b.id);
return cmp; }
} }
}); return cmp;
});
boolean dedup = random().nextBoolean(); boolean dedup = random().nextBoolean();
if (dedup) { if (dedup) {
List<Entry> deduped = new ArrayList<>(); List<Entry> deduped = new ArrayList<>();
Set<String> seen = new HashSet<>(); Set<String> seen = new HashSet<>();
for(Entry entry : expected) { for(Entry entry : expected) {
if (seen.contains(entry.output) == false) { if (seen.contains(entry.output) == false) {
seen.add(entry.output); seen.add(entry.output);
deduped.add(entry); deduped.add(entry);
} }
 End of changes. 3 change blocks. 
13 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)