Examples of BytesRefBuilder


Examples of org.apache.lucene.util.BytesRefBuilder

                fieldComparatorSource = new BytesRefFieldComparatorSource(null, null, sortMode, nested) {
                    @Override
                    protected SortedBinaryDocValues getValues(LeafReaderContext context) {
                        searchScript.setNextReader(context);
                        final BinaryDocValues values = new BinaryDocValues() {
                            final BytesRefBuilder spare = new BytesRefBuilder();
                            @Override
                            public BytesRef get(int docID) {
                                searchScript.setNextDocId(docID);
                                spare.copyChars(searchScript.run().toString());
                                return spare.get();
                            }
                        };
                        return FieldData.singleton(values, null);
                    }
                    @Override
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

                    suggestion.getShardSize(), indexReader,wordScorer , separator, suggestion.confidence(), suggestion.gramSize());

            PhraseSuggestion.Entry resultEntry = buildResultEntry(suggestion, spare, checkerResult.cutoffScore);
            response.addTerm(resultEntry);

            BytesRefBuilder byteSpare = new BytesRefBuilder();

            MultiSearchResponse multiSearchResponse = collate(suggestion, checkerResult, byteSpare, spare);
            final boolean collateEnabled = multiSearchResponse != null;
            final boolean collatePrune = suggestion.collatePrune();
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

        AtomicFieldData rightData = random.nextBoolean() ? right.load(context) : right.loadDirect(context);

        int numDocs = context.reader().maxDoc();
        SortedBinaryDocValues leftBytesValues = leftData.getBytesValues();
        SortedBinaryDocValues rightBytesValues = rightData.getBytesValues();
        BytesRefBuilder leftSpare = new BytesRefBuilder();
        BytesRefBuilder rightSpare = new BytesRefBuilder();

        for (int i = 0; i < numDocs; i++) {
            leftBytesValues.setDocument(i);
            rightBytesValues.setDocument(i);
            int numValues = leftBytesValues.count();
            assertThat(numValues, equalTo(rightBytesValues.count()));
            BytesRef previous = null;
            for (int j = 0; j < numValues; j++) {
                rightSpare.copyBytes(rightBytesValues.valueAt(j));
                leftSpare.copyBytes(leftBytesValues.valueAt(j));
                if (previous != null) {
                    assertThat(pre.compare(previous, rightSpare.get()), lessThan(0));
                }
                previous = BytesRef.deepCopyOf(rightSpare.get());
                pre.toString(rightSpare.get());
                pre.toString(leftSpare.get());
                assertThat(pre.toString(leftSpare.get()), equalTo(pre.toString(rightSpare.get())));
            }
        }
    }
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

    private IndexQueryParserService queryParser() throws IOException {
        return this.queryParser;
    }

    private BytesRef longToPrefixCoded(long val, int shift) {
        BytesRefBuilder bytesRef = new BytesRefBuilder();
        NumericUtils.longToPrefixCoded(val, shift, bytesRef);
        return bytesRef.get();
    }
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

        TopDocs topDocs = searcher.search(new TermQuery(new Term("_id", "1")), 1);
        Document doc = searcher.doc(topDocs.scoreDocs[0].doc);
        IndexableField f = doc.getField("test");
        assertThat(f.stringValue(), equalTo("2"));

        BytesRefBuilder bytes = new BytesRefBuilder();
        NumericUtils.intToPrefixCoded(2, 0, bytes);
        topDocs = searcher.search(new TermQuery(new Term("test", bytes.get())), 1);
        doc = searcher.doc(topDocs.scoreDocs[0].doc);
        f = doc.getField("test");
        assertThat(f.stringValue(), equalTo("2"));

        indexWriter.close();
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

    /**
     * Test method for {@link org.apache.lucene.util.BytesRefHash#size()}.
     */
    @Test
    public void testSize() {
        BytesRefBuilder ref = new BytesRefBuilder();
        int num = scaledRandomIntBetween(2, 20);
        for (int j = 0; j < num; j++) {
            final int mod = 1+randomInt(40);
            for (int i = 0; i < 797; i++) {
                String str;
                do {
                    str = TestUtil.randomRealisticUnicodeString(getRandom(), 1000);
                } while (str.length() == 0);
                ref.copyChars(str);
                long count = hash.size();
                long key = hash.add(ref.get());
                if (key < 0)
                    assertEquals(hash.size(), count);
                else
                    assertEquals(hash.size(), count + 1);
                if(i % mod == 0) {
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

     * {@link org.apache.lucene.util.BytesRefHash#get(int, BytesRef)}
     * .
     */
    @Test
    public void testGet() {
        BytesRefBuilder ref = new BytesRefBuilder();
        BytesRef scratch = new BytesRef();
        int num = scaledRandomIntBetween(2, 20);
        for (int j = 0; j < num; j++) {
            Map<String, Long> strings = new HashMap<>();
            int uniqueCount = 0;
            for (int i = 0; i < 797; i++) {
                String str;
                do {
                    str = TestUtil.randomRealisticUnicodeString(getRandom(), 1000);
                } while (str.length() == 0);
                ref.copyChars(str);
                long count = hash.size();
                long key = hash.add(ref.get());
                if (key >= 0) {
                    assertNull(strings.put(str, Long.valueOf(key)));
                    assertEquals(uniqueCount, key);
                    uniqueCount++;
                    assertEquals(hash.size(), count + 1);
                } else {
                    assertTrue((-key)-1 < count);
                    assertEquals(hash.size(), count);
                }
            }
            for (Entry<String, Long> entry : strings.entrySet()) {
                ref.copyChars(entry.getKey());
                assertEquals(ref.get(), hash.get(entry.getValue().longValue(), scratch));
            }
            newHash();
        }
        hash.close();
    }
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

     * {@link org.apache.lucene.util.BytesRefHash#add(org.apache.lucene.util.BytesRef)}
     * .
     */
    @Test
    public void testAdd() {
        BytesRefBuilder ref = new BytesRefBuilder();
        BytesRef scratch = new BytesRef();
        int num = scaledRandomIntBetween(2, 20);
        for (int j = 0; j < num; j++) {
            Set<String> strings = new HashSet<>();
            int uniqueCount = 0;
            for (int i = 0; i < 797; i++) {
                String str;
                do {
                    str = TestUtil.randomRealisticUnicodeString(getRandom(), 1000);
                } while (str.length() == 0);
                ref.copyChars(str);
                long count = hash.size();
                long key = hash.add(ref.get());

                if (key >=0) {
                    assertTrue(strings.add(str));
                    assertEquals(uniqueCount, key);
                    assertEquals(hash.size(), count + 1);
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

        hash.close();
    }

    @Test
    public void testFind() throws Exception {
        BytesRefBuilder ref = new BytesRefBuilder();
        BytesRef scratch = new BytesRef();
        int num = scaledRandomIntBetween(2, 20);
        for (int j = 0; j < num; j++) {
            Set<String> strings = new HashSet<>();
            int uniqueCount = 0;
            for (int i = 0; i < 797; i++) {
                String str;
                do {
                    str = TestUtil.randomRealisticUnicodeString(getRandom(), 1000);
                } while (str.length() == 0);
                ref.copyChars(str);
                long count = hash.size();
                long key = hash.find(ref.get()); //hash.add(ref);
                if (key >= 0) { // string found in hash
                    assertFalse(strings.add(str));
                    assertTrue(key < count);
                    assertEquals(str, hash.get(key, scratch).utf8ToString());
                    assertEquals(count, hash.size());
                } else {
                    key = hash.add(ref.get());
                    assertTrue(strings.add(str));
                    assertEquals(uniqueCount, key);
                    assertEquals(hash.size(), count + 1);
                    uniqueCount++;
                }
View Full Code Here

Examples of org.apache.lucene.util.BytesRefBuilder

        }
        hash.close();
    }

    private void assertAllIn(Set<String> strings, BytesRefHash hash) {
        BytesRefBuilder ref = new BytesRefBuilder();
        BytesRef scratch = new BytesRef();
        long count = hash.size();
        for (String string : strings) {
            ref.copyChars(string);
            long key  =  hash.add(ref.get()); // add again to check duplicates
            assertEquals(string, hash.get((-key)-1, scratch).utf8ToString());
            assertEquals(count, hash.size());
            assertTrue("key: " + key + " count: " + count + " string: " + string,
                    key < count);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.