nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: blevesearch/bleve
Pull request #2000 (2024-03-19 20:59:15)

MB-61216: Interpret empty `query` (in search request) as a match_none


Patch:
diff --git a/search/query/query.go b/search/query/query.go
index f0172b76..26ab656e 100644
--- a/search/query/query.go
+++ b/search/query/query.go
@@ -98,11 +98,22 @@ func ParsePreSearchData(input []byte) (map[string]interface{}, error) {
 // ParseQuery deserializes a JSON representation of
 // a Query object.
 func ParseQuery(input []byte) (Query, error) {
+	if len(input) == 0 {
+		// interpret as a match_none query
+		return NewMatchNoneQuery(), nil
+	}
+
 	var tmp map[string]interface{}
 	err := util.UnmarshalJSON(input, &tmp)
 	if err != nil {
 		return nil, err
 	}
+
+	if len(tmp) == 0 {
+		// interpret as a match_none query
+		return NewMatchNoneQuery(), nil
+	}
+
 	_, hasFuzziness := tmp["fuzziness"]
 	_, isMatchQuery := tmp["match"]
 	_, isMatchPhraseQuery := tmp["match_phrase"]


Test patch:
diff --git a/search/query/query_test.go b/search/query/query_test.go
index 228fb65c..0028c956 100644
--- a/search/query/query_test.go
+++ b/search/query/query_test.go
@@ -763,3 +763,25 @@ func TestGeoShapeQuery(t *testing.T) {
 		}
 	}
 }
+
+func TestParseEmptyQuery(t *testing.T) {
+	var qBytes []byte
+	rv, err := ParseQuery(qBytes)
+	if err != nil {
+		t.Fatal(err)
+	}
+	expect := NewMatchNoneQuery()
+	if !reflect.DeepEqual(rv, expect) {
+		t.Errorf("[1] Expected %#v, got %#v", expect, rv)
+	}
+
+	qBytes = []byte(`{}`)
+	rv, err = ParseQuery(qBytes)
+	if err != nil {
+		t.Fatal(err)
+	}
+	expect = NewMatchNoneQuery()
+	if !reflect.DeepEqual(rv, expect) {
+		t.Errorf("[2] Expected %#v, got %#v", expect, rv)
+	}
+}
Repository: blevesearch/bleve
Pull request #1485 (2020-10-08 22:10:28)

Fix DocValuesDynamic's json-ability within IndexMappingImpl
    + DocValuesDynamic defaults to "true" if unset.
    + Now, because of the "omitempty" json setting for the attribute,
      we incorrectly flip a "false" setting for the attribute (which is
      omitted as it's the zero value for boolean) to "true" (it's default).
    + Dropping the omitempty setting for this attribute corrects the
      behavior to this:
        - when unset, DocValuesDynamic will default to true (like before)
        - when set, DocValuesDynamic will take that value and will retain
          the value until an index definition update for the setting.
    + Fixes https://github.com/blevesearch/bleve/issues/1484
        (where the scenario is highlighted better)


Patch:
diff --git a/mapping/index.go b/mapping/index.go
index 21ca5cce..319ba949 100644
--- a/mapping/index.go
+++ b/mapping/index.go
@@ -50,7 +50,7 @@ type IndexMappingImpl struct {
 	DefaultField          string                      `json:"default_field"`
 	StoreDynamic          bool                        `json:"store_dynamic"`
 	IndexDynamic          bool                        `json:"index_dynamic"`
-	DocValuesDynamic      bool                        `json:"docvalues_dynamic,omitempty"`
+	DocValuesDynamic      bool                        `json:"docvalues_dynamic"`
 	CustomAnalysis        *customAnalysis             `json:"analysis,omitempty"`
 	cache                 *registry.Cache
 }


Test patch:
diff --git a/index_test.go b/index_test.go
index 50684420..394e7308 100644
--- a/index_test.go
+++ b/index_test.go
@@ -16,6 +16,7 @@ package bleve
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	"io/ioutil"
 	"log"
@@ -2236,3 +2237,39 @@ func TestOptimisedConjunctionSearchHits(t *testing.T) {
 		t.Fatal(err)
 	}
 }
+
+func TestIndexMappingDocValuesDynamic(t *testing.T) {
+	im := NewIndexMapping()
+	// DocValuesDynamic's default is true
+	// Now explicitly set it to false
+	im.DocValuesDynamic = false
+
+	// Next, retrieve the JSON dump of the index mapping
+	var data []byte
+	data, err = json.Marshal(im)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	// Now, edit an unrelated setting in the index mapping
+	var m map[string]interface{}
+	err = json.Unmarshal(data, &m)
+	if err != nil {
+		t.Fatal(err)
+	}
+	m["index_dynamic"] = false
+	data, err = json.Marshal(m)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	// Unmarshal back the changes into the index mapping struct
+	if err = im.UnmarshalJSON(data); err != nil {
+		t.Fatal(err)
+	}
+
+	// Expect DocValuesDynamic to remain false!
+	if im.DocValuesDynamic {
+		t.Fatalf("Expected DocValuesDynamic to remain false after the index mapping edit")
+	}
+}
Repository: blevesearch/bleve
Pull request #1590 (2021-05-20 16:22:10)

