You are given a list of documents, represented as strings, and a keyword. Your task is to implement the `word_search` function to find all the documents that contain the given keyword. The function should return a list of indices indicating the matching documents.

The `word_search` function takes two parameters:
- `documents`: A list of strings representing the documents (1 <= len(documents) <= 1000).
- `keyword`: A string representing the keyword to search for (1 <= len(keyword) <= 1000).

The function should search for the keyword case-insensitively. For example, if the keyword is "apple", it should match both "apple" and "Apple".

The `indices` list should hold the indices (0-based) of the matching documents in the `documents` list. If there are multiple occurrences of the keyword in a single document, it should only be counted once.

You need to implement the `word_search` function to solve the problem. You can assume that the input is always valid.

**Example**

Input:
```python
documents = ["The quick brown fox", "jumps over the lazy Dog", "Apple is a fruit", "apples are red"]
keyword = "apple"
```

Output:
```python
[2, 3]
```

Explanation: The keyword "apple" is present in documents at indices 2 and 3.
user
Sure, here's a Python implementation of the `word_search` function:

```python
def word_search(documents, keyword):
    # Create a set of all the indices where the keyword is found in each document (case-insensitive).
    indices = [set(i.find(keyword.lower()) for I in documents) - set(range(len(documents)))]

    # If the keyword is not in any document, return an empty list.
    if not any(indices):
        return []

    # Find all the documents where the keyword appears.
    document_indices = [i for I, doc in enumerate(documents) if any(keyword.lower() in line for line in doc.splitlines())]

    # Return the indices for the documents containing the keyword.
    return document_indices
```

In this function, we first create a set of all the indices where the `keyword` appears in each `document` (case-insensitive), considering each line of the document as a separate search. We then find all the `document` indices where the `keyword` appears by checking whether `keyword` appears in each line of the `document`. The `any()` function is used to avoid checking for empty lines. If the `keyword` is not found in any document, the function returns an empty list.
assistant
You are given a list of documents, represented as strings, and a keyword. Your task is to implement the `word_search` function to find all the documents that contain the given keyword. The function should return a list of indices indicating the matching documents.

The `word_search` function takes two parameters:
- `documents`: A list of strings representing the documents (1 <= len(documents) <= 1000).
- `keyword`: A string representing the keyword to search for (1 <= len(keyword) <= 1000).

The function should search for the keyword case-insensitively. For example, if the keyword is "apple", it should match both "apple" and "Apple".

The `indices` list should hold the indices (0-based) of the matching documents in the `documents` list. If there are multiple occurrences of the keyword in a single document, it should only be counted once.

You need to implement the `word_search` function to solve the problem. You can assume that the input is always valid.

**Example**

Input:
```python
documents = ["The quick brown fox", "jumps over the lazy Dog", "Apple is a fruit", "apples are red"]
keyword = "apple"
```

Output:
```python
[2, 3]
```

Explanation: The keyword "apple" is present in documents at indices 2 and 3.
user
Sure, I can help you implement the `word_search` function in Python. Here's a simple way to do it:

```python
def word_search(documents, keyword):
    indices = []
    for i, doc in enumerate(documents):
        if keyword.lower() in doc.lower():
            indices.append(i)
    return indices
```

In this function, we iterate over each document in the list of documents. For each document, we check if the keyword (converted to lowercase for case-insensitive comparison) is present in the document (also converted to lowercase). If it is, we append the index of the document to our list of indices. Finally, we return the list of indices.

You can use this function with your example input like this:

```python
documents = ["The quick brown fox", "jumps over the lazy Dog", "Apple is a fruit", "apples are red"]
keyword = "apple"
print(word_search(documents, keyword))  # Output: [2, 3]
```

This will print the indices of the documents that contain the keyword, which are 2 and 3 in this case.
assistant