private Address getSearchStartAddress(boolean forward) {
		ProgramLocation location = navigatable.getLocation();
		Address startAddress = location == null ? null : location.getByteAddress();
		if (startAddress == null) {
			startAddress = forward ? program.getMinAddress() : program.getMaxAddress();
		}

		/*
			Finding the correct starting address is tricky. Ideally, we would just use the
		 	current cursor location's address and begin searching. However, this doesn't work
		 	for subsequent searches for two reasons. 
		 
		 	The first reason is simply that subsequent searches need to start one address past the
		 	current address or else you will just find the same location again.
		 
		 	The second reason is caused by the way the listing handles arrays. Since arrays don't
		 	have a bytes field, a previous search may have found a hit inside an array, but because
		 	there is no place in the listing to represent that, the cursor is actually placed at
		 	address that is before (possibly several addresses before) the actual hit. So going
		 	forward in the next search, even after incrementing the address, will result in finding
		 	that same hit.
		  
		 	To solve this, the provider keeps track of a last match address. Subsequent searches
		 	will use this address as long as that address and the cursor address are in the same
		 	code unit. If they are not in the same code unit, we assume the user manually moved the
			cursor and want to start searching from that new location.
		*/

		if (lastMatchingAddress == null) {
			return startAddress;
		}
		CodeUnit cu = program.getListing().getCodeUnitContaining(startAddress);
		if (cu.contains(lastMatchingAddress)) {
			startAddress = forward ? lastMatchingAddress.next() : lastMatchingAddress.previous();
		}
		if (startAddress == null) {
			startAddress = program.getMinAddress();
		}
		return startAddress;
	}
Performs a scan on the current results, keeping only the results that match the type of scan.
Note: this method is public to facilitate testing.

@param scanner the scanner to use to reduce the results.
Ghidra/Features/Base/src/main/java/ghidra/features/base/memsearch/gui/MemorySearchProvider.java