mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-11-03 17:36:29 +00:00 
			
		
		
		
	Add indices field to _matchesPosition to specify where in an array a match comes from (#5005)
	
		
			
	
		
	
	
		
	
		
			Some checks are pending
		
		
	
	
		
			
				
	
				Indexing bench (push) / Run and upload benchmarks (push) Waiting to run
				
					
					
				
			
		
			
				
	
				Benchmarks of indexing (push) / Run and upload benchmarks (push) Waiting to run
				
					
					
				
			
		
			
				
	
				Benchmarks of search for geo (push) / Run and upload benchmarks (push) Waiting to run
				
					
					
				
			
		
			
				
	
				Benchmarks of search for songs (push) / Run and upload benchmarks (push) Waiting to run
				
					
					
				
			
		
			
				
	
				Benchmarks of search for Wikipedia articles (push) / Run and upload benchmarks (push) Waiting to run
				
					
					
				
			
		
			
				
	
				Run the indexing fuzzer / Setup the action (push) Successful in 1h4m31s
				
					
					
				
			
		
		
	
	
				
					
				
			
		
			Some checks are pending
		
		
	
	Indexing bench (push) / Run and upload benchmarks (push) Waiting to run
				Benchmarks of indexing (push) / Run and upload benchmarks (push) Waiting to run
				Benchmarks of search for geo (push) / Run and upload benchmarks (push) Waiting to run
				Benchmarks of search for songs (push) / Run and upload benchmarks (push) Waiting to run
				Benchmarks of search for Wikipedia articles (push) / Run and upload benchmarks (push) Waiting to run
				Run the indexing fuzzer / Setup the action (push) Successful in 1h4m31s
				* Remove unreachable code
* Add `indices` field to `MatchBounds`
For matches inside arrays, this field holds the indices of the array
elements that matched. For example, searching for `cat` inside
`{ "a": ["dog", "cat", "fox"] }` would return `indices: [1]`. For nested
arrays, this contains multiple indices, starting with the one for the
top-most array. For matches in fields without arrays, `indices` is not
serialized (does not exist) to save space.
			
			
This commit is contained in:
		@@ -105,6 +105,8 @@ impl FormatOptions {
 | 
			
		||||
pub struct MatchBounds {
 | 
			
		||||
    pub start: usize,
 | 
			
		||||
    pub length: usize,
 | 
			
		||||
    #[serde(skip_serializing_if = "Option::is_none")]
 | 
			
		||||
    pub indices: Option<Vec<usize>>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Structure used to analyze a string, compute words that match,
 | 
			
		||||
@@ -220,15 +222,20 @@ impl<'t, 'tokenizer> Matcher<'t, 'tokenizer, '_, '_> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Returns boundaries of the words that match the query.
 | 
			
		||||
    pub fn matches(&mut self) -> Vec<MatchBounds> {
 | 
			
		||||
    pub fn matches(&mut self, array_indices: &[usize]) -> Vec<MatchBounds> {
 | 
			
		||||
        match &self.matches {
 | 
			
		||||
            None => self.compute_matches().matches(),
 | 
			
		||||
            None => self.compute_matches().matches(array_indices),
 | 
			
		||||
            Some((tokens, matches)) => matches
 | 
			
		||||
                .iter()
 | 
			
		||||
                .map(|m| MatchBounds {
 | 
			
		||||
                    start: tokens[m.get_first_token_pos()].byte_start,
 | 
			
		||||
                    // TODO: Why is this in chars, while start is in bytes?
 | 
			
		||||
                    length: m.char_count,
 | 
			
		||||
                    indices: if array_indices.is_empty() {
 | 
			
		||||
                        None
 | 
			
		||||
                    } else {
 | 
			
		||||
                        Some(array_indices.to_owned())
 | 
			
		||||
                    },
 | 
			
		||||
                })
 | 
			
		||||
                .collect(),
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user