fix utf8 out of bounds
Fix simple fragmenter utf8 out of bounds when `highlight.TermLocations` is nil


Patch:
diff --git a/search/highlight/fragmenter/simple/simple.go b/search/highlight/fragmenter/simple/simple.go
index 348dc1ce..34e5c959 100644
--- a/search/highlight/fragmenter/simple/simple.go
+++ b/search/highlight/fragmenter/simple/simple.go
@@ -123,9 +123,15 @@ OUTER:
 		// if there were no terms to highlight
 		// produce a single fragment from the beginning
 		start := 0
-		end := start + s.fragmentSize
-		if end > len(orig) {
-			end = len(orig)
+		end := start
+		used := 0
+		for end < len(orig) && used < s.fragmentSize {
+			r, size := utf8.DecodeRune(orig[end:])
+			if r == utf8.RuneError {
+				break
+			}
+			end += size
+			used++
 		}
 		rv = append(rv, &highlight.Fragment{Orig: orig, Start: start, End: end})
 	}


Test patch:
diff --git a/search/highlight/fragmenter/simple/simple_test.go b/search/highlight/fragmenter/simple/simple_test.go
index dcf4bf83..5106b652 100644
--- a/search/highlight/fragmenter/simple/simple_test.go
+++ b/search/highlight/fragmenter/simple/simple_test.go
@@ -285,6 +285,17 @@ func TestSimpleFragmenterWithSize(t *testing.T) {
 				},
 			},
 		},
+		{
+			orig: []byte("避免出现 rune 越界问题"),
+			fragments: []*highlight.Fragment{
+				{
+					Orig:  []byte("避免出现 rune 越界问题"),
+					Start: 0,
+					End:   13,
+				},
+			},
+			ot: nil,
+		},
 	}
 
 	fragmenter := NewFragmenter(5)
Repository: CS-SI/eodag
Pull request #1607 (2025-04-11 12:25:04)

fix(core): reset errors between SearchResult instances
fix a bug that caused the errors list in SearchResult to not be reset between SearchResult instances.



Patch:
diff --git a/eodag/api/search_result.py b/eodag/api/search_result.py
index cc5761b3..75f5aac4 100644
--- a/eodag/api/search_result.py
+++ b/eodag/api/search_result.py
@@ -36,7 +36,7 @@ if TYPE_CHECKING:
     from eodag.plugins.crunch.base import Crunch
 
 
-class SearchResult(UserList):
+class SearchResult(UserList[EOProduct]):
     """An object representing a collection of :class:`~eodag.api.product._product.EOProduct` resulting from a search.
 
     :param products: A list of products resulting from a search
@@ -46,8 +46,6 @@ class SearchResult(UserList):
     :ivar number_matched: Estimated total number of matching results
     """
 
-    data: list[EOProduct]
-
     errors: Annotated[
         list[tuple[str, Exception]], Doc("Tuple of provider name, exception")
     ]
@@ -56,11 +54,11 @@ class SearchResult(UserList):
         self,
         products: list[EOProduct],
         number_matched: Optional[int] = None,
-        errors: list[tuple[str, Exception]] = [],
+        errors: Optional[list[tuple[str, Exception]]] = None,
     ) -> None:
         super().__init__(products)
         self.number_matched = number_matched
-        self.errors = errors
+        self.errors = errors if errors is not None else []
 
     def crunch(self, cruncher: Crunch, **search_params: Any) -> SearchResult:
         """Do some crunching with the underlying EO products.
@@ -193,8 +191,8 @@ class SearchResult(UserList):
                 <details><summary style='color: grey; font-family: monospace;'>
                     {i}&ensp;
                     {type(p).__name__}(id=<span style='color: black;'>{
-                    p.properties["id"]
-                }</span>, provider={p.provider})
+                        p.properties["id"]
+                    }</span>, provider={p.provider})
                 </summary>
                 {p._repr_html_()}
                 </details>


Test patch:
diff --git a/tests/units/test_search_result.py b/tests/units/test_search_result.py
index 6b563432..5f591666 100644
--- a/tests/units/test_search_result.py
+++ b/tests/units/test_search_result.py
@@ -88,3 +88,11 @@ class TestSearchResult(unittest.TestCase):
         """SearchResult html repr must be correctly formatted"""
         sr_repr = html.fromstring(self.search_result._repr_html_())
         self.assertIn("SearchResult", sr_repr.xpath("//thead/tr/td")[0].text)
+
+    def test_search_result_errors(self):
+        """SearchResult instances must store search errors"""
+        self.assertEqual(self.search_result.errors, [])
+        self.search_result.errors.append(["foo", Exception("1st exception")])
+        self.search_result.errors.append(["bar", Exception("2nd exception")])
+        self.assertEqual(len(self.search_result.errors), 2)
+        self.assertEqual(SearchResult([]).errors, [])