Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've implemented exactly what you're asking about and it works really well. There's two issues to be aware of:</p> <ul> <li>Highlighting in the results list summaries doesn't work, and the suggested workaround also doesn't work in this particular case.</li> <li>If your documents have long titles and truncate them when displayed, there's a chance you'll be matching on the prefix of a word that's not being displayed. Several ways to handle this of course.</li> <li>And in a future version, I'd like to give words towards the start of the title a bit more weight then words at the end. This would be one way to mitigate the previous item.</li> </ul> <p>Like the previous answer, I'd start with the same article linked above, but you DO want the Edge NGram analyzer. The thing you'll add is to ALSO do whitespace tokenization.</p> <p>And then you'd make these changes to your schema.xml file. This example assumes you already have a field called "title" defined, and it's what you'd like to display as well. I create a second field, which is ONLY used for autocomplete prefix matching.</p> <p>Step 1: Define Edge NGram Text field type</p> <pre><code>&lt;types&gt; &lt;!-- ... other types ... --&gt; &lt;!-- Assuming you already have this --&gt; &lt;fieldType name="text" class="solr.TextField" positionIncrementGap="100"&gt; ... normal text definition ... &lt;/fieldType&gt; &lt;!-- Adding this --&gt; &lt;fieldType name="prefix_edge_text" class="solr.TextField" positionIncrementGap="100"&gt; &lt;analyzer type="index"&gt; &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt; &lt;filter class="solr.LowerCaseFilterFactory"/&gt; &lt;!-- not using enablePositionIncrements="true" for now --&gt; &lt;filter class="solr.StopFilterFactory" words="stopwords.txt" /&gt; &lt;filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" /&gt; &lt;/analyzer&gt; &lt;analyzer type="query"&gt; &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt; &lt;filter class="solr.LowerCaseFilterFactory"/&gt; &lt;!-- No need to create Edges here --&gt; &lt;!-- Don't want stopwords here --&gt; &lt;/analyzer&gt; &lt;/fieldType&gt; &lt;/types&gt; </code></pre> <p>Step 2: Define the New Field</p> <pre><code>&lt;fields&gt; &lt;!-- ... other fields ... --&gt; &lt;!-- Assuming you already have this --&gt; &lt;field name="title" type="text" indexed="true" stored="true" multiValued="true"/&gt; &lt;!-- Adding this --&gt; &lt;field name="prefix_title" type="prefix_edge_text" indexed="true" stored="true" multiValued="true" /&gt; &lt;/fields&gt; </code></pre> <p>Step 3: Copy the Title's content over to the prefix field during indexing</p> <pre><code>&lt;!-- Adding this --&gt; &lt;copyField source="title" dest="prefix_title" /&gt; </code></pre> <p>That's pretty much it for the schema. Just remember:</p> <ul> <li>When you do a regular search, you still search against the regular <strong>title</strong> field.</li> <li>When you're doing an autocomplete search, search against the <strong>prefix_title</strong>.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